Skip to content

Commit b527557

Browse files
committed
Big Maze refactor
1 parent e496bdf commit b527557

16 files changed

+639
-393
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
org.gradle.jvmargs = -Xmx1G
22
org.gradle.parallel = true
33

4-
version = 10.0.2
4+
version = 11.0.0
55
maven_group = net.ludocrypt
66
archives_base_name = limlib
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
package net.ludocrypt.limlib.api.world;
2+
3+
import com.mojang.serialization.Codec;
4+
5+
import net.minecraft.util.BlockMirror;
6+
import net.minecraft.util.BlockRotation;
7+
import net.minecraft.util.StringIdentifiable;
8+
import net.minecraft.util.random.RandomGenerator;
9+
10+
public enum Manipulation implements StringIdentifiable {
11+
12+
NONE("none", BlockRotation.NONE, BlockMirror.NONE),
13+
CLOCKWISE_90("clockwise_90", BlockRotation.CLOCKWISE_90, BlockMirror.NONE),
14+
CLOCKWISE_180("180", BlockRotation.CLOCKWISE_180, BlockMirror.NONE),
15+
COUNTERCLOCKWISE_90("counterclockwise_90", BlockRotation.COUNTERCLOCKWISE_90, BlockMirror.NONE),
16+
FRONT_BACK("front_back", BlockRotation.NONE, BlockMirror.FRONT_BACK),
17+
LEFT_RIGHT("left_right", BlockRotation.NONE, BlockMirror.LEFT_RIGHT),
18+
TOP_LEFT_BOTTOM_RIGHT("top_left_bottom_right", BlockRotation.COUNTERCLOCKWISE_90, BlockMirror.LEFT_RIGHT),
19+
TOP_RIGHT_BOTTOM_LEFT("top_right_bottom_left", BlockRotation.CLOCKWISE_90, BlockMirror.LEFT_RIGHT);
20+
21+
public static final Codec<Manipulation> CODEC = StringIdentifiable.createCodec(Manipulation::values);
22+
final String id;
23+
final BlockRotation rotation;
24+
final BlockMirror mirror;
25+
26+
Manipulation(String id, BlockRotation rotation, BlockMirror mirror) {
27+
this.id = id;
28+
this.rotation = rotation;
29+
this.mirror = mirror;
30+
}
31+
32+
public BlockRotation getRotation() {
33+
return rotation;
34+
}
35+
36+
public BlockMirror getMirror() {
37+
return mirror;
38+
}
39+
40+
@Override
41+
public String asString() {
42+
return id;
43+
}
44+
45+
public static Manipulation random(RandomGenerator random) {
46+
return Manipulation.values()[random.nextInt(8)];
47+
}
48+
49+
public static Manipulation of(BlockRotation rotation) {
50+
return of(rotation, BlockMirror.NONE);
51+
}
52+
53+
public static Manipulation of(BlockMirror mirror) {
54+
return of(BlockRotation.NONE, mirror);
55+
}
56+
57+
public static Manipulation of(BlockRotation rotation, BlockMirror mirror) {
58+
return switch (rotation) {
59+
case NONE -> (switch (mirror) {
60+
case NONE -> NONE;
61+
case FRONT_BACK -> FRONT_BACK;
62+
case LEFT_RIGHT -> LEFT_RIGHT;
63+
});
64+
case CLOCKWISE_180 -> (switch (mirror) {
65+
case NONE -> CLOCKWISE_180;
66+
case FRONT_BACK -> LEFT_RIGHT;
67+
case LEFT_RIGHT -> FRONT_BACK;
68+
});
69+
case CLOCKWISE_90 -> (switch (mirror) {
70+
case NONE -> CLOCKWISE_90;
71+
case FRONT_BACK -> TOP_LEFT_BOTTOM_RIGHT;
72+
case LEFT_RIGHT -> TOP_RIGHT_BOTTOM_LEFT;
73+
});
74+
case COUNTERCLOCKWISE_90 -> (switch (mirror) {
75+
case NONE -> COUNTERCLOCKWISE_90;
76+
case FRONT_BACK -> TOP_RIGHT_BOTTOM_LEFT;
77+
case LEFT_RIGHT -> TOP_LEFT_BOTTOM_RIGHT;
78+
});
79+
};
80+
}
81+
82+
public Manipulation rotate(BlockRotation rotation) {
83+
return switch (rotation) {
84+
case NONE -> this;
85+
case CLOCKWISE_180 -> (switch (this) {
86+
case NONE -> CLOCKWISE_180;
87+
case FRONT_BACK -> LEFT_RIGHT;
88+
case LEFT_RIGHT -> FRONT_BACK;
89+
case CLOCKWISE_180 -> NONE;
90+
case CLOCKWISE_90 -> COUNTERCLOCKWISE_90;
91+
case COUNTERCLOCKWISE_90 -> CLOCKWISE_90;
92+
case TOP_LEFT_BOTTOM_RIGHT -> TOP_RIGHT_BOTTOM_LEFT;
93+
case TOP_RIGHT_BOTTOM_LEFT -> TOP_LEFT_BOTTOM_RIGHT;
94+
});
95+
case CLOCKWISE_90 -> (switch (this) {
96+
case NONE -> CLOCKWISE_90;
97+
case FRONT_BACK -> TOP_RIGHT_BOTTOM_LEFT;
98+
case LEFT_RIGHT -> TOP_LEFT_BOTTOM_RIGHT;
99+
case CLOCKWISE_180 -> COUNTERCLOCKWISE_90;
100+
case CLOCKWISE_90 -> CLOCKWISE_180;
101+
case COUNTERCLOCKWISE_90 -> NONE;
102+
case TOP_LEFT_BOTTOM_RIGHT -> FRONT_BACK;
103+
case TOP_RIGHT_BOTTOM_LEFT -> LEFT_RIGHT;
104+
});
105+
case COUNTERCLOCKWISE_90 -> (switch (this) {
106+
case NONE -> COUNTERCLOCKWISE_90;
107+
case FRONT_BACK -> TOP_LEFT_BOTTOM_RIGHT;
108+
case LEFT_RIGHT -> TOP_RIGHT_BOTTOM_LEFT;
109+
case CLOCKWISE_180 -> CLOCKWISE_90;
110+
case CLOCKWISE_90 -> NONE;
111+
case COUNTERCLOCKWISE_90 -> CLOCKWISE_180;
112+
case TOP_LEFT_BOTTOM_RIGHT -> LEFT_RIGHT;
113+
case TOP_RIGHT_BOTTOM_LEFT -> FRONT_BACK;
114+
});
115+
};
116+
}
117+
118+
public Manipulation mirror(BlockMirror mirror) {
119+
return switch (mirror) {
120+
case NONE -> this;
121+
case FRONT_BACK -> (switch (this) {
122+
case NONE -> FRONT_BACK;
123+
case FRONT_BACK -> NONE;
124+
case LEFT_RIGHT -> CLOCKWISE_180;
125+
case CLOCKWISE_180 -> LEFT_RIGHT;
126+
case CLOCKWISE_90 -> TOP_LEFT_BOTTOM_RIGHT;
127+
case COUNTERCLOCKWISE_90 -> TOP_RIGHT_BOTTOM_LEFT;
128+
case TOP_LEFT_BOTTOM_RIGHT -> CLOCKWISE_90;
129+
case TOP_RIGHT_BOTTOM_LEFT -> COUNTERCLOCKWISE_90;
130+
});
131+
case LEFT_RIGHT -> (switch (this) {
132+
case NONE -> LEFT_RIGHT;
133+
case FRONT_BACK -> CLOCKWISE_180;
134+
case LEFT_RIGHT -> NONE;
135+
case CLOCKWISE_180 -> FRONT_BACK;
136+
case CLOCKWISE_90 -> TOP_RIGHT_BOTTOM_LEFT;
137+
case COUNTERCLOCKWISE_90 -> TOP_LEFT_BOTTOM_RIGHT;
138+
case TOP_LEFT_BOTTOM_RIGHT -> COUNTERCLOCKWISE_90;
139+
case TOP_RIGHT_BOTTOM_LEFT -> CLOCKWISE_90;
140+
});
141+
};
142+
}
143+
144+
public Manipulation manipulate(Manipulation manipulation) {
145+
return this.rotate(manipulation.rotation).mirror(manipulation.mirror);
146+
}
147+
148+
public static Manipulation[] rotations() {
149+
return new Manipulation[] { Manipulation.NONE, Manipulation.CLOCKWISE_90, Manipulation.CLOCKWISE_180,
150+
Manipulation.COUNTERCLOCKWISE_90 };
151+
}
152+
153+
public static Manipulation[] mirrors() {
154+
return new Manipulation[] { Manipulation.NONE, Manipulation.FRONT_BACK, Manipulation.LEFT_RIGHT,
155+
Manipulation.TOP_LEFT_BOTTOM_RIGHT, Manipulation.TOP_RIGHT_BOTTOM_LEFT };
156+
}
157+
158+
}

