Skip to content

Commit 4275aad

Browse files
trefoil
1 parent 9ec2c40 commit 4275aad

4 files changed

Lines changed: 255 additions & 195 deletions

File tree

mods/client/maze.patch

Lines changed: 47 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,52 @@
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
33
@@ -72,6 +72,7 @@
44
register(registry, "spline", DensityFunctions.Spline.CODEC);
55
register(registry, "constant", DensityFunctions.Constant.CODEC);
66
register(registry, "y_clamped_gradient", DensityFunctions.YClampedGradient.CODEC);
77
+ register(registry, "maze_wall", DensityFunctions.MazeWall.CODEC);
88
return register(registry, "find_top_surface", DensityFunctions.FindTopSurface.CODEC);
99
}
10-
10+
1111
@@ -280,6 +281,10 @@
1212
return new DensityFunctions.FindTopSurface(density, upperBound, lowerBound, stepSize);
1313
}
14-
14+
1515
+ public static DensityFunction mazeWall(final int cell, final int thick, final int height) {
1616
+ return new DensityFunctions.MazeWall(cell, thick, height);
1717
+ }
1818
+
1919
private record Ap2(
2020
DensityFunctions.TwoArgumentSimpleFunction.Type type, DensityFunction argument1, DensityFunction argument2, double minValue, double maxValue
2121
) implements DensityFunctions.TwoArgumentSimpleFunction {
22-
@@ -1391,6 +1396,113 @@
22+
@@ -1391,6 +1396,100 @@
2323
}
2424
}
25-
25+
2626
+ protected record MazeWall(int cell, int thick, int height) implements DensityFunction.SimpleFunction {
2727
+ private static final MapCodec<DensityFunctions.MazeWall> DATA_CODEC = RecordCodecBuilder.mapCodec(
2828
+ 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)
3232
+ )
3333
+ .apply(i, DensityFunctions.MazeWall::new)
3434
+ );
3535
+ 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;
3838
+ private static final int[] DX = {-1, 1, 0, 0};
3939
+ private static final int[] DZ = {0, 0, -1, 1};
4040
+
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;
4443
+ for (s = n / 2; s > 0; s /= 2) {
4544
+ rx = (cx & s) > 0 ? 1 : 0;
4645
+ ry = (cy & s) > 0 ? 1 : 0;
4746
+ d += s * s * ((3 * rx) ^ ry);
4847
+ 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;
5650
+ }
5751
+ }
5852
+ return d;
@@ -64,110 +58,80 @@
6458
+ return h;
6559
+ }
6660
+
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);
7365
+ int[] cand = new int[4];
7466
+ int n = 0;
7567
+ 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;
8171
+ }
8272
+ 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)];
8574
+ }
8675
+
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);
9379
+ }
9480
+
9581
+ @Override
9682
+ 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();
10084
+ int floor = 64;
10185
+ if (y < floor) return 1.0;
10286
+ if (y >= floor + this.height) return -1.0;
10387
+ 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;
11091
+ if (!wx && !wz) return -1.0;
11192
+ 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;
11495
+ return 1.0;
11596
+ }
11697
+
11798
+ @Override
118-
+ public double minValue() {
119-
+ return -1.0;
120-
+ }
99+
+ public double minValue() { return -1.0; }
121100
+
122101
+ @Override
123-
+ public double maxValue() {
124-
+ return 1.0;
125-
+ }
102+
+ public double maxValue() { return 1.0; }
126103
+
127104
+ @Override
128-
+ public KeyDispatchDataCodec<? extends DensityFunction> codec() {
129-
+ return CODEC;
130-
+ }
105+
+ public KeyDispatchDataCodec<? extends DensityFunction> codec() { return CODEC; }
131106
+ }
132107
+
133108
private record YClampedGradient(int fromY, int toY, double fromValue, double toValue) implements DensityFunction.SimpleFunction {
134109
private static final MapCodec<DensityFunctions.YClampedGradient> DATA_CODEC = RecordCodecBuilder.mapCodec(
135110
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
138113
@@ -94,7 +94,8 @@
139114
}
140115
}
141-
116+
142117
- this.router = settings.noiseRouter().mapAll(new NoiseWiringHelper());
143118
+ NoiseRouter base = settings.noiseRouter().mapAll(new NoiseWiringHelper());
144-
+ this.router = wrapMaze(base);
119+
+ this.router = wrap(base);
145120
DensityFunction.Visitor noiseFlattener = new DensityFunction.Visitor() {
146121
private final Map<DensityFunction, DensityFunction> wrapped = new HashMap<>();
147-
148-
@@ -149,4 +150,25 @@
122+
123+
@@ -149,4 +150,15 @@
149124
public PositionalRandomFactory oreRandom() {
150125
return this.oreRandom;
151126
}
152127
+
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);
155130
+ 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()
171135
+ );
172136
+ }
173137
}

0 commit comments

Comments
 (0)