From 4bf12c7fc4aaca78c8d40fac12871db3818a7caf Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 19 Aug 2023 11:01:52 -0500 Subject: [PATCH] Fix lighting and LOD generation for snow layers --- .../dataObjects/transformers/LodDataBuilder.java | 16 +++++++++++++--- .../core/generation/DhLightingEngine.java | 15 +-------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java index 8f7c3b1c9..cafafa6b5 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/transformers/LodDataBuilder.java @@ -38,9 +38,19 @@ public class LodDataBuilder // FIXME: The +1 offset to reproduce the old behavior. Remove this when we get per-face lighting byte light = (byte) ((chunkWrapper.getBlockLight(x, lastY + 1, z) << 4) + chunkWrapper.getSkyLight(x, lastY + 1, z)); - // using a height map to reduce how many empty blocks positions we have to check would be preferable, but there are some world generators - // that don't work well with that, so we have to check the whole column - int y = chunkWrapper.getMaxBuildHeight(); + + // determine the starting Y Pos + int y = chunkWrapper.getLightBlockingHeightMapValue(x,z); + // go up until we reach open air or the world limit + IBlockStateWrapper topBlockState = chunkWrapper.getBlockState(x, y, z); + while (!topBlockState.isAir() && y < chunkWrapper.getMaxBuildHeight()) + { + // This is necessary in some edge cases with snow layers and some other blocks that may not appear in the height map but do block light. + // Interestingly this doesn't appear to be the case in the DhLightingEngine, if this same logic is added there the lighting breaks for the affected blocks. + y++; + topBlockState = chunkWrapper.getBlockState(x, y, z); + } + for (; y >= chunkWrapper.getMinBuildHeight(); y--) { diff --git a/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java b/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java index 93eae35ee..bbc035d04 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/generation/DhLightingEngine.java @@ -103,21 +103,8 @@ public class DhLightingEngine for (int relZ = 0; relZ < LodUtil.CHUNK_WIDTH; relZ++) { // get the light - int maxY = Math.max(chunk.getLightBlockingHeightMapValue(relX, relZ), chunk.getSolidHeightMapValue(relX, relZ)); - - IBlockStateWrapper blockState = chunk.getBlockState(relX, maxY, relZ); - // go up until we reach open air or the world limit - while (!blockState.isAir() && maxY < chunk.getMaxBuildHeight()) - { - // this shouldn't normally be necessary, but in the off change the height map is wrong, - // (like with a modded world generator) - // this should prevent generating skylights inside the ground - maxY++; - blockState = chunk.getBlockState(relX, maxY, relZ); - } - + int maxY = chunk.getLightBlockingHeightMapValue(relX, relZ); DhBlockPos skyLightPos = new DhBlockPos(chunk.getMinBlockX() + relX, maxY, chunk.getMinBlockZ() + relZ); - if (skyLightPos.y < chunk.getMinBuildHeight() || skyLightPos.y > chunk.getMaxBuildHeight()) { // this shouldn't normally happen