Skip to content

Commit a633604

Browse files
Planetoids mod
1 parent 81efd6f commit a633604

4 files changed

Lines changed: 288 additions & 84 deletions

File tree

buildSrc/src/main/java/Patcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public static void diff(File base, File cur, File out, boolean isZip) throws Exc
5454
try {
5555
String d = Utils.runOut(tmp.toFile(), "diff", "-u", rel, curFile.getAbsolutePath());
5656
if (!d.isEmpty()) {
57-
d = d.replace(rel, "a/" + rel);
58-
d = d.replace(curFile.getAbsolutePath(), "b/" + rel);
57+
d = d.replaceFirst("--- " + rel, "--- a/" + rel);
58+
d = d.replaceFirst("\\+\\+\\+ .*", "+++ b/" + rel);
5959
sb.append(d);
6060
}
6161
} catch (Exception e) {}

mods/client/maze.patch

Lines changed: 99 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
--- a/net/minecraft/world/level/levelgen/DensityFunctions.java 2025-12-07 14:45:36.109273548 +0100
2-
+++ /home/user/github/minecraft-decomp/client/src/main/java/a/net/minecraft/world/level/levelgen/DensityFunctions.java 2025-12-07 14:40:57.849212137 +0100
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
33
@@ -72,6 +72,7 @@
44
register(registry, "spline", DensityFunctions.Spline.CODEC);
55
register(registry, "constant", DensityFunctions.Constant.CODEC);
@@ -12,77 +12,105 @@
1212
return new DensityFunctions.FindTopSurface(density, upperBound, lowerBound, stepSize);
1313
}
1414

15-
+ public static DensityFunction mazeWall(final int cellSize, final int wallThickness, final int wallHeight) {
16-
+ return new DensityFunctions.MazeWall(cellSize, wallThickness, wallHeight);
15+
+ public static DensityFunction mazeWall(final int cell, final int thick, final int height) {
16+
+ 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,85 @@
22+
@@ -1391,6 +1396,113 @@
2323
}
2424
}
2525

