Skip to content

Commit

Permalink
update maze stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
LudoCrypt committed May 14, 2022
1 parent 17839ee commit 0f51535
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 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.6
mod_version = 5.1.7
maven_group = net.ludocrypt
archives_base_name = limlib
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -93,6 +102,10 @@ public void setVisited(boolean visited) {
this.visited = visited;
}

public Vec2i getPosition() {
return position;
}

public boolean isNorth() {
return north;
}
Expand Down Expand Up @@ -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 + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.gen.chunk.ChunkGenerator;

public abstract class MazeGenerator<T extends ChunkGenerator> {
public abstract class MazeGenerator<C extends ChunkGenerator, M extends MazeComponent> {

public static final Codec<MazeGenerator<? extends ChunkGenerator>> CODEC = LimlibRegistries.LIMINAL_MAZE_GENERATOR.getCodec().dispatchStable(MazeGenerator::getCodec, Function.identity());
public static final Codec<MazeGenerator<? extends ChunkGenerator, ? extends MazeComponent>> CODEC = LimlibRegistries.LIMINAL_MAZE_GENERATOR.getCodec().dispatchStable(MazeGenerator::getCodec, Function.identity());

private final HashMap<BlockPos, MazeComponent> mazes = new HashMap<BlockPos, MazeComponent>(30);
private final HashMap<BlockPos, M> mazes = new HashMap<BlockPos, M>(30);

public final int width;
public final int height;
Expand All @@ -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 {
Expand All @@ -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<BlockPos, MazeComponent> getMazes() {
public HashMap<BlockPos, M> getMazes() {
return mazes;
}

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

protected int mod(int x, int n) {
int r = x % n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,6 @@ public class LimlibRegistries {
public static final SimpleRegistry<Codec<? extends LiminalShaderApplier>> LIMINAL_SHADER_APPLIER = (SimpleRegistry<Codec<? extends LiminalShaderApplier>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_shader_applier")).attribute(RegistryAttribute.SYNCED).buildAndRegister();
public static final SimpleRegistry<Codec<? extends LiminalBaseEffects>> LIMINAL_BASE_EFFECTS = (SimpleRegistry<Codec<? extends LiminalBaseEffects>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_base_effects")).attribute(RegistryAttribute.SYNCED).buildAndRegister();

public static final SimpleRegistry<Codec<? extends MazeGenerator<? extends ChunkGenerator>>> LIMINAL_MAZE_GENERATOR = (SimpleRegistry<Codec<? extends MazeGenerator<? extends ChunkGenerator>>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_maze_generator")).attribute(RegistryAttribute.SYNCED).buildAndRegister();
public static final SimpleRegistry<Codec<? extends MazeGenerator<? extends ChunkGenerator, ? extends MazeComponent>>> LIMINAL_MAZE_GENERATOR = (SimpleRegistry<Codec<? extends MazeGenerator<? extends ChunkGenerator, ? extends MazeComponent>>>) (Object) FabricRegistryBuilder.createSimple(Codec.class, new Identifier("limlib", "limlib_maze_generator")).attribute(RegistryAttribute.SYNCED).buildAndRegister();

}

0 comments on commit 0f51535

Please sign in to comment.