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 6825f5236..9a6e13199 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 @@ -41,6 +41,7 @@ import net.minecraft.world.level.levelgen.Heightmap; import com.seibel.distanthorizons.core.logging.DhLogger; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; #if MC_VER >= MC_1_17_1 import net.minecraft.core.QuartPos; @@ -81,6 +82,8 @@ public class ChunkWrapper implements IChunkWrapper private static final ThreadLocal MUTABLE_BLOCK_POS_REF = ThreadLocal.withInitial(() -> new BlockPos.MutableBlockPos()); private static final ThreadLocal MUTABLE_BLOCK_POS_WRAPPER_REF = ThreadLocal.withInitial(() -> new MutableBlockPosWrapper()); + public static final Set LOGGED_BLOCK_GET_ERRORS = Collections.newSetFromMap(new ConcurrentHashMap()); + private static boolean heightmapThreadWarningLogged = false; @@ -250,6 +253,7 @@ public class ChunkWrapper implements IChunkWrapper if (heightmapThreadWarningLogged && !DhApi.isDhThread()) { + heightmapThreadWarningLogged = true; LOGGER.warn("ChunkWrapper Height maps created on non-DH thread ["+Thread.currentThread().getName()+"]. This may cause stuttering."); } @@ -371,7 +375,19 @@ public class ChunkWrapper implements IChunkWrapper blockPos.setY(relY); blockPos.setZ(relZ); - return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(blockPos), this.wrappedLevel); + try + { + return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(blockPos), this.wrappedLevel); + } + catch (Exception e) + { + if (LOGGED_BLOCK_GET_ERRORS.add(e.getMessage())) + { + LOGGER.warn("Failed to get block from chunk ["+this.chunkPos+"] at relative block pos ["+relX+","+relY+","+relZ+"], air will be used instead. This error message will only be logged once. error: ["+e.getMessage()+"].", e); + } + + return BlockStateWrapper.AIR; + } } @Override @@ -383,8 +399,20 @@ public class ChunkWrapper implements IChunkWrapper pos.setX(relX); pos.setY(relY); pos.setZ(relZ); - - return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(pos), this.wrappedLevel, guess); + + try + { + return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(pos), this.wrappedLevel, guess); + } + catch (Exception e) + { + if (LOGGED_BLOCK_GET_ERRORS.add(e.getMessage())) + { + LOGGER.warn("Failed to get block from chunk ["+this.chunkPos+"] at relative block pos ["+relX+","+relY+","+relZ+"], air will be used instead. This error message will only be logged once. error: ["+e.getMessage()+"].", e); + } + + return BlockStateWrapper.AIR; + } } /**