Skip to content

Commit

Permalink
Fixes #3
Browse files Browse the repository at this point in the history
How the Fix works:
Previously, Growlichen, Kelp, Seagrass and more Blocks under Water would
cause the overlay to be rendered. This can be mitigated by checking the
FluidState of the Block - if it isn't empty, block the overlay from
being computed - and, in consequence, don't render it.
  • Loading branch information
andi-makes committed Nov 15, 2022
1 parent 0cb32c6 commit 856568c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main/java/dev/schmarrn/lighty/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public static class OverlayData {
}
}

public static boolean isBlocked(BlockState block, BlockState up) {
// If block with FluidState (think Kelp, Seagrass, Glowlichen underwater), disable overlay
return (!up.getFluidState().isEmpty()) ||
// MagmaBlocks caused a Crash - But Mobs can still spawn on them, I need to fix this
block.getBlock() instanceof MagmaBlock;
}

private static final List<OverlayData> cache = new ArrayList<>();
private static BlockPos oldPlayerPos = BlockPos.ORIGIN;

Expand All @@ -38,12 +45,14 @@ public static List<OverlayData> computeCache(BlockPos playerPos, ClientWorld wor
for (int z = -16; z <= 16; ++z) {
BlockPos pos = new BlockPos(playerPos.getX() + x, playerPos.getY() + y, playerPos.getZ() + z);
BlockPos posUp = pos.up();
Block up = world.getBlockState(posUp).getBlock();
BlockState up = world.getBlockState(posUp);
Block upBlock = up.getBlock();
BlockState block = world.getBlockState(pos);
boolean validSpawn = up.canMobSpawnInside();
if (!(block.getBlock() instanceof MagmaBlock)) {
validSpawn = validSpawn && block.allowsSpawning(world, pos, type);
boolean validSpawn = upBlock.canMobSpawnInside();
if (isBlocked(block, up)) {
continue;
}
validSpawn = validSpawn && world.getBlockState(pos).allowsSpawning(world, pos, type);

if (!validSpawn) {
continue;
Expand All @@ -62,11 +71,11 @@ public static List<OverlayData> computeCache(BlockPos playerPos, ClientWorld wor
}

double offset = 0;
if (up instanceof SnowBlock) { // snow layers
if (upBlock instanceof SnowBlock) { // snow layers
int layer = world.getBlockState(posUp).get(SnowBlock.LAYERS);
// One layer of snow is two pixels high, with one pixel being 1/16
offset = 2f / 16f * layer;
} else if (up instanceof CarpetBlock) {
} else if (upBlock instanceof CarpetBlock) {
// Carpet is just one pixel high
offset = 1f / 16f;
}
Expand Down

0 comments on commit 856568c

Please sign in to comment.