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 ba93d3755..b62bdbb08 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 @@ -76,6 +76,9 @@ public class ChunkWrapper implements IChunkWrapper private final byte[] blockLightArray; private final byte[] skyLightArray; + /** cache so we don't have to hit the vanilla chunk as often. */ + private final IBlockStateWrapper[] blockStateWrappers; + private ArrayList blockLightPosList = null; private boolean useDhLighting; @@ -115,6 +118,8 @@ public class ChunkWrapper implements IChunkWrapper this.blockLightArray = new byte[LodUtil.CHUNK_WIDTH * LodUtil.CHUNK_WIDTH * (this.getHeight() + 1)]; this.skyLightArray = new byte[LodUtil.CHUNK_WIDTH * LodUtil.CHUNK_WIDTH * (this.getHeight() + 1)]; + this.blockStateWrappers = new IBlockStateWrapper[LodUtil.CHUNK_WIDTH * LodUtil.CHUNK_WIDTH * (this.getHeight() + 1)]; + chunksNeedingClientLightUpdating.add(this); } @@ -314,7 +319,7 @@ public class ChunkWrapper implements IChunkWrapper } @Override - public List getBlockLightPosList() + public ArrayList getBlockLightPosList() { // only populate the list once if (this.blockLightPosList == null) @@ -372,7 +377,21 @@ public class ChunkWrapper implements IChunkWrapper @Override public IBlockStateWrapper getBlockState(int relX, int relY, int relZ) { - return BlockStateWrapper.fromBlockState(this.chunk.getBlockState(new BlockPos(relX, relY, relZ)), this.wrappedLevel); + this.throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(relX, relY, relZ); + + int index = this.relativeBlockPosToIndex(relX, relY, relZ); + IBlockStateWrapper cachedBlockState = this.blockStateWrappers[index]; + if (cachedBlockState != null) + { + return cachedBlockState; + } + else + { + // the wrapper is cached to prevent having to create a bunch of new BlockPos and hitting the vanilla chunk object + IBlockStateWrapper blockState = BlockStateWrapper.fromBlockState(this.chunk.getBlockState(new BlockPos(relX, relY, relZ)), this.wrappedLevel); + this.blockStateWrappers[index] = blockState; + return blockState; + } } @Override @@ -442,7 +461,10 @@ public class ChunkWrapper implements IChunkWrapper private void throwIndexOutOfBoundsIfRelativePosOutsideChunkBounds(int x, int y, int z) throws IndexOutOfBoundsException { if (RUN_RELATIVE_POS_INDEX_VALIDATION) + { return; + } + // FIXME +1 is to handle the fact that LodDataBuilder adds +1 to all block lighting calculations, also done in the constructor int minHeight = this.getMinBuildHeight(); diff --git a/coreSubProjects b/coreSubProjects index 7d84e05b1..d3865551a 160000 --- a/coreSubProjects +++ b/coreSubProjects @@ -1 +1 @@ -Subproject commit 7d84e05b1f18240df8dab79002d6d8103b5054a6 +Subproject commit d3865551a56b94b7fde500d09c1a181fafe1a827