From 40580e81c2a2c8113090250955b3e2ef8446f471 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sun, 3 Mar 2024 14:54:11 -0600 Subject: [PATCH] Fix ChunkWrapper returning block light 15 for out of bound positions Now it will return 0, which is more accurate --- .../wrappers/chunk/ChunkLightStorage.java | 35 +++++++++++++++---- .../common/wrappers/chunk/ChunkWrapper.java | 10 ++++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkLightStorage.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkLightStorage.java index 8d0a465c5..405c0fb95 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkLightStorage.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkLightStorage.java @@ -42,26 +42,49 @@ public class ChunkLightStorage /** the data stored in this storage, split up into 16x16x16 areas. */ public LightSection[] lightSections; + /** + * If the get method is called on a Y position above what's stored + * this value will be returned.

+ * + * This needs to be manually defined since sky and block lights behave differently + * for values both above and below what's defined. + */ + public int aboveMaxYValue; + /** @see ChunkLightStorage#aboveMaxYValue */ + public int belowMinYValue; - public ChunkLightStorage(int minY, int maxY) + + //=============// + // constructor // + //=============// + + public ChunkLightStorage(int minY, int maxY, int aboveMaxYValue, int belowMinYValue) { this.minY = minY; this.maxY = maxY; + + this.aboveMaxYValue = aboveMaxYValue; + this.belowMinYValue = belowMinYValue; } + //=====================// + // getters and setters // + //=====================// + public int get(int x, int y, int z) { if (y < this.minY) { - return 0; - } - if (y >= this.maxY) - { - return 15; + return this.belowMinYValue; } + else if (y >= this.maxY) + { + return this.aboveMaxYValue; + } + if (this.lightSections != null) { diff --git a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java index 55471663a..b49e01a74 100644 --- a/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java +++ b/common/src/main/java/com/seibel/distanthorizons/common/wrappers/chunk/ChunkWrapper.java @@ -358,7 +358,10 @@ public class ChunkWrapper implements IChunkWrapper { if (this.blockLightStorage == null) { - this.blockLightStorage = new ChunkLightStorage(this.getMinBuildHeight(), this.getMaxBuildHeight()); + this.blockLightStorage = new ChunkLightStorage( + this.getMinBuildHeight(), this.getMaxBuildHeight(), + // positions above and below the handled area should be unlit + LodUtil.MIN_MC_LIGHT, LodUtil.MIN_MC_LIGHT); } return this.blockLightStorage; } @@ -381,7 +384,10 @@ public class ChunkWrapper implements IChunkWrapper { if (this.skyLightStorage == null) { - this.skyLightStorage = new ChunkLightStorage(this.getMinBuildHeight(), this.getMaxBuildHeight()); + this.skyLightStorage = new ChunkLightStorage( + this.getMinBuildHeight(), this.getMaxBuildHeight(), + // positions above should be lit but positions below should be unlit + LodUtil.MAX_MC_LIGHT, LodUtil.MIN_MC_LIGHT); } return this.skyLightStorage; }