Skip to content

Commit

Permalink
Updated maze generator logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed May 14, 2022
1 parent b6fb772 commit 17839ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockPos, MazeComponent> getMazes() {
return mazes;
}

public abstract Codec<? extends MazeGenerator<? extends ChunkGenerator>> getCodec();

Expand Down

0 comments on commit 17839ee

Please sign in to comment.