src/main/java/net/ludocrypt/limlib/api/world/NbtPlacerUtil.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public NbtPlacerUtil(NbtCompound storedNbt, HashMap<BlockPos, Pair<BlockState, O
6565
this(storedNbt, positions, entities, lowestPos, sizePos.getX(), sizePos.getY(), sizePos.getZ());
6666
}
6767

68-
public NbtPlacerUtil manipulate(BlockRotation rotation, BlockMirror mirror) {
68+
public NbtPlacerUtil manipulate(Manipulation manipulation) {
6969
NbtList paletteList = storedNbt.getList("palette", 10);
7070
HashMap<Integer, BlockState> palette = new HashMap<Integer, BlockState>(paletteList.size());
7171
List<NbtCompound> paletteCompoundList = paletteList
@@ -79,13 +79,15 @@ public NbtPlacerUtil manipulate(BlockRotation rotation, BlockMirror mirror) {
7979
.put(i,
8080
NbtHelper
8181
.toBlockState(Registries.BLOCK.asLookup(), paletteCompoundList.get(i))
82-
.rotate(rotation)
83-
.mirror(mirror));
82+
.rotate(manipulation.getRotation())
83+
.mirror(manipulation.getMirror()));
8484
}
8585

8686
NbtList sizeList = storedNbt.getList("size", 3);
8787
BlockPos sizeVectorRotated = NbtPlacerUtil
88-
.mirror(new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2)).rotate(rotation), mirror);
88+
.mirror(
89+
new BlockPos(sizeList.getInt(0), sizeList.getInt(1), sizeList.getInt(2)).rotate(manipulation.getRotation()),
90+
manipulation.getMirror());
8991
BlockPos sizeVector = new BlockPos(Math.abs(sizeVectorRotated.getX()), Math.abs(sizeVectorRotated.getY()),
9092
Math.abs(sizeVectorRotated.getZ()));
9193
NbtList positionsList = storedNbt.getList("blocks", 10);
@@ -97,8 +99,10 @@ public NbtPlacerUtil manipulate(BlockRotation rotation, BlockMirror mirror) {
9799
.map(element -> (NbtCompound) element)
98100
.map((nbtCompound) -> Pair
99101
.of(NbtPlacerUtil
100-
.mirror(new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1),
101-
nbtCompound.getList("pos", 3).getInt(2)).rotate(rotation), mirror),
102+
.mirror(
103+
new BlockPos(nbtCompound.getList("pos", 3).getInt(0), nbtCompound.getList("pos", 3).getInt(1),
104+
nbtCompound.getList("pos", 3).getInt(2)).rotate(manipulation.getRotation()),
105+
manipulation.getMirror()),
102106
Pair
103107
.of(palette.get(nbtCompound.getInt("state")),
104108
nbtCompound.contains("nbt", NbtElement.COMPOUND_TYPE)
@@ -112,7 +116,7 @@ public NbtPlacerUtil manipulate(BlockRotation rotation, BlockMirror mirror) {
112116
.forEach(
113117
(pair) -> positions.put(pair.getFirst().subtract(positionsPairList.get(0).getFirst()), pair.getSecond()));
114118
return new NbtPlacerUtil(storedNbt, positions, storedNbt.getList("entities", 10),
115-
transformSize(sizeVector, rotation, mirror), sizeVector);
119+
transformSize(sizeVector, manipulation.getRotation(), manipulation.getMirror()), sizeVector);
116120
}
117121

118122
public static NbtPlacerUtil load(Identifier id, ResourceManager manager) {
@@ -234,23 +238,23 @@ public NbtPlacerUtil generateNbt(ChunkRegion region, Vec3i offset, BlockPos from
234238
return this;
235239
}
236240

237-
public NbtPlacerUtil spawnEntities(ChunkRegion region, BlockPos pos, BlockRotation rotation, BlockMirror mirror) {
238-
return spawnEntities(region, BlockPos.ORIGIN, pos, pos.add(this.sizeX, this.sizeY, this.sizeZ), rotation, mirror);
241+
public NbtPlacerUtil spawnEntities(ChunkRegion region, BlockPos pos, Manipulation manipulation) {
242+
return spawnEntities(region, BlockPos.ORIGIN, pos, pos.add(this.sizeX, this.sizeY, this.sizeZ), manipulation);
239243
}
240244

241245
public NbtPlacerUtil spawnEntities(ChunkRegion region, BlockPos offset, BlockPos from, BlockPos to,
242-
BlockRotation rotation, BlockMirror mirror) {
243-
this.entities.forEach((nbtElement) -> spawnEntity(nbtElement, region, offset, from, to, rotation, mirror));
246+
Manipulation manipulation) {
247+
this.entities.forEach((nbtElement) -> spawnEntity(nbtElement, region, offset, from, to, manipulation));
244248
return this;
245249
}
246250

247251
public NbtPlacerUtil spawnEntity(NbtElement nbtElement, ChunkRegion region, BlockPos offset, BlockPos from, BlockPos to,
248-
BlockRotation rotation, BlockMirror mirror) {
252+
Manipulation manipulation) {
249253
NbtCompound entityCompound = (NbtCompound) nbtElement;
250254
NbtList nbtPos = entityCompound.getList("pos", 6);
251255
Vec3d relativeLocation = mirror(
252-
rotate(new Vec3d(nbtPos.getDouble(0), nbtPos.getDouble(1), nbtPos.getDouble(2)), rotation), mirror)
253-
.subtract(Vec3d.of(lowestPos));
256+
rotate(new Vec3d(nbtPos.getDouble(0), nbtPos.getDouble(1), nbtPos.getDouble(2)), manipulation.getRotation()),
257+
manipulation.getMirror()).subtract(Vec3d.of(lowestPos));
254258
Vec3d realPosition = relativeLocation.add(Vec3d.of(from.subtract(offset)));
255259
BlockPos min = offset;
256260
BlockPos max = to.subtract(from).add(offset);
@@ -271,14 +275,16 @@ public NbtPlacerUtil spawnEntity(NbtElement nbtElement, ChunkRegion region, Bloc
271275
nbt.put("Pos", posList);
272276
NbtList rotationList = new NbtList();
273277
NbtList entityRotationList = nbt.getList("Rotation", 5);
274-
float yawRotation = applyMirror(applyRotation(entityRotationList.getFloat(0), rotation), mirror);
278+
float yawRotation = applyMirror(applyRotation(entityRotationList.getFloat(0), manipulation.getRotation()),
279+
manipulation.getMirror());
275280
rotationList.add(NbtFloat.of(yawRotation));
276281
rotationList.add(NbtFloat.of(entityRotationList.getFloat(1)));
277282
nbt.remove("Rotation");
278283
nbt.put("Rotation", rotationList);
279284

280285
if (nbt.contains("facing")) {
281-
Direction dir = mirror(rotation.rotate(Direction.fromHorizontal(nbt.getByte("facing"))), mirror);
286+
Direction dir = mirror(manipulation.getRotation().rotate(Direction.fromHorizontal(nbt.getByte("facing"))),
287+
manipulation.getMirror());
282288
nbt.remove("facing");
283289
nbt.putByte("facing", (byte) dir.getHorizontal());
284290
}

src/main/java/net/ludocrypt/limlib/api/world/chunk/AbstractNbtChunkGenerator.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import net.ludocrypt.limlib.api.world.FunctionMap;
66
import net.ludocrypt.limlib.api.world.LimlibHelper;
7+
import net.ludocrypt.limlib.api.world.Manipulation;
78
import net.ludocrypt.limlib.api.world.NbtGroup;
89
import net.ludocrypt.limlib.api.world.NbtPlacerUtil;
910
import net.minecraft.block.Block;
@@ -14,8 +15,6 @@
1415
import net.minecraft.loot.LootTables;
1516
import net.minecraft.nbt.NbtCompound;
1617
import net.minecraft.resource.ResourceManager;
17-
import net.minecraft.util.BlockMirror;
18-
import net.minecraft.util.BlockRotation;
1918
import net.minecraft.util.Identifier;
2019
import net.minecraft.util.math.BlockPos;
2120
import net.minecraft.world.ChunkRegion;
@@ -39,41 +38,37 @@ public AbstractNbtChunkGenerator(BiomeSource biomeSource, NbtGroup nbtGroup,
3938
}
4039

4140
public void generateNbt(ChunkRegion region, BlockPos at, Identifier id) {
42-
generateNbt(region, at, id, BlockRotation.NONE, BlockMirror.NONE);
41+
generateNbt(region, at, id, Manipulation.NONE);
4342
}
4443

45-
public void generateNbt(ChunkRegion region, BlockPos at, Identifier id, BlockRotation rotation) {
46-
generateNbt(region, at, id, rotation, BlockMirror.NONE);
47-
}
48-
49-
public void generateNbt(ChunkRegion region, BlockPos at, Identifier id, BlockMirror mirror) {
50-
generateNbt(region, at, id, BlockRotation.NONE, mirror);
51-
}
52-
53-
public void generateNbt(ChunkRegion region, BlockPos at, Identifier id, BlockRotation rotation, BlockMirror mirror) {
44+
public void generateNbt(ChunkRegion region, BlockPos at, Identifier id, Manipulation manipulation) {
5445

5546
try {
5647
structures
5748
.eval(id, region.getServer().getResourceManager())
58-
.manipulate(rotation, mirror)
49+
.manipulate(manipulation)
5950
.generateNbt(region, at, (pos, state, nbt) -> this.modifyStructure(region, pos, state, nbt))
60-
.spawnEntities(region, at, rotation, mirror);
51+
.spawnEntities(region, at, manipulation);
6152
} catch (Exception e) {
6253
e.printStackTrace();
6354
throw new NullPointerException("Attempted to load undefined structure \'" + id + "\'");
6455
}
6556

6657
}
6758

59+
public void generateNbt(ChunkRegion region, BlockPos offset, BlockPos from, BlockPos to, Identifier id) {
60+
generateNbt(region, offset, from, to, id, Manipulation.NONE);
61+
}
62+
6863
public void generateNbt(ChunkRegion region, BlockPos offset, BlockPos from, BlockPos to, Identifier id,
69-
BlockRotation rotation, BlockMirror mirror) {
64+
Manipulation manipulation) {
7065

7166
try {
7267
structures
7368
.eval(id, region.getServer().getResourceManager())
74-
.manipulate(rotation, mirror)
69+
.manipulate(manipulation)
7570
.generateNbt(region, offset, from, to, (pos, state, nbt) -> this.modifyStructure(region, pos, state, nbt))
76-
.spawnEntities(region, offset, from, to, rotation, mirror);
71+
.spawnEntities(region, offset, from, to, manipulation);
7772
} catch (Exception e) {
7873
e.printStackTrace();
7974
throw new NullPointerException("Attempted to load undefined structure \'" + id + "\'");

src/main/java/net/ludocrypt/limlib/api/world/chunk/LiminalChunkGenerator.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import net.minecraft.world.gen.chunk.ChunkGenerator;
2929
import net.minecraft.world.gen.chunk.VerticalBlockSample;
3030

31-
/**
32-
* A simplification of {@link ChunkGenerator}
33-
*/
3431
public abstract class LiminalChunkGenerator extends ChunkGenerator {
3532

3633
public LiminalChunkGenerator(BiomeSource biomeSource) {
@@ -53,19 +50,21 @@ public void populateEntities(ChunkRegion region) {
5350
@Override
5451
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, RandomState randomState,
5552
StructureManager structureManager, Chunk chunk) {
56-
throw new UnsupportedOperationException("populateNoise should never be called in LiminalChunkGenerator");
53+
throw new UnsupportedOperationException("Vanilla populateNoise should never be called in LiminalChunkGenerator");
5754
}
5855

5956
/**
60-
* How many chunks (distance) around the currently generating chunk from the
61-
* populateNoise method should be allowed to generate into.
57+
* The number of neighboring chunks which can be accessed for block placement. A
58+
* value of 0 means that only this chunk is accessible. A positive value means
59+
* that the given amount of neighbors are accessible in each direction. A
60+
* negative value means that this region shouldn't be used for block placement.
6261
*/
63-
public abstract int getChunkDistance();
62+
public abstract int getPlacementRadius();
6463

6564
/**
6665
* An extention of the base populateNoise method but with more variables. Use
6766
* ChunkRegion as opposed to world when setting blocks, as it allows you to
68-
* extend through multiple chunks in {@link getChunkDistance} away.
67+
* extend through multiple chunks in {@link getPlacementRadius} away.
6968
*/
7069
public abstract CompletableFuture<Chunk> populateNoise(ChunkRegion chunkRegion, ChunkStatus targetStatus,
7170
Executor executor, ServerWorld world, ChunkGenerator generator,

0 commit comments

Comments
 (0)