Skip to content

Commit

Permalink
possibly correct chunk scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Mar 30, 2024
1 parent 02f2d67 commit 7ed8a60
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 37 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.gradle.configureondemand=true
# Enable advanced multi-module optimizations (share tiny-remaper instance between projects)
fabric.loom.multiProjectOptimisation=true
# Mod Properties
baseVersion = 0.1.0-beta.25
baseVersion = 0.1.0-beta.26
defaultBranch = 1.20
branch = 1.20
36 changes: 18 additions & 18 deletions src/main/java/folk/sisby/surveyor/terrain/ChunkSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public ChunkSummary(World world, Chunk chunk, int[] layerHeights, Int2ObjectBiMa
int walkspaceHeight = 0;
int waterDepth = 0;
for (int layerIndex = 0; layerIndex < layerHeights.length - 1; layerIndex++) {
Block carpetBlock = null;
int carpetY = Integer.MAX_VALUE;
LayerSummary.FloorSummary foundFloor = null;
int carpetHeight = Integer.MAX_VALUE;
for (int y = layerHeights[layerIndex]; y > layerHeights[layerIndex + 1]; y--) {
for (int y = layerHeights[layerIndex]; y >= layerHeights[layerIndex + 1]; y--) {
int sectionIndex = chunk.getSectionIndex(y);
SectionSummary section = sections[sectionIndex];
if (section == null) {
Expand All @@ -57,30 +58,29 @@ public ChunkSummary(World world, Chunk chunk, int[] layerHeights, Int2ObjectBiMa
y = sectionBottom;
continue;
}

BlockState state = section.getBlockState(x, y, z);
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.

if (!state.blocksMovement() && fluid.matchesType(Fluids.EMPTY)) {
if (waterDepth > 0) walkspaceHeight = 0; // Erase walkspace when air below water (weird, but possible)
walkspaceHeight++;
carpetHeight = Integer.MAX_VALUE;
} else if (fluid.matchesType(Fluids.WATER) || fluid.matchesType(Fluids.FLOWING_WATER)) {
waterDepth = 0;
if (walkspaceHeight >= MINIMUM_AIR_DEPTH && state.getMapColor(world, new BlockPos(x, y, z)) != MapColor.CLEAR) {
carpetY = y;
carpetBlock = state.getBlock();
}
} else if (fluid.matchesType(Fluids.WATER) || fluid.matchesType(Fluids.FLOWING_WATER)) { // keep walkspace when traversing water
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);
} else { // Blocks Movement or Has Non-Water Fluid.
if (foundFloor == null) {
if (carpetY == y - 1) {
foundFloor = new LayerSummary.FloorSummary(carpetY, section.getBiomeEntry(x, carpetY, z, world.getBottomY(), world.getTopY()).value(), carpetBlock, world.getLightLevel(LightType.BLOCK, new BlockPos(x, carpetY - 1, z)), waterDepth);
} else if (walkspaceHeight >= MINIMUM_AIR_DEPTH && state.getMapColor(world, new BlockPos(x, y, z)) != MapColor.CLEAR && y > layerHeights[layerIndex + 1]) {
foundFloor = new LayerSummary.FloorSummary(y, section.getBiomeEntry(x, y, z, world.getBottomY(), world.getTopY()).value(), 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
23 changes: 6 additions & 17 deletions src/main/java/folk/sisby/surveyor/util/ArrayUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package folk.sisby.surveyor.util;

import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;

import java.util.Arrays;

public class ArrayUtil {
Expand All @@ -12,21 +9,13 @@ public static int[] ofSingle(int value, int size) {
return array;
}

public static int distinctCount(int[] ints) {
int count = 0;
IntSet counted = new IntOpenHashSet();
public static boolean isSingle(int[] ints) {
int min = Integer.MIN_VALUE;
int max = Integer.MAX_VALUE;
for(int i : ints) {
if (counted.contains(i)) continue;
counted.add(i);
count++;
}
return count;
}

public static int trimIndex(int[] ints, int value) {
for (int i = ints.length - 1; i >= 0; i--) {
if (ints[i] != value) return i + 1;
if (i > min) min = i;
if (i < max) max = i;
}
return 0;
return max == min;
}
}
2 changes: 1 addition & 1 deletion src/main/java/folk/sisby/surveyor/util/uints/UInts.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static UInts readBuf(PacketByteBuf buf, int cardinality) {
}

static UInts fromUInts(int[] uints, int defaultValue) {
return ArrayUtil.distinctCount(uints) > 1 ? ofMany(uints) : ofSingle(uints[0], defaultValue);
return ArrayUtil.isSingle(uints) ? ofSingle(uints[0], defaultValue) : ofMany(uints);
}

static UInts ofMany(int[] uints) {
Expand Down

0 comments on commit 7ed8a60

Please sign in to comment.