chunk caching either way
This commit is contained in:
parent
b56dde8f7e
commit
14df84ef0e
@ -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)
|
||||
|
@ -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));
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user