forked from RepoMirrors/baritone
cache chunk in BlockStateInterface
This commit is contained in:
parent
836b41a3aa
commit
0ee93aea23
|
@ -31,6 +31,7 @@ import net.minecraft.world.chunk.Chunk;
|
|||
public class BlockStateInterface implements Helper {
|
||||
|
||||
public static int numBlockStateLookups = 0;
|
||||
private static Chunk prev = null;
|
||||
|
||||
public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability
|
||||
numBlockStateLookups++;
|
||||
|
@ -39,8 +40,18 @@ public class BlockStateInterface implements Helper {
|
|||
return Blocks.AIR.getDefaultState();
|
||||
|
||||
if (!Baritone.settings().pathThroughCachedOnly.get()) {
|
||||
Chunk cached = prev;
|
||||
// there's great cache locality in block state lookups
|
||||
// generally it's within each movement
|
||||
// if it's the same chunk as last time
|
||||
// we can just skip the mc.world.getChunk lookup
|
||||
// which is a Long2ObjectOpenHashMap.get
|
||||
if (cached != null && cached.x == pos.getX() >> 4 && cached.z == pos.getZ() >> 4) {
|
||||
return cached.getBlockState(pos);
|
||||
}
|
||||
Chunk chunk = mc.world.getChunk(pos);
|
||||
if (chunk.isLoaded()) {
|
||||
prev = chunk;
|
||||
return chunk.getBlockState(pos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue