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;
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)

View File

@ -111,14 +111,13 @@ 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);
});
}
}
dispatch(listener -> listener.onChunkEvent(event));
}
@ -136,7 +135,6 @@ public final class GameEventHandler implements IGameEventListener, Helper {
@Override
public final void onWorldEvent(WorldEvent event) {
if (Baritone.settings().chunkCaching.get()) {
WorldProvider cache = WorldProvider.INSTANCE;
switch (event.getState()) {
@ -149,7 +147,6 @@ public final class GameEventHandler implements IGameEventListener, Helper {
cache.initWorld(event.getWorld());
break;
}
}
dispatch(listener -> listener.onWorldEvent(event));
}

View File

@ -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,13 +111,11 @@ 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 (!isPositionCached && Minecraft.getMinecraft().world.getChunk(dest) instanceof EmptyChunk) {
numEmptyChunk++;
continue;

View File

@ -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,15 +42,14 @@ public class BlockStateInterface implements Helper {
return chunk.getBlockState(pos);
}
}
if (Baritone.settings().chunkCaching.get()) {
CachedWorld world = WorldProvider.INSTANCE.getCurrentWorld().cache;
WorldData world = WorldProvider.INSTANCE.getCurrentWorld();
if (world != null) {
IBlockState type = world.getBlock(pos);
IBlockState type = world.cache.getBlock(pos);
if (type != null) {
return type;
}
}
}
return Blocks.AIR.getDefaultState();
}