diff --git a/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java b/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java index 343bdda6..e3b7cbeb 100644 --- a/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java +++ b/src/launch/java/baritone/launch/mixins/MixinBlockStateContainer.java @@ -45,7 +45,7 @@ public abstract class MixinBlockStateContainer implements IBlockStateContainer { @Override @Unique - public IBlockState getFast(int x, int y, int z) { - return palette.getBlockState(storage.getAt(y << 8 | z << 4 | x)); + public IBlockState getFast(int index) { + return palette.getBlockState(storage.getAt(index)); } } diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 365c8bf7..3c314e71 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -116,26 +116,23 @@ public enum WorldScanner implements IWorldScanner { IBlockStateContainer bsc = (IBlockStateContainer) extendedblockstorage.getData(); // the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x; // for better cache locality, iterate in that order - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - for (int x = 0; x < 16; x++) { - IBlockState state = bsc.getFast(x, y, z); - if (filter.has(state)) { - int yy = yReal | y; - if (result.size() >= max) { - if (Math.abs(yy - playerY) < yLevelThreshold) { - foundWithinY = true; - } else { - if (foundWithinY) { - // have found within Y in this chunk, so don't need to consider outside Y - // TODO continue iteration to one more sorted Y coordinate block - return true; - } - } + int imax = 1 << 12; + for (int i = 0; i < imax; i++) { + IBlockState state = bsc.getFast(i); + if (filter.has(state)) { + int y = yReal | (i >> 8 & 15); + if (result.size() >= max) { + if (Math.abs(y - playerY) < yLevelThreshold) { + foundWithinY = true; + } else { + if (foundWithinY) { + // have found within Y in this chunk, so don't need to consider outside Y + // TODO continue iteration to one more sorted Y coordinate block + return true; } - result.add(new BlockPos(chunkX | x, yy, chunkZ | z)); } } + result.add(new BlockPos(chunkX | (i & 15), y, chunkZ | (i >> 4 & 15))); } } } diff --git a/src/main/java/baritone/utils/accessor/IBlockStateContainer.java b/src/main/java/baritone/utils/accessor/IBlockStateContainer.java index 735e183a..ad602f37 100644 --- a/src/main/java/baritone/utils/accessor/IBlockStateContainer.java +++ b/src/main/java/baritone/utils/accessor/IBlockStateContainer.java @@ -9,5 +9,9 @@ public interface IBlockStateContainer { BitArray getStorage(); - IBlockState getFast(int x, int y, int z); + IBlockState getFast(int index); + + default IBlockState getFast(int x, int y, int z) { + return getFast(y << 8 | z << 4 | x); + }; }