diff --git a/gradle.properties b/gradle.properties index 1dcf343..23dc669 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,6 +6,6 @@ loader_version=0.13.3 fabric_version=0.47.10+1.18.2 satin_version=1.7.2 -mod_version = 5.1.6 +mod_version = 5.1.7 maven_group = net.ludocrypt archives_base_name = limlib \ No newline at end of file diff --git a/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeComponent.java b/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeComponent.java index 8002420..efc19e5 100644 --- a/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeComponent.java +++ b/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeComponent.java @@ -13,8 +13,12 @@ public MazeComponent(int width, int height) { this.width = width; this.height = height; this.maze = new CellState[width * height]; - for (int i = 0; i < width * height; i++) { - this.maze[i] = new CellState(); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + CellState state = new CellState(); + state.setPosition(new Vec2i(x, y)); + this.maze[y * this.width + x] = state; + } } this.visitedCells = 1; } @@ -47,6 +51,7 @@ public boolean hasNeighbors(Vec2i vec) { public static class CellState { + private Vec2i position = new Vec2i(0, 0); private boolean north = false; private boolean east = false; private boolean south = false; @@ -73,6 +78,10 @@ public void visited() { this.visited = true; } + public void setPosition(Vec2i position) { + this.position = position; + } + public void setNorth(boolean north) { this.north = north; } @@ -93,6 +102,10 @@ public void setVisited(boolean visited) { this.visited = visited; } + public Vec2i getPosition() { + return position; + } + public boolean isNorth() { return north; } @@ -133,6 +146,14 @@ public int getY() { return y; } + @Override + public boolean equals(Object obj) { + if (obj instanceof Vec2i pos) { + return pos.x == this.x && pos.y == this.y; + } + return super.equals(obj); + } + @Override public String toString() { return "(" + this.x + ", " + this.y + ")"; diff --git a/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeGenerator.java b/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeGenerator.java index 3b40f42..4263031 100644 --- a/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeGenerator.java +++ b/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeGenerator.java @@ -13,11 +13,11 @@ import net.minecraft.world.chunk.Chunk; import net.minecraft.world.gen.chunk.ChunkGenerator; -public abstract class MazeGenerator { +public abstract class MazeGenerator { - public static final Codec> CODEC = LimlibRegistries.LIMINAL_MAZE_GENERATOR.getCodec().dispatchStable(MazeGenerator::getCodec, Function.identity()); + public static final Codec> CODEC = LimlibRegistries.LIMINAL_MAZE_GENERATOR.getCodec().dispatchStable(MazeGenerator::getCodec, Function.identity()); - private final HashMap mazes = new HashMap(30); + private final HashMap mazes = new HashMap(30); public final int width; public final int height; @@ -33,14 +33,14 @@ public MazeGenerator(int width, int height, int thickness, boolean redundancy, l this.seedModifier = seedModifier; } - public void generateMaze(BlockPos pos, Chunk chunk, ChunkRegion region, T chunkGenerator) { + public void generateMaze(BlockPos pos, Chunk chunk, ChunkRegion region, C chunkGenerator) { for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { BlockPos inPos = pos.add(x, 0, y); if (mod(inPos.getX(), thickness) == 0 && mod(inPos.getZ(), thickness) == 0) { BlockPos mazePos = new BlockPos(inPos.getX() - mod(inPos.getX(), (width * thickness)), 0, inPos.getZ() - mod(inPos.getZ(), (height * thickness))); - MazeComponent maze; + M maze; if (this.mazes.containsKey(mazePos)) { maze = this.mazes.get(mazePos); } else { @@ -53,21 +53,21 @@ public void generateMaze(BlockPos pos, Chunk chunk, ChunkRegion region, T chunkG CellState originCell = maze.cellState(redundancy ? mazeX + 2 : mazeX, redundancy ? mazeY + 2 : mazeY); - this.decorateCell(inPos, mazePos, chunk, region, chunkGenerator, originCell, this.thickness); + this.decorateCell(inPos, mazePos, chunk, region, chunkGenerator, maze, originCell, this.thickness); } } } } - public abstract MazeComponent newMaze(BlockPos mazePos, ChunkRegion region, Chunk chunk, T chunkGenerator, int width, int height, Random random); + public abstract M newMaze(BlockPos mazePos, ChunkRegion region, Chunk chunk, C chunkGenerator, int width, int height, Random random); - public abstract void decorateCell(BlockPos pos, BlockPos mazePos, Chunk chunk, ChunkRegion region, T chunkGenerator, CellState state, int thickness); + public abstract void decorateCell(BlockPos pos, BlockPos mazePos, Chunk chunk, ChunkRegion region, C chunkGenerator, M maze, CellState state, int thickness); - public HashMap getMazes() { + public HashMap getMazes() { return mazes; } - public abstract Codec> getCodec(); + public abstract Codec> getCodec(); protected int mod(int x, int n) { int r = x % n; diff --git a/src/main/java/net/ludocrypt/limlib/impl/LimlibRegistries.java b/src/main/java/net/ludocrypt/limlib/impl/LimlibRegistries.java index 1c59db6..5c84ac3 100644 --- a/src/main/java/net/ludocrypt/limlib/impl/LimlibRegistries.java +++ b/src/main/java/net/ludocrypt/limlib/impl/LimlibRegistries.java @@ -8,6 +8,7 @@ import net.ludocrypt.limlib.api.render.LiminalBaseEffects; import net.ludocrypt.limlib.api.render.LiminalShaderApplier; import net.ludocrypt.limlib.api.render.LiminalSkyRenderer; +import net.ludocrypt.limlib.api.world.maze.MazeComponent; import net.ludocrypt.limlib.api.world.maze.MazeGenerator; import net.minecraft.util.Identifier; import net.minecraft.util.registry.SimpleRegistry; @@ -22,6 +23,6 @@ public class LimlibRegistries { public static final SimpleRegistry> LIMINAL_SHADER_APPLIER = (SimpleRegistry>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_shader_applier")).attribute(RegistryAttribute.SYNCED).buildAndRegister(); public static final SimpleRegistry> LIMINAL_BASE_EFFECTS = (SimpleRegistry>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_base_effects")).attribute(RegistryAttribute.SYNCED).buildAndRegister(); - public static final SimpleRegistry>> LIMINAL_MAZE_GENERATOR = (SimpleRegistry>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_maze_generator")).attribute(RegistryAttribute.SYNCED).buildAndRegister(); + public static final SimpleRegistry>> LIMINAL_MAZE_GENERATOR = (SimpleRegistry>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_maze_generator")).attribute(RegistryAttribute.SYNCED).buildAndRegister(); }