From 66da826eab56381c2de9cb3b80b7a30af34dd778 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 15 Dec 2018 22:25:50 -0800 Subject: [PATCH] fix toxic cloud --- .../java/baritone/cache/WorldScanner.java | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/main/java/baritone/cache/WorldScanner.java b/src/main/java/baritone/cache/WorldScanner.java index 30b67ded..3487a0c1 100644 --- a/src/main/java/baritone/cache/WorldScanner.java +++ b/src/main/java/baritone/cache/WorldScanner.java @@ -28,6 +28,7 @@ import net.minecraft.world.chunk.BlockStateContainer; import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; +import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -71,33 +72,7 @@ public enum WorldScanner implements IWorldScanner { continue; } allUnloaded = false; - ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); - chunkX = chunkX << 4; - chunkZ = chunkZ << 4; - for (int y0 = 0; y0 < 16; y0++) { - ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; - if (extendedblockstorage == null) { - continue; - } - int yReal = y0 << 4; - BlockStateContainer bsc = 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.get(x, y, z); - if (blocks.contains(state.getBlock())) { - int yy = yReal | y; - res.add(new BlockPos(chunkX | x, yy, chunkZ | z)); - if (Math.abs(yy - playerY) < yLevelThreshold) { - foundWithinY = true; - } - } - } - } - } - } + scanChunkInto(chunkX << 4, chunkZ << 4, chunk, blocks, res, max, yLevelThreshold, playerY); } } if ((allUnloaded && foundChunks) @@ -125,6 +100,11 @@ public enum WorldScanner implements IWorldScanner { } LinkedList res = new LinkedList<>(); + scanChunkInto(pos.x << 4, pos.z << 4, chunk, blocks, res, max, yLevelThreshold, playerY); + return res; + } + + public void scanChunkInto(int chunkX, int chunkZ, Chunk chunk, List search, Collection result, int max, int yLevelThreshold, int playerY) { ExtendedBlockStorage[] chunkInternalStorageArray = chunk.getBlockStorageArray(); for (int y0 = 0; y0 < 16; y0++) { ExtendedBlockStorage extendedblockstorage = chunkInternalStorageArray[y0]; @@ -133,21 +113,22 @@ public enum WorldScanner implements IWorldScanner { } int yReal = y0 << 4; BlockStateContainer bsc = 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.get(x, y, z); - if (blocks.contains(state.getBlock())) { + if (search.contains(state.getBlock())) { int yy = yReal | y; - res.add(new BlockPos((pos.x << 4) | x, yy, (pos.z << 4) | z)); - if (res.size() >= max || Math.abs(yy - playerY) < yLevelThreshold) { - return res; + result.add(new BlockPos(chunkX | x, yy, chunkZ | z)); + if (result.size() >= max || Math.abs(yy - playerY) < yLevelThreshold) { + return; } } } } } } - return res; } }