|
1 | | ---- a/net/minecraft/world/level/levelgen/DensityFunctions.java 2025-12-10 12:13:46.468496065 +0100 |
2 | | -+++ b/net/minecraft/world/level/levelgen/DensityFunctions.java 2025-12-10 12:13:07.200959142 +0100 |
| 1 | +--- a/net/minecraft/world/level/levelgen/DensityFunctions.java |
| 2 | ++++ b/net/minecraft/world/level/levelgen/DensityFunctions.java |
3 | 3 | @@ -72,6 +72,7 @@ |
4 | 4 | register(registry, "spline", DensityFunctions.Spline.CODEC); |
5 | 5 | register(registry, "constant", DensityFunctions.Constant.CODEC); |
6 | 6 | register(registry, "y_clamped_gradient", DensityFunctions.YClampedGradient.CODEC); |
7 | 7 | + register(registry, "maze_wall", DensityFunctions.MazeWall.CODEC); |
8 | 8 | return register(registry, "find_top_surface", DensityFunctions.FindTopSurface.CODEC); |
9 | 9 | } |
10 | | - |
| 10 | + |
11 | 11 | @@ -280,6 +281,10 @@ |
12 | 12 | return new DensityFunctions.FindTopSurface(density, upperBound, lowerBound, stepSize); |
13 | 13 | } |
14 | | - |
| 14 | + |
15 | 15 | + public static DensityFunction mazeWall(final int cell, final int thick, final int height) { |
16 | 16 | + return new DensityFunctions.MazeWall(cell, thick, height); |
17 | 17 | + } |
18 | 18 | + |
19 | 19 | private record Ap2( |
20 | 20 | DensityFunctions.TwoArgumentSimpleFunction.Type type, DensityFunction argument1, DensityFunction argument2, double minValue, double maxValue |
21 | 21 | ) implements DensityFunctions.TwoArgumentSimpleFunction { |
22 | | -@@ -1391,6 +1396,113 @@ |
| 22 | +@@ -1391,6 +1396,100 @@ |
23 | 23 | } |
24 | 24 | } |
25 | | - |
| 25 | + |
26 | 26 | + protected record MazeWall(int cell, int thick, int height) implements DensityFunction.SimpleFunction { |
27 | 27 | + private static final MapCodec<DensityFunctions.MazeWall> DATA_CODEC = RecordCodecBuilder.mapCodec( |
28 | 28 | + i -> i.group( |
29 | | -+ Codec.INT.fieldOf("cell_size").forGetter(DensityFunctions.MazeWall::cell), |
30 | | -+ Codec.INT.fieldOf("wall_thickness").forGetter(DensityFunctions.MazeWall::thick), |
31 | | -+ Codec.INT.fieldOf("wall_height").forGetter(DensityFunctions.MazeWall::height) |
| 29 | ++ Codec.INT.fieldOf("cell").forGetter(DensityFunctions.MazeWall::cell), |
| 30 | ++ Codec.INT.fieldOf("thick").forGetter(DensityFunctions.MazeWall::thick), |
| 31 | ++ Codec.INT.fieldOf("height").forGetter(DensityFunctions.MazeWall::height) |
32 | 32 | + ) |
33 | 33 | + .apply(i, DensityFunctions.MazeWall::new) |
34 | 34 | + ); |
35 | 35 | + public static final KeyDispatchDataCodec<DensityFunctions.MazeWall> CODEC = DensityFunctions.makeCodec(DATA_CODEC); |
36 | | -+ private static final int HILBERT_N = 4; |
37 | | -+ private static final int HILBERT_SZ = 1 << HILBERT_N; |
| 36 | ++ private static final int H_N = 4; |
| 37 | ++ private static final int H_SZ = 1 << H_N; |
38 | 38 | + private static final int[] DX = {-1, 1, 0, 0}; |
39 | 39 | + private static final int[] DZ = {0, 0, -1, 1}; |
40 | 40 | + |
41 | | -+ private static int hilbertXy2d(final int n, final int x, final int y) { |
42 | | -+ int rx, ry, s, d = 0; |
43 | | -+ int cx = x, cy = y; |
| 41 | ++ private static int hilbert(final int n, final int x, final int y) { |
| 42 | ++ int rx, ry, s, d = 0, cx = x, cy = y; |
44 | 43 | + for (s = n / 2; s > 0; s /= 2) { |
45 | 44 | + rx = (cx & s) > 0 ? 1 : 0; |
46 | 45 | + ry = (cy & s) > 0 ? 1 : 0; |
47 | 46 | + d += s * s * ((3 * rx) ^ ry); |
48 | 47 | + if (ry == 0) { |
49 | | -+ if (rx == 1) { |
50 | | -+ cx = s - 1 - cx; |
51 | | -+ cy = s - 1 - cy; |
52 | | -+ } |
53 | | -+ int temp = cx; |
54 | | -+ cx = cy; |
55 | | -+ cy = temp; |
| 48 | ++ if (rx == 1) { cx = s - 1 - cx; cy = s - 1 - cy; } |
| 49 | ++ int t = cx; cx = cy; cy = t; |
56 | 50 | + } |
57 | 51 | + } |
58 | 52 | + return d; |
|
64 | 58 | + return h; |
65 | 59 | + } |
66 | 60 | + |
67 | | -+ private int getConn(final int cx, final int cz) { |
68 | | -+ int hx = Math.floorMod(cx, HILBERT_SZ); |
69 | | -+ int hz = Math.floorMod(cz, HILBERT_SZ); |
70 | | -+ int qx = Math.floorDiv(cx, HILBERT_SZ); |
71 | | -+ int qz = Math.floorDiv(cz, HILBERT_SZ); |
72 | | -+ int d = hilbertXy2d(HILBERT_SZ, hx, hz); |
| 61 | ++ private int conn(final int cx, final int cz) { |
| 62 | ++ int hx = Math.floorMod(cx, H_SZ), hz = Math.floorMod(cz, H_SZ); |
| 63 | ++ int qx = Math.floorDiv(cx, H_SZ), qz = Math.floorDiv(cz, H_SZ); |
| 64 | ++ int d = hilbert(H_SZ, hx, hz); |
73 | 65 | + int[] cand = new int[4]; |
74 | 66 | + int n = 0; |
75 | 67 | + for (int dir = 0; dir < 4; dir++) { |
76 | | -+ int nx = hx + DX[dir]; |
77 | | -+ int nz = hz + DZ[dir]; |
78 | | -+ if (nx < 0 || nx >= HILBERT_SZ || nz < 0 || nz >= HILBERT_SZ) continue; |
79 | | -+ int nd = hilbertXy2d(HILBERT_SZ, nx, nz); |
80 | | -+ if (nd > d) cand[n++] = dir; |
| 68 | ++ int nx = hx + DX[dir], nz = hz + DZ[dir]; |
| 69 | ++ if (nx < 0 || nx >= H_SZ || nz < 0 || nz >= H_SZ) continue; |
| 70 | ++ if (hilbert(H_SZ, nx, nz) > d) cand[n++] = dir; |
81 | 71 | + } |
82 | 72 | + if (n == 0) return -1; |
83 | | -+ long h = hash(cx, cz, qx * 31L + qz); |
84 | | -+ return cand[(int) ((h & 0x7FFFFFFFL) % n)]; |
| 73 | ++ return cand[(int) ((hash(cx, cz, qx * 31L + qz) & 0x7FFFFFFFL) % n)]; |
85 | 74 | + } |
86 | 75 | + |
87 | | -+ private boolean isOpen(final int cx, final int cz, final int dir) { |
88 | | -+ int conn = getConn(cx, cz); |
89 | | -+ if (conn == dir) return true; |
90 | | -+ int nx = cx + DX[dir]; |
91 | | -+ int nz = cz + DZ[dir]; |
92 | | -+ return getConn(nx, nz) == (dir ^ 1); |
| 76 | ++ private boolean open(final int cx, final int cz, final int dir) { |
| 77 | ++ if (conn(cx, cz) == dir) return true; |
| 78 | ++ return conn(cx + DX[dir], cz + DZ[dir]) == (dir ^ 1); |
93 | 79 | + } |
94 | 80 | + |
95 | 81 | + @Override |
96 | 82 | + public double compute(final DensityFunction.FunctionContext ctx) { |
97 | | -+ int x = ctx.blockX(); |
98 | | -+ int y = ctx.blockY(); |
99 | | -+ int z = ctx.blockZ(); |
| 83 | ++ int x = ctx.blockX(), y = ctx.blockY(), z = ctx.blockZ(); |
100 | 84 | + int floor = 64; |
101 | 85 | + if (y < floor) return 1.0; |
102 | 86 | + if (y >= floor + this.height) return -1.0; |
103 | 87 | + int stride = this.cell + this.thick; |
104 | | -+ int lx = Math.floorMod(x, stride); |
105 | | -+ int lz = Math.floorMod(z, stride); |
106 | | -+ int cx = Math.floorDiv(x, stride); |
107 | | -+ int cz = Math.floorDiv(z, stride); |
108 | | -+ boolean wx = lx < this.thick; |
109 | | -+ boolean wz = lz < this.thick; |
| 88 | ++ int lx = Math.floorMod(x, stride), lz = Math.floorMod(z, stride); |
| 89 | ++ int cx = Math.floorDiv(x, stride), cz = Math.floorDiv(z, stride); |
| 90 | ++ boolean wx = lx < this.thick, wz = lz < this.thick; |
110 | 91 | + if (!wx && !wz) return -1.0; |
111 | 92 | + if (wx && wz) return 1.0; |
112 | | -+ if (wx && lz >= this.thick && isOpen(cx, cz, 0)) return -1.0; |
113 | | -+ if (wz && lx >= this.thick && isOpen(cx, cz, 2)) return -1.0; |
| 93 | ++ if (wx && lz >= this.thick && open(cx, cz, 0)) return -1.0; |
| 94 | ++ if (wz && lx >= this.thick && open(cx, cz, 2)) return -1.0; |
114 | 95 | + return 1.0; |
115 | 96 | + } |
116 | 97 | + |
117 | 98 | + @Override |
118 | | -+ public double minValue() { |
119 | | -+ return -1.0; |
120 | | -+ } |
| 99 | ++ public double minValue() { return -1.0; } |
121 | 100 | + |
122 | 101 | + @Override |
123 | | -+ public double maxValue() { |
124 | | -+ return 1.0; |
125 | | -+ } |
| 102 | ++ public double maxValue() { return 1.0; } |
126 | 103 | + |
127 | 104 | + @Override |
128 | | -+ public KeyDispatchDataCodec<? extends DensityFunction> codec() { |
129 | | -+ return CODEC; |
130 | | -+ } |
| 105 | ++ public KeyDispatchDataCodec<? extends DensityFunction> codec() { return CODEC; } |
131 | 106 | + } |
132 | 107 | + |
133 | 108 | private record YClampedGradient(int fromY, int toY, double fromValue, double toValue) implements DensityFunction.SimpleFunction { |
134 | 109 | private static final MapCodec<DensityFunctions.YClampedGradient> DATA_CODEC = RecordCodecBuilder.mapCodec( |
135 | 110 | i -> i.group( |
136 | | ---- a/net/minecraft/world/level/levelgen/RandomState.java 2025-12-10 12:13:46.467890698 +0100 |
137 | | -+++ b/net/minecraft/world/level/levelgen/RandomState.java 2025-12-10 12:13:40.929849826 +0100 |
| 111 | +--- a/net/minecraft/world/level/levelgen/RandomState.java |
| 112 | ++++ b/net/minecraft/world/level/levelgen/RandomState.java |
138 | 113 | @@ -94,7 +94,8 @@ |
139 | 114 | } |
140 | 115 | } |
141 | | - |
| 116 | + |
142 | 117 | - this.router = settings.noiseRouter().mapAll(new NoiseWiringHelper()); |
143 | 118 | + NoiseRouter base = settings.noiseRouter().mapAll(new NoiseWiringHelper()); |
144 | | -+ this.router = wrapMaze(base); |
| 119 | ++ this.router = wrap(base); |
145 | 120 | DensityFunction.Visitor noiseFlattener = new DensityFunction.Visitor() { |
146 | 121 | private final Map<DensityFunction, DensityFunction> wrapped = new HashMap<>(); |
147 | | - |
148 | | -@@ -149,4 +150,25 @@ |
| 122 | + |
| 123 | +@@ -149,4 +150,15 @@ |
149 | 124 | public PositionalRandomFactory oreRandom() { |
150 | 125 | return this.oreRandom; |
151 | 126 | } |
152 | 127 | + |
153 | | -+ private static NoiseRouter wrapMaze(final NoiseRouter r) { |
154 | | -+ DensityFunction maze = DensityFunctions.mazeWall(8, 4, 100); |
| 128 | ++ private static NoiseRouter wrap(final NoiseRouter r) { |
| 129 | ++ DensityFunction shape = DensityFunctions.mazeWall(8, 4, 100); |
155 | 130 | + return new NoiseRouter( |
156 | | -+ r.barrierNoise(), |
157 | | -+ r.fluidLevelFloodednessNoise(), |
158 | | -+ r.fluidLevelSpreadNoise(), |
159 | | -+ r.lavaNoise(), |
160 | | -+ r.temperature(), |
161 | | -+ r.vegetation(), |
162 | | -+ r.continents(), |
163 | | -+ r.erosion(), |
164 | | -+ r.depth(), |
165 | | -+ r.ridges(), |
166 | | -+ r.preliminarySurfaceLevel(), |
167 | | -+ maze, |
168 | | -+ r.veinToggle(), |
169 | | -+ r.veinRidged(), |
170 | | -+ r.veinGap() |
| 131 | ++ r.barrierNoise(), r.fluidLevelFloodednessNoise(), r.fluidLevelSpreadNoise(), r.lavaNoise(), |
| 132 | ++ r.temperature(), r.vegetation(), r.continents(), r.erosion(), r.depth(), r.ridges(), |
| 133 | ++ r.preliminarySurfaceLevel(), shape, |
| 134 | ++ r.veinToggle(), r.veinRidged(), r.veinGap() |
171 | 135 | + ); |
172 | 136 | + } |
173 | 137 | } |
0 commit comments