increase efficiency of scanChunkInto by ~25%
This commit is contained in:
parent
c938983ff5
commit
9f3eaac3df
@ -45,7 +45,7 @@ public abstract class MixinBlockStateContainer implements IBlockStateContainer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Unique
|
@Unique
|
||||||
public IBlockState getFast(int x, int y, int z) {
|
public IBlockState getFast(int index) {
|
||||||
return palette.getBlockState(storage.getAt(y << 8 | z << 4 | x));
|
return palette.getBlockState(storage.getAt(index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
31
src/main/java/baritone/cache/WorldScanner.java
vendored
31
src/main/java/baritone/cache/WorldScanner.java
vendored
@ -116,26 +116,23 @@ public enum WorldScanner implements IWorldScanner {
|
|||||||
IBlockStateContainer bsc = (IBlockStateContainer) extendedblockstorage.getData();
|
IBlockStateContainer bsc = (IBlockStateContainer) extendedblockstorage.getData();
|
||||||
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
|
// the mapping of BlockStateContainer.getIndex from xyz to index is y << 8 | z << 4 | x;
|
||||||
// for better cache locality, iterate in that order
|
// for better cache locality, iterate in that order
|
||||||
for (int y = 0; y < 16; y++) {
|
int imax = 1 << 12;
|
||||||
for (int z = 0; z < 16; z++) {
|
for (int i = 0; i < imax; i++) {
|
||||||
for (int x = 0; x < 16; x++) {
|
IBlockState state = bsc.getFast(i);
|
||||||
IBlockState state = bsc.getFast(x, y, z);
|
if (filter.has(state)) {
|
||||||
if (filter.has(state)) {
|
int y = yReal | (i >> 8 & 15);
|
||||||
int yy = yReal | y;
|
if (result.size() >= max) {
|
||||||
if (result.size() >= max) {
|
if (Math.abs(y - playerY) < yLevelThreshold) {
|
||||||
if (Math.abs(yy - playerY) < yLevelThreshold) {
|
foundWithinY = true;
|
||||||
foundWithinY = true;
|
} else {
|
||||||
} else {
|
if (foundWithinY) {
|
||||||
if (foundWithinY) {
|
// have found within Y in this chunk, so don't need to consider outside Y
|
||||||
// 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
|
||||||
// TODO continue iteration to one more sorted Y coordinate block
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
result.add(new BlockPos(chunkX | x, yy, chunkZ | z));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result.add(new BlockPos(chunkX | (i & 15), y, chunkZ | (i >> 4 & 15)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,9 @@ public interface IBlockStateContainer {
|
|||||||
|
|
||||||
BitArray getStorage();
|
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);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user