chunk caching either way

This commit is contained in:
Leijurv 2018-08-23 13:39:13 -07:00
parent b56dde8f7e
commit 14df84ef0e
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 32 additions and 34 deletions

View File

@ -17,6 +17,7 @@
package baritone.chunk; package baritone.chunk;
import baritone.Baritone;
import baritone.utils.pathing.IBlockTypeAccess; import baritone.utils.pathing.IBlockTypeAccess;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
@ -120,6 +121,10 @@ public final class CachedWorld implements IBlockTypeAccess {
} }
public final void save() { 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(); long start = System.currentTimeMillis();
this.cachedRegions.values().forEach(region -> { this.cachedRegions.values().forEach(region -> {
if (region != null) if (region != null)

View File

@ -111,15 +111,14 @@ public final class GameEventHandler implements IGameEventListener, Helper {
&& type == ChunkEvent.Type.UNLOAD && type == ChunkEvent.Type.UNLOAD
&& mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ()); && mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ());
if (Baritone.settings().chunkCaching.get()) { if (isPostPopulate || isPreUnload) {
if (isPostPopulate || isPreUnload) { WorldProvider.INSTANCE.ifWorldLoaded(world -> {
WorldProvider.INSTANCE.ifWorldLoaded(world -> { Chunk chunk = mc.world.getChunk(event.getX(), event.getZ());
Chunk chunk = mc.world.getChunk(event.getX(), event.getZ()); world.cache.queueForPacking(chunk);
world.cache.queueForPacking(chunk); });
});
}
} }
dispatch(listener -> listener.onChunkEvent(event)); dispatch(listener -> listener.onChunkEvent(event));
} }
@ -136,19 +135,17 @@ public final class GameEventHandler implements IGameEventListener, Helper {
@Override @Override
public final void onWorldEvent(WorldEvent event) { public final void onWorldEvent(WorldEvent event) {
if (Baritone.settings().chunkCaching.get()) { WorldProvider cache = WorldProvider.INSTANCE;
WorldProvider cache = WorldProvider.INSTANCE;
switch (event.getState()) { switch (event.getState()) {
case PRE: case PRE:
cache.closeWorld(); cache.closeWorld();
break; break;
case POST: case POST:
cache.closeWorld(); cache.closeWorld();
if (event.getWorld() != null) if (event.getWorld() != null)
cache.initWorld(event.getWorld()); cache.initWorld(event.getWorld());
break; break;
}
} }
dispatch(listener -> listener.onWorldEvent(event)); dispatch(listener -> listener.onWorldEvent(event));

View File

@ -77,8 +77,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
int numNodes = 0; int numNodes = 0;
int numEmptyChunk = 0; int numEmptyChunk = 0;
boolean favoring = favoredPositions.isPresent(); 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(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get();
double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get(); double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get(); boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();
while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime) { while (!openSet.isEmpty() && numEmptyChunk < pathingMaxChunkBorderFetch && System.currentTimeMillis() < timeoutTime) {
@ -112,11 +111,9 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
} }
BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest(); BetterBlockPos dest = (BetterBlockPos) movementToGetToNeighbor.getDest();
boolean isPositionCached = false; boolean isPositionCached = false;
if (cache) { if (WorldProvider.INSTANCE.getCurrentWorld() != null) {
if (WorldProvider.INSTANCE.getCurrentWorld() != null) { if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) {
if (WorldProvider.INSTANCE.getCurrentWorld().cache.getBlock(dest) != null) { isPositionCached = true;
isPositionCached = true;
}
} }
} }
if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) { if (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) {

View File

@ -18,7 +18,7 @@
package baritone.utils; package baritone.utils;
import baritone.Baritone; import baritone.Baritone;
import baritone.chunk.CachedWorld; import baritone.chunk.WorldData;
import baritone.chunk.WorldProvider; import baritone.chunk.WorldProvider;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
@ -42,16 +42,15 @@ public class BlockStateInterface implements Helper {
return chunk.getBlockState(pos); return chunk.getBlockState(pos);
} }
} }
if (Baritone.settings().chunkCaching.get()) { WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
CachedWorld world = WorldProvider.INSTANCE.getCurrentWorld().cache; if (world != null) {
if (world != null) { IBlockState type = world.cache.getBlock(pos);
IBlockState type = world.getBlock(pos); if (type != null) {
if (type != null) { return type;
return type;
}
} }
} }
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
} }