Inspired by 2020's April Fools' 20w14infinite Snapshot, this mod brings endless randomly generated dimensions into Minecraft.
1package net.lerariemann.infinity.util.var;
2
3import java.util.ArrayList;
4import java.util.List;
5import java.util.Map;
6import java.util.Objects;
7import net.minecraft.core.BlockPos;
8import net.minecraft.core.Direction;
9
10public record TextData(int longest_line, List<List<Integer>> offsetMap, List<List<Character>> charMap) {
11 public int getLineCount() {
12 return offsetMap.size();
13 }
14 public int getLineLen(int i) {
15 return offsetMap.get(i).size();
16 }
17
18 public static int width(Character c, int char_spacing) {
19 return storage.get(c).size() + char_spacing;
20 }
21
22 public static boolean check(int x, int z, Character c) {
23 List<Integer> lst = TextData.storage.get(c);
24 if(x >= lst.size()) return false;
25 return ((lst.get(x) >> z)%2) == 1;
26 }
27
28 public static BlockPos mutate(BlockPos blockPos, int ori, int a, int b) { //for features and surface rules
29 if (((ori/6)%2) == 1) {
30 a*=-1;
31 }
32 if (((ori/12)%2) == 1) {
33 b*=-1;
34 }
35 List<Integer> lst = switch (ori % 6) {
36 case 0 -> List.of(0, a, b);
37 case 1 -> List.of(b, 0, a);
38 case 2 -> List.of(a, b, 0);
39 case 3 -> List.of(0, b, a);
40 case 4 -> List.of(a, 0, b);
41 default -> List.of(b, a, 0);
42 };
43 return blockPos.offset(lst.get(0), lst.get(1), lst.get(2));
44 }
45
46 public static BlockPos mutate(BlockPos blockPos, int ori, int a, int b, int c, int amax, int bmax, int cmax) {
47 if (((ori/6)%2) == 1) {
48 a = amax - a;
49 c = cmax - c;
50 }
51 if (((ori/12)%2) == 1) {
52 b = bmax - b;
53 c = cmax - c;
54 }
55 List<Integer> lst = switch (ori % 6) {
56 case 0 -> List.of(c, a, b);
57 case 1 -> List.of(b, c, a);
58 case 2 -> List.of(a, b, c);
59 case 3 -> List.of(c, b, a);
60 case 4 -> List.of(a, c, b);
61 default -> List.of(b, a, c);
62 };
63 return blockPos.offset(lst.get(0), lst.get(1), lst.get(2));
64 }
65
66 public static int getOri(Polarization pol, Direction dir) {
67 return axis(pol, dir) + (isDownPos(pol, dir) ? 0 : 6) + (isAlongPos(pol, dir) ? 0 : 12);
68 }
69 static int axis(Polarization pol, Direction dir) {
70 boolean x = dir.getAxis().equals(Direction.Axis.X);
71 if (pol.isVertical()) return x ? 3 : 2;
72 if (x) return pol.isFlat() ? 1 : 5;
73 return pol.isFlat() ? 4 : 0;
74 }
75 static boolean isDownPos(Polarization pol, Direction dir) {
76 return !pol.isPositive() ^ switch (pol.toPositive()) {
77 case FLAT -> dir.equals(Direction.EAST) || dir.equals(Direction.NORTH);
78 case UP -> dir.equals(Direction.SOUTH) || dir.equals(Direction.WEST);
79 default -> false; //STANDING
80 };
81 }
82 static boolean isAlongPos(Polarization pol, Direction dir) {
83 if (pol.isVertical()) return pol.isPositive();
84 return dir.getAxisDirection().equals(Direction.AxisDirection.POSITIVE);
85 }
86
87 public enum Polarization {
88 FLAT(0),
89 FLAT_REVERSE(1),
90 STANDING(2),
91 STANDING_REVERSE(3),
92 UP(4),
93 DOWN(5);
94 public final int id;
95 Polarization(final int i) {
96 id = i;
97 }
98 public static Polarization of(int i) {
99 return switch (i) {
100 case 1 -> FLAT_REVERSE;
101 case 2 -> STANDING;
102 case 3 -> STANDING_REVERSE;
103 case 4 -> UP;
104 case 5 -> DOWN;
105 default -> FLAT;
106 };
107 }
108 public boolean isVertical() {
109 return id > 3;
110 }
111 public boolean isFlat() {
112 return id < 2;
113 }
114 public boolean isPositive() {
115 return id%2 == 0;
116 }
117 public Polarization toPositive() {
118 if (isPositive()) return this;
119 return of(id - 1);
120 }
121 }
122
123 public static TextData genData(int char_spacing, int max_width, String text) {
124 int x = 0;
125 int z = 0;
126 int longest_line = 0;
127 boolean bl;
128 List<List<Integer>> textmap = new ArrayList<>();
129 List<List<Character>> charmap = new ArrayList<>();
130 textmap.add(new ArrayList<>());
131 charmap.add(new ArrayList<>());
132 int i = 0;
133 boolean lineWrap = false;
134 while (i < text.length()) {
135 bl = false;
136 Character c = text.charAt(i);
137 if (c.equals('$')) {
138 if (i+1 < text.length() && (Objects.equals(text.charAt(i+1), 'n'))) {
139 i+=1;
140 bl = true;
141 lineWrap = false;
142 }
143 }
144 if (lineWrap && x == 0 && c.equals(' ')) {
145 i+=1;
146 lineWrap = false;
147 continue;
148 }
149 if (!bl && storage.containsKey(c)) {
150 textmap.get(z).add(x);
151 charmap.get(z).add(c);
152 x += width(c, char_spacing);
153 }
154 if (i+1 == text.length()) {
155 longest_line = Math.max(longest_line, x);
156 break;
157 }
158 if (bl || x >= max_width) {
159 textmap.add(new ArrayList<>());
160 charmap.add(new ArrayList<>());
161 longest_line = Math.max(longest_line, x);
162 x = 0;
163 z += 1;
164 lineWrap = true;
165 }
166 i++;
167 }
168 return new TextData(longest_line, textmap, charmap);
169 }
170
171 public static final Map<Character, List<Integer>> storage = Map.ofEntries(
172 Map.entry('a', List.of(0b00100000, 0b01010100, 0b01010100, 0b01010100, 0b01111000)),
173 Map.entry('b', List.of(0b01111111, 0b01001000, 0b01000100, 0b01000100, 0b00111000)),
174 Map.entry('c', List.of(0b00111000, 0b01000100, 0b01000100, 0b01000100, 0b00101000)),
175 Map.entry('d', List.of(0b00111000, 0b01000100, 0b01000100, 0b01001000, 0b01111111)),
176 Map.entry('e', List.of(0b00111000, 0b01010100, 0b01010100, 0b01010100, 0b01011000)),
177 Map.entry('f', List.of(0b00000100, 0b01111110, 0b00000101, 0b00000101)),
178 Map.entry('g', List.of(0b10011000, 0b10100100, 0b10100100, 0b10100100, 0b01111100)),
179 Map.entry('h', List.of(0b01111111, 0b00001000, 0b00000100, 0b00000100, 0b01111000)),
180 Map.entry('i', List.of(0b01111101)),
181 Map.entry('j', List.of(0b01000000, 0b10000000, 0b10000000, 0b10000000, 0b01111101)),
182 Map.entry('k', List.of(0b01111111, 0b00010000, 0b00101000, 0b01000100)),
183 Map.entry('l', List.of(0b00111111, 0b01000000)),
184 Map.entry('m', List.of(0b01111100, 0b00000100, 0b00011000, 0b00000100, 0b01111000)),
185 Map.entry('n', List.of(0b01111100, 0b00000100, 0b00000100, 0b00000100, 0b01111000)),
186 Map.entry('o', List.of(0b00111000, 0b01000100, 0b01000100, 0b01000100, 0b00111000)),
187 Map.entry('p', List.of(0b11111100, 0b00101000, 0b00100100, 0b00100100, 0b00011000)),
188 Map.entry('q', List.of(0b00011000, 0b00100100, 0b00100100, 0b00101000, 0b11111100)),
189 Map.entry('r', List.of(0b01111100, 0b00001000, 0b00000100, 0b00000100, 0b00001000)),
190 Map.entry('s', List.of(0b01001000, 0b01010100, 0b01010100, 0b01010100, 0b00100100)),
191 Map.entry('t', List.of(0b00000100, 0b00111111, 0b01000100)),
192 Map.entry('u', List.of(0b00111100, 0b01000000, 0b01000000, 0b01000000, 0b01111100)),
193 Map.entry('v', List.of(0b00011100, 0b00100000, 0b01000000, 0b00100000, 0b00011100)),
194 Map.entry('w', List.of(0b00111100, 0b01000000, 0b01110000, 0b01000000, 0b01111100)),
195 Map.entry('x', List.of(0b01000100, 0b00101000, 0b00010000, 0b00101000, 0b01000100)),
196 Map.entry('y', List.of(0b10011100, 0b10100000, 0b10100000, 0b10100000, 0b01111100)),
197 Map.entry('z', List.of(0b01000100, 0b01100100, 0b01010100, 0b01001100, 0b01000100)),
198 Map.entry('A', List.of(0b01111110, 0b00000101, 0b00000101, 0b00000101, 0b01111110)),
199 Map.entry('B', List.of(0b01111111, 0b01000101, 0b01000101, 0b01000101, 0b00111010)),
200 Map.entry('C', List.of(0b00111110, 0b01000001, 0b01000001, 0b01000001, 0b00100010)),
201 Map.entry('D', List.of(0b01111111, 0b01000001, 0b01000001, 0b01000001, 0b00111110)),
202 Map.entry('E', List.of(0b01111111, 0b01000101, 0b01000101, 0b01000001, 0b01000001)),
203 Map.entry('F', List.of(0b01111111, 0b00000101, 0b00000101, 0b00000001, 0b00000001)),
204 Map.entry('G', List.of(0b00111110, 0b01000001, 0b01000001, 0b01000101, 0b00111101)),
205 Map.entry('H', List.of(0b01111111, 0b00000100, 0b00000100, 0b00000100, 0b01111111)),
206 Map.entry('I', List.of(0b01000001, 0b01111111, 0b01000001)),
207 Map.entry('J', List.of(0b00100000, 0b01000000, 0b01000000, 0b01000000, 0b00111111)),
208 Map.entry('K', List.of(0b01111111, 0b00000100, 0b00000100, 0b00001010, 0b01110001)),
209 Map.entry('L', List.of(0b01111111, 0b01000000, 0b01000000, 0b01000000, 0b01000000)),
210 Map.entry('M', List.of(0b01111111, 0b00000010, 0b00000100, 0b00000010, 0b01111111)),
211 Map.entry('N', List.of(0b01111111, 0b00000010, 0b00000100, 0b00001000, 0b01111111)),
212 Map.entry('O', List.of(0b00111110, 0b01000001, 0b01000001, 0b01000001, 0b00111110)),
213 Map.entry('P', List.of(0b01111111, 0b00000101, 0b00000101, 0b00000101, 0b00000010)),
214 Map.entry('Q', List.of(0b00111110, 0b01000001, 0b01000001, 0b00100001, 0b01011110)),
215 Map.entry('R', List.of(0b01111111, 0b00000101, 0b00000101, 0b00000101, 0b01111010)),
216 Map.entry('S', List.of(0b00100010, 0b01000101, 0b01000101, 0b01000101, 0b00111001)),
217 Map.entry('T', List.of(0b00000001, 0b00000001, 0b01111111, 0b00000001, 0b00000001)),
218 Map.entry('U', List.of(0b00111111, 0b01000000, 0b01000000, 0b01000000, 0b00111111)),
219 Map.entry('V', List.of(0b00001111, 0b00110000, 0b01000000, 0b00110000, 0b00001111)),
220 Map.entry('W', List.of(0b01111111, 0b00100000, 0b00010000, 0b00100000, 0b01111111)),
221 Map.entry('X', List.of(0b01110001, 0b00001010, 0b00000100, 0b00001010, 0b01110001)),
222 Map.entry('Y', List.of(0b00000001, 0b00000010, 0b00000110, 0b00000010, 0b00000001)),
223 Map.entry('Z', List.of(0b01100001, 0b01010001, 0b01001001, 0b01000101, 0b01000011)),
224 Map.entry(' ', List.of(0b00000000, 0b00000000, 0b00000000, 0b00000000)),
225 Map.entry('.', List.of(0b01000000)),
226 Map.entry(',', List.of(0b11000000)),
227 Map.entry(':', List.of(0b01000100)),
228 Map.entry(';', List.of(0b11000100)),
229 Map.entry('\'', List.of(0b00000011)),
230 Map.entry('"', List.of(0b00000011, 0b00000000, 0b00000011)),
231 Map.entry('`', List.of(0b00000001, 0b00000010)),
232 Map.entry('!', List.of(0b01011111)),
233 Map.entry('|', List.of(0b01111111)),
234 Map.entry('~', List.of(0b00000010, 0b00000001, 0b00000001, 0b00000010, 0b00000010, 0b00000001)),
235 Map.entry('@', List.of(0b01111100, 0b10000010, 0b10111010, 0b10101010, 0b10100010, 0b00111100)),
236 Map.entry('#', List.of(0b00010100, 0b01111111, 0b00010100, 0b01111111, 0b00010100)),
237 Map.entry('$', List.of(0b00100100, 0b00101010, 0b01101011, 0b00101010, 0b00010010)),
238 Map.entry('%', List.of(0b01000011, 0b00110000, 0b00001000, 0b00000110, 0b01100001)),
239 Map.entry('^', List.of(0b00000100, 0b00000010, 0b00000001, 0b00000010, 0b00000100)),
240 Map.entry('*', List.of(0b00000101, 0b0000010, 0b00000101)),
241 Map.entry('&', List.of(0b00110000, 0b01001010, 0b01011101, 0b00110010, 0b01001000)),
242 Map.entry('(', List.of(0b00011100, 0b00100010, 0b01000001)),
243 Map.entry(')', List.of(0b01000001, 0b00100010, 0b00011100)),
244 Map.entry('[', List.of(0b01111111, 0b01000001, 0b01000001)),
245 Map.entry(']', List.of(0b01000001, 0b01000001, 0b01111111)),
246 Map.entry('{', List.of(0b00001000, 0b00110110, 0b01000001)),
247 Map.entry('}', List.of(0b01000001, 0b00110110, 0b00001000)),
248 Map.entry('+', List.of(0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000)),
249 Map.entry('-', List.of(0b00001000, 0b00001000, 0b00001000, 0b00001000, 0b00001000)),
250 Map.entry('=', List.of(0b00100100, 0b00100100, 0b00100100, 0b00100100, 0b00100100)),
251 Map.entry('_', List.of(0b10000000, 0b10000000, 0b10000000, 0b10000000, 0b10000000)),
252 Map.entry('/', List.of(0b01000000, 0b00110000, 0b00001000, 0b00000110, 0b00000001)),
253 Map.entry('\\', List.of(0b00000001, 0b00000110, 0b00001000, 0b00110000, 0b01000000)),
254 Map.entry('<', List.of(0b00001000, 0b00010100, 0b00100010, 0b01000001)),
255 Map.entry('>', List.of(0b01000001, 0b00100010, 0b00010100, 0b00001000)),
256 Map.entry('?', List.of(0b00000010, 0b00000001, 0b01010001, 0b00001001, 0b00000110)),
257 Map.entry('1', List.of(0b01000000, 0b01000010, 0b01111111, 0b01000000, 0b01000000)),
258 Map.entry('2', List.of(0b01100010, 0b01010001, 0b01001001, 0b01001001, 0b01100110)),
259 Map.entry('3', List.of(0b00100010, 0b01000001, 0b01001001, 0b01001001, 0b00110110)),
260 Map.entry('4', List.of(0b00011000, 0b00010100, 0b00010010, 0b00010001, 0b01111111)),
261 Map.entry('5', List.of(0b00100111, 0b01000101, 0b01000101, 0b01000101, 0b00111001)),
262 Map.entry('6', List.of(0b00111100, 0b01001010, 0b01001001, 0b01001001, 0b00110000)),
263 Map.entry('7', List.of(0b00000011, 0b00000001, 0b01110001, 0b00001001, 0b00000111)),
264 Map.entry('8', List.of(0b00110110, 0b01001001, 0b01001001, 0b01001001, 0b00110110)),
265 Map.entry('9', List.of(0b00000110, 0b01001001, 0b01001001, 0b00101001, 0b00011110)),
266 Map.entry('0', List.of(0b00111110, 0b01010001, 0b01001001, 0b01000101, 0b00111110))
267 );
268}