diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index 20d58a38..a2a2fd6e 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -17,6 +17,7 @@ package baritone.chunk; +import baritone.Baritone; import baritone.utils.pathing.IBlockTypeAccess; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; @@ -120,6 +121,10 @@ public final class CachedWorld implements IBlockTypeAccess { } public final void save() { + if (!Baritone.settings().chunkCaching.get()) { + System.out.println("Not saving to disk; chunk caching is disabled."); + return; + } long start = System.currentTimeMillis(); this.cachedRegions.values().forEach(region -> { if (region != null) diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index bfc42219..7185b632 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -111,15 +111,14 @@ public final class GameEventHandler implements IGameEventListener, Helper { && type == ChunkEvent.Type.UNLOAD && mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ()); - if (Baritone.settings().chunkCaching.get()) { - if (isPostPopulate || isPreUnload) { - WorldProvider.INSTANCE.ifWorldLoaded(world -> { - Chunk chunk = mc.world.getChunk(event.getX(), event.getZ()); - world.cache.queueForPacking(chunk); - }); - } + if (isPostPopulate || isPreUnload) { + WorldProvider.INSTANCE.ifWorldLoaded(world -> { + Chunk chunk = mc.world.getChunk(event.getX(), event.getZ()); + world.cache.queueForPacking(chunk); + }); } + dispatch(listener -> listener.onChunkEvent(event)); } @@ -136,19 +135,17 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onWorldEvent(WorldEvent event) { - if (Baritone.settings().chunkCaching.get()) { - WorldProvider cache = WorldProvider.INSTANCE; + WorldProvider cache = WorldProvider.INSTANCE; - switch (event.getState()) { - case PRE: - cache.closeWorld(); - break; - case POST: - cache.closeWorld(); - if (event.getWorld() != null) - cache.initWorld(event.getWorld()); - break; - } + switch (event.getState()) { + case PRE: + cache.closeWorld(); + break; + case POST: + cache.closeWorld(); + if (event.getWorld() != null) + cache.initWorld(event.getWorld()); + break; } dispatch(listener -> listener.onWorldEvent(event)); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 6d8b3ac7..2c1df800 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -77,8 +77,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { int numNodes = 0; int numEmptyChunk = 0; boolean favoring = favoredPositions.isPresent(); - boolean cache = Baritone.settings().chunkCaching.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior - int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); + int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime) { @@ -112,11 +111,9 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { } BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); boolean isPositionCached = false; - if (cache) { - if (WorldProvider.INSTANCE.getCurrentWorld() != null) { - if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) { - isPositionCached = true; - } + if (WorldProvider.INSTANCE.getCurrentWorld() != null) { + if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) { + isPositionCached = true; } } if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 1c23e74a..a1013d7f 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -18,7 +18,7 @@ package baritone.utils; import baritone.Baritone; -import baritone.chunk.CachedWorld; +import baritone.chunk.WorldData; import baritone.chunk.WorldProvider; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; @@ -42,16 +42,15 @@ public class BlockStateInterface implements Helper { return chunk.getBlockState(pos); } } - if (Baritone.settings().chunkCaching.get()) { - CachedWorld world = WorldProvider.INSTANCE.getCurrentWorld().cache; - if (world != null) { - IBlockState type = world.getBlock(pos); - if (type != null) { - return type; - } + WorldData world = WorldProvider.INSTANCE.getCurrentWorld(); + if (world != null) { + IBlockState type = world.cache.getBlock(pos); + if (type != null) { + return type; } } + return Blocks.AIR.getDefaultState(); }