cache chunk in BlockStateInterface, fixes #113
This commit is contained in:
parent
7cd0b186a9
commit
a93af3404b
@ -30,6 +30,8 @@ import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
public class BlockStateInterface implements Helper {
|
||||
|
||||
private static Chunk prev = null;
|
||||
|
||||
public static IBlockState get(BlockPos pos) { // wrappers for chunk caching capability
|
||||
|
||||
// Invalid vertical position
|
||||
@ -37,8 +39,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
Block a user