From b228f4c6fb6d8a952634a5949dc3dba2145f5f75 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Fri, 23 Nov 2018 09:03:51 -0800 Subject: [PATCH] remove extraneous checks in bsi --- .../pathing/movement/MovementHelper.java | 2 +- .../baritone/utils/BlockStateInterface.java | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index ff73b0f2..917adc7c 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -86,7 +86,7 @@ public interface MovementHelper extends ActionCosts, Helper { // so the only remaining dynamic isPassables are snow and trapdoor // if they're cached as a top block, we don't know their metadata // default to true (mostly because it would otherwise make long distance pathing through snowy biomes impossible) - if (bsi.getWorld().getChunk(x >> 4, z >> 4) instanceof EmptyChunk) { + if (!bsi.worldContainsLoadedChunk(x, z)) { return true; } if (snow) { diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 9b6401e9..b6b264d0 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -31,7 +31,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.chunk.EmptyChunk; /** * Wraps get for chuck caching capability @@ -40,7 +39,6 @@ import net.minecraft.world.chunk.EmptyChunk; */ public class BlockStateInterface { - private final World world; private final Long2ObjectMap loadedChunks; private final WorldData worldData; @@ -55,15 +53,14 @@ public class BlockStateInterface { public BlockStateInterface(World world, WorldData worldData) { this.worldData = worldData; - this.world = world; this.loadedChunks = ((IChunkProviderClient) world.getChunkProvider()).loadedChunks(); if (!Minecraft.getMinecraft().isCallingFromMinecraftThread()) { throw new IllegalStateException(); } } - public World getWorld() { - return world; + public boolean worldContainsLoadedChunk(int blockX, int blockZ) { + return loadedChunks.containsKey(ChunkPos.asLong(blockX >> 4, blockZ >> 4)); } public static Block getBlock(IPlayerContext ctx, BlockPos pos) { // won't be called from the pathing thread because the pathing thread doesn't make a single blockpos pog @@ -98,13 +95,9 @@ public class BlockStateInterface { if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) { return cached.getBlockState(x, y, z); } - Chunk c2 = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4)); - Chunk chunk = world.getChunk(x >> 4, z >> 4); + Chunk chunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4)); - if ((c2 != null && c2 != chunk) || (c2 == null && !(chunk instanceof EmptyChunk))) { - throw new IllegalStateException((((IChunkProviderClient) world.getChunkProvider()).loadedChunks() == loadedChunks) + " " + x + " " + y + " " + c2 + " " + chunk); - } - if (chunk.isLoaded()) { + if (chunk != null && chunk.isLoaded()) { prev = chunk; return chunk.getBlockState(x, y, z); } @@ -135,8 +128,8 @@ public class BlockStateInterface { if (prevChunk != null && prevChunk.x == x >> 4 && prevChunk.z == z >> 4) { return true; } - prevChunk = world.getChunk(x >> 4, z >> 4); - if (prevChunk.isLoaded()) { + prevChunk = loadedChunks.get(ChunkPos.asLong(x >> 4, z >> 4)); + if (prevChunk != null && prevChunk.isLoaded()) { prev = prevChunk; return true; }