From 10d542ed14c0db32417090a1f3e89a41401800ea Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 25 Nov 2023 08:45:23 -0600 Subject: [PATCH] Fix incorrect ChunkWrapper IndexOutOfBounds checking --- .../common/wrappers/chunk/ChunkWrapper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 bef8b46b7..63cde7683 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 @@ -31,6 +31,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; +import com.seibel.distanthorizons.coreapi.ModInfo; import net.minecraft.client.multiplayer.ClientChunkCache; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; @@ -77,7 +78,7 @@ public class ChunkWrapper implements IChunkWrapper private static final Logger LOGGER = DhLoggerBuilder.getLogger(); /** useful for debugging, but can slow down chunk operations quite a bit due to being called every time. */ - private static final boolean RUN_RELATIVE_POS_INDEX_VALIDATION = false; + private static final boolean RUN_RELATIVE_POS_INDEX_VALIDATION = ModInfo.IS_DEV_BUILD; /** can be used for interactions with the underlying chunk where creating new BlockPos objects could cause issues for the garbage collector. */ private static final ThreadLocal MUTABLE_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new BlockPos.MutableBlockPos()); @@ -432,6 +433,8 @@ public class ChunkWrapper implements IChunkWrapper @Override public IBlockStateWrapper getBlockState(int relX, int relY, int relZ) { + this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, relY, relZ); + BlockPos.MutableBlockPos blockPos = MUTABLE_BLOCK_POS_REF.get(); blockPos.setX(relX); @@ -511,7 +514,7 @@ public class ChunkWrapper implements IChunkWrapper /** used to prevent accidentally attempting to get/set values outside this chunk's boundaries */ private void throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(int x, int y, int z) throws IndexOutOfBoundsException { - if (RUN_RELATIVE_POS_INDEX_VALIDATION) + if (!RUN_RELATIVE_POS_INDEX_VALIDATION) { return; }