26-
+ protected record MazeWall(int cellSize, int wallThickness, int wallHeight) implements DensityFunction.SimpleFunction {
26+
+ 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::cellSize),
30-
+ Codec.INT.fieldOf("wall_thickness").forGetter(DensityFunctions.MazeWall::wallThickness),
31-
+ Codec.INT.fieldOf("wall_height").forGetter(DensityFunctions.MazeWall::wallHeight)
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)
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;
38+
+ private static final int[] DX = {-1, 1, 0, 0};
39+
+ private static final int[] DZ = {0, 0, -1, 1};
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;
44+
+ for (s = n / 2; s > 0; s /= 2) {
45+
+ rx = (cx & s) > 0 ? 1 : 0;
46+
+ ry = (cy & s) > 0 ? 1 : 0;
47+
+ d += s * s * ((3 * rx) ^ ry);
48+
+ 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;
56+
+ }
57+
+ }
58+
+ return d;
59+
+ }
3660
+
37-
+ private long hash(final long x, final long z) {
38-
+ long h = x * 3129871L ^ z * 116129781L;
61+
+ private long hash(final long a, final long b, final long c) {
62+
+ long h = a * 3129871L ^ b * 116129781L ^ c * 982451653L;
3963
+ h = h * h * 42317861L + h * 11L;
4064
+ return h;
4165
+ }
4266
+
43-
+ private boolean hasOpening(final int cellX, final int cellZ, final int dir) {
44-
+ long h = hash(cellX, cellZ);
45-
+ return ((h >> dir) & 1L) == 0L;
46-
+ }
47-
+
48-
+ @Override
49-
+ public double compute(final DensityFunction.FunctionContext context) {
50-
+ int x = context.blockX();
51-
+ int y = context.blockY();
52-
+ int z = context.blockZ();
53-
+
54-
+ if (y < 64) return 1.0;
55-
+ if (y >= 64 + this.wallHeight) return -1.0;
56-
+
57-
+ int localX = Math.floorMod(x, this.cellSize);
58-
+ int localZ = Math.floorMod(z, this.cellSize);
59-
+ int cellX = Math.floorDiv(x, this.cellSize);
60-
+ int cellZ = Math.floorDiv(z, this.cellSize);
61-
+
62-
+ boolean onWallX = localX < this.wallThickness;
63-
+ boolean onWallZ = localZ < this.wallThickness;
64-
+
65-
+ if (!onWallX && !onWallZ) return -1.0;
66-
+
67-
+ if (onWallX && onWallZ) return 1.0;
68-
+
69-
+ int pathStart = this.wallThickness;
70-
+ int pathEnd = this.cellSize - this.wallThickness;
71-
+ int pathMid = (pathStart + pathEnd) / 2;
72-
+ int openingHalf = (pathEnd - pathStart) / 3;
73-
+
74-
+ if (onWallX) {
75-
+ if (localZ >= pathMid - openingHalf && localZ <= pathMid + openingHalf) {
76-
+ if (hasOpening(cellX, cellZ, 0)) return -1.0;
77-
+ }
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);
73+
+ int[] cand = new int[4];
74+
+ int n = 0;
75+
+ 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;
7881
+ }
82+
+ if (n == 0) return -1;
83+
+ long h = hash(cx, cz, qx * 31L + qz);
84+
+ return cand[(int) ((h & 0x7FFFFFFFL) % n)];
85+
+ }
7986
+
80-
+ if (onWallZ) {
81-
+ if (localX >= pathMid - openingHalf && localX <= pathMid + openingHalf) {
82-
+ if (hasOpening(cellX, cellZ, 1)) return -1.0;
83-
+ }
84-
+ }
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);
93+
+ }
8594
+
95+
+ @Override
96+
+ public double compute(final DensityFunction.FunctionContext ctx) {
97+
+ int x = ctx.blockX();
98+
+ int y = ctx.blockY();
99+
+ int z = ctx.blockZ();
100+
+ int floor = 64;
101+
+ if (y < floor) return 1.0;
102+
+ if (y >= floor + this.height) return -1.0;
103+
+ 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;
110+
+ if (!wx && !wz) return -1.0;
111+
+ 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;
86114
+ return 1.0;
87115
+ }
88116
+
@@ -105,15 +133,15 @@
105133
private record YClampedGradient(int fromY, int toY, double fromValue, double toValue) implements DensityFunction.SimpleFunction {
106134
private static final MapCodec<DensityFunctions.YClampedGradient> DATA_CODEC = RecordCodecBuilder.mapCodec(
107135
i -> i.group(
108-
--- a/net/minecraft/world/level/levelgen/RandomState.java 2025-12-07 14:45:36.108581661 +0100
109-
+++ /home/user/github/minecraft-decomp/client/src/main/java/a/net/minecraft/world/level/levelgen/RandomState.java 2025-12-07 14:28:09.234229820 +0100
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
110138
@@ -94,7 +94,8 @@
111139
}
112140
}
113141

114142
- this.router = settings.noiseRouter().mapAll(new NoiseWiringHelper());
115-
+ NoiseRouter baseRouter = settings.noiseRouter().mapAll(new NoiseWiringHelper());
116-
+ this.router = wrapMaze(baseRouter);
143+
+ NoiseRouter base = settings.noiseRouter().mapAll(new NoiseWiringHelper());
144+
+ this.router = wrapMaze(base);
117145
DensityFunction.Visitor noiseFlattener = new DensityFunction.Visitor() {
118146
private final Map<DensityFunction, DensityFunction> wrapped = new HashMap<>();
119147

@@ -122,24 +150,24 @@
122150
return this.oreRandom;
123151
}
124152
+
125-
+ private static NoiseRouter wrapMaze(final NoiseRouter router) {
126-
+ DensityFunction maze = DensityFunctions.mazeWall(32, 2, 20);
153+
+ private static NoiseRouter wrapMaze(final NoiseRouter r) {
154+
+ DensityFunction maze = DensityFunctions.mazeWall(8, 4, 100);
127155
+ return new NoiseRouter(
128-
+ router.barrierNoise(),
129-
+ router.fluidLevelFloodednessNoise(),
130-
+ router.fluidLevelSpreadNoise(),
131-
+ router.lavaNoise(),
132-
+ router.temperature(),
133-
+ router.vegetation(),
134-
+ router.continents(),
135-
+ router.erosion(),
136-
+ router.depth(),
137-
+ router.ridges(),
138-
+ router.preliminarySurfaceLevel(),
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(),
139167
+ maze,
140-
+ router.veinToggle(),
141-
+ router.veinRidged(),
142-
+ router.veinGap()
168+
+ r.veinToggle(),
169+
+ r.veinRidged(),
170+
+ r.veinGap()
143171
+ );
144172
+ }
145173
}

0 commit comments

Comments
 (0)