From 17839ee6838edd0091a6916de3e2d7a212d602a3 Mon Sep 17 00:00:00 2001 From: LudoCrypt <60561627+LudoCrypt@users.noreply.github.com> Date: Fri, 13 May 2022 19:02:43 -0500 Subject: [PATCH] Updated maze generator logic --- gradle.properties | 2 +- .../limlib/api/world/maze/MazeGenerator.java | 30 ++++++++----------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/gradle.properties b/gradle.properties index 0e91d60..1dcf343 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.5 +mod_version = 5.1.6 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/MazeGenerator.java b/src/main/java/net/ludocrypt/limlib/api/world/maze/MazeGenerator.java index c8a4ea6..3b40f42 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 @@ -34,44 +34,38 @@ public MazeGenerator(int width, int height, int thickness, boolean redundancy, l } public void generateMaze(BlockPos pos, Chunk chunk, ChunkRegion region, T chunkGenerator) { - if (thickness < 1) - throw new UnsupportedOperationException("Thickness can not be less than 1"); - 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 * 2)), 0, inPos.getZ() - mod(inPos.getZ(), (height * thickness * 2))); + BlockPos mazePos = new BlockPos(inPos.getX() - mod(inPos.getX(), (width * thickness)), 0, inPos.getZ() - mod(inPos.getZ(), (height * thickness))); MazeComponent maze; if (this.mazes.containsKey(mazePos)) { maze = this.mazes.get(mazePos); } else { - maze = this.newMaze(region, chunk, chunkGenerator, redundancy ? width + 4 : width, redundancy ? height + 4 : height, new Random(blockSeed(mazePos.getX(), mazePos.getZ(), seedModifier))); + maze = this.newMaze(mazePos, region, chunk, chunkGenerator, redundancy ? width + 4 : width, redundancy ? height + 4 : height, new Random(blockSeed(mazePos.getX(), mazePos.getZ(), seedModifier))); this.mazes.put(mazePos, maze); } - BlockPos originPos = new BlockPos(inPos.getX() - mod(inPos.getX(), (2 * thickness)), 0, inPos.getZ() - mod(inPos.getZ(), (2 * thickness))); - - boolean isOpenCell = mod(inPos.getX(), (2 * thickness)) == 0 && mod(inPos.getZ(), (2 * thickness)) == 0; - boolean isWallCell = mod(inPos.getX(), (2 * thickness)) == thickness && mod(inPos.getZ(), (2 * thickness)) == thickness; - boolean isTopCell = mod(inPos.getX(), (2 * thickness)) == thickness && mod(inPos.getZ(), (2 * thickness)) == 0; - boolean isSideCell = mod(inPos.getX(), (2 * thickness)) == 0 && mod(inPos.getZ(), (2 * thickness)) == thickness; - - int mazeX = mod(originPos.getX(), (width * thickness * 2)) / (2 * thickness); - int mazeY = mod(originPos.getZ(), (height * thickness * 2)) / (2 * thickness); + int mazeX = (inPos.getX() - mazePos.getX()) / thickness; + int mazeY = (inPos.getZ() - mazePos.getZ()) / thickness; - CellState originCell = maze.cellState(redundancy ? mazeX + 2 : mazeX, redundancy ? mazeY + 2 : mazeX); + CellState originCell = maze.cellState(redundancy ? mazeX + 2 : mazeX, redundancy ? mazeY + 2 : mazeY); - this.decorateCell(inPos, originPos, chunk, region, chunkGenerator, originCell, isOpenCell, isWallCell, isTopCell, isSideCell, thickness); + this.decorateCell(inPos, mazePos, chunk, region, chunkGenerator, originCell, this.thickness); } } } } - public abstract MazeComponent newMaze(ChunkRegion region, Chunk chunk, T chunkGenerator, int width, int height, Random random); + public abstract MazeComponent newMaze(BlockPos mazePos, ChunkRegion region, Chunk chunk, T chunkGenerator, int width, int height, Random random); - public abstract void decorateCell(BlockPos pos, BlockPos origin, Chunk chunk, ChunkRegion region, T chunkGenerator, CellState state, boolean isOpen, boolean isWall, boolean isTopCell, boolean isSideCell, int thickness); + public abstract void decorateCell(BlockPos pos, BlockPos mazePos, Chunk chunk, ChunkRegion region, T chunkGenerator, CellState state, int thickness); + + public HashMap getMazes() { + return mazes; + } public abstract Codec> getCodec();