Skip to content

Commit

Permalink
new floor logic
Browse files Browse the repository at this point in the history
fix #10
  • Loading branch information
sisby-folk committed Mar 30, 2024
1 parent a68b07f commit 4e0d983
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/folk/sisby/surveyor/terrain/ChunkSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ChunkSummary(World world, Chunk chunk, int[] layerHeights, Int2ObjectBiMa
int waterDepth = 0;
for (int layerIndex = 0; layerIndex < layerHeights.length - 1; layerIndex++) {
LayerSummary.FloorSummary foundFloor = null;
int carpetHeight = Integer.MAX_VALUE;
for (int y = layerHeights[layerIndex]; y > layerHeights[layerIndex + 1]; y--) {
int sectionIndex = chunk.getSectionIndex(y);
SectionSummary section = sections[sectionIndex];
Expand All @@ -61,17 +62,25 @@ public ChunkSummary(World world, Chunk chunk, int[] layerHeights, Int2ObjectBiMa
Fluid fluid = state.getFluidState().getFluid();
if (fluid.matchesType(Fluids.EMPTY) && !state.blocksMovement()) { // The current block's air counts for space - a 2 block high walkway with a torch or grass is valid - the floor is the torch/grass.
walkspaceHeight++;
carpetHeight = Integer.MAX_VALUE;
} else if (fluid.matchesType(Fluids.WATER) || fluid.matchesType(Fluids.FLOWING_WATER)) {
waterDepth++;
}

if (state.blocksMovement()) {
if (foundFloor == null && walkspaceHeight > MINIMUM_AIR_DEPTH && state.getMapColor(world, new BlockPos(x, y, z)) != MapColor.CLEAR) {
Biome biome = section.getBiomeEntry(x, y, z, world.getBottomY(), world.getTopY()).value();
foundFloor = new LayerSummary.FloorSummary(y, biome, state.getBlock(), world.getLightLevel(LightType.BLOCK, new BlockPos(x, y - 1, z)), waterDepth);
carpetHeight = Integer.MAX_VALUE;
} else if (state.blocksMovement()) {
if (foundFloor == null && walkspaceHeight > MINIMUM_AIR_DEPTH) {
if (carpetHeight != Integer.MAX_VALUE) {
Biome biome = section.getBiomeEntry(x, carpetHeight, z, world.getBottomY(), world.getTopY()).value();
foundFloor = new LayerSummary.FloorSummary(carpetHeight, biome, section.getBlockState(x, carpetHeight, z).getBlock(), world.getLightLevel(LightType.BLOCK, new BlockPos(x, carpetHeight - 1, z)), waterDepth);
} else if (state.getMapColor(world, new BlockPos(x, y, z)) != MapColor.CLEAR) {
Biome biome = section.getBiomeEntry(x, y, z, world.getBottomY(), world.getTopY()).value();
foundFloor = new LayerSummary.FloorSummary(y, biome, state.getBlock(), world.getLightLevel(LightType.BLOCK, new BlockPos(x, y - 1, z)), waterDepth);
}
}
walkspaceHeight = 0;
waterDepth = 0;
carpetHeight = Integer.MAX_VALUE;
} else if (state.getMapColor(world, new BlockPos(x, y, z)) != MapColor.CLEAR) {
carpetHeight = y;
}
}
layerFloors[layerIndex][x * 16 + z] = foundFloor;
Expand Down

0 comments on commit 4e0d983

Please sign in to comment.