fix blockstateinterface

This commit is contained in:
Leijurv 2018-11-11 17:36:54 -08:00
parent 903b1b16a4
commit e3cb164723
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
4 changed files with 36 additions and 36 deletions

View File

@ -22,7 +22,6 @@ import baritone.api.event.events.*;
import baritone.api.event.events.type.EventState;
import baritone.api.event.listener.IGameEventListener;
import baritone.cache.WorldProvider;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import net.minecraft.world.chunk.Chunk;
@ -98,8 +97,6 @@ public final class GameEventHandler implements IGameEventListener, Helper {
public final void onWorldEvent(WorldEvent event) {
WorldProvider cache = baritone.getWorldProvider();
BlockStateInterface.clearCachedChunk();
if (event.getState() == EventState.POST) {
cache.closeWorld();
if (event.getWorld() != null) {

View File

@ -25,7 +25,6 @@ import baritone.api.utils.BetterBlockPos;
import baritone.pathing.calc.openset.BinaryHeapOpenSet;
import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.Moves;
import baritone.utils.BlockStateInterface;
import baritone.utils.Helper;
import baritone.utils.pathing.BetterWorldBorder;
import baritone.utils.pathing.MutableMoveResult;
@ -66,7 +65,6 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
MutableMoveResult res = new MutableMoveResult();
HashSet<Long> favored = favoredPositions.orElse(null);
BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder());
BlockStateInterface.clearCachedChunk();
long startTime = System.nanoTime() / 1000000L;
boolean slowPath = Baritone.settings().slowPath.get();
if (slowPath) {
@ -100,7 +98,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel
for (Moves moves : Moves.values()) {
int newX = currentNode.x + moves.xOffset;
int newZ = currentNode.z + moves.zOffset;
if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !BlockStateInterface.isLoaded(calcContext, newX, newZ)) {
if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !calcContext.isLoaded(newX, newZ)) {
// only need to check if the destination is a loaded chunk if it's in a different chunk than the start of the movement
if (!moves.dynamicXZ) { // only increment the counter if the movement would have gone out of bounds guaranteed
numEmptyChunk++;

View File

@ -43,6 +43,7 @@ public class CalculationContext {
private final EntityPlayerSP player;
private final World world;
private final BlockStateInterface bsi;
private final ToolSet toolSet;
private final boolean hasWaterBucket;
private final boolean hasThrowaway;
@ -58,6 +59,8 @@ public class CalculationContext {
public CalculationContext() {
this.player = Helper.HELPER.player();
this.world = Helper.HELPER.world();
this.bsi = new BlockStateInterface(world, Baritone.INSTANCE.getWorldProvider().getCurrentWorld()); // TODO TODO TODO
// new CalculationContext() needs to happen, can't add an argument (i'll beat you), can we get the world provider from currentlyTicking?
this.toolSet = new ToolSet(player);
this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(false);
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && !world.provider.isNether();
@ -80,7 +83,15 @@ public class CalculationContext {
}
public IBlockState get(int x, int y, int z) {
return BlockStateInterface.get(world, x, y, z);
return bsi.get0(x, y, z); // laughs maniacally
}
public boolean isLoaded(int x, int z) {
return bsi.isLoaded(x, z);
}
public BlockStateInterface bsi() {
return bsi;
}
public IBlockState get(BlockPos pos) {

View File

@ -20,7 +20,6 @@ package baritone.utils;
import baritone.Baritone;
import baritone.cache.CachedRegion;
import baritone.cache.WorldData;
import baritone.pathing.movement.CalculationContext;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
@ -35,21 +34,31 @@ import net.minecraft.world.chunk.Chunk;
*/
public class BlockStateInterface implements Helper {
private static Chunk prev = null;
private static CachedRegion prevCached = null;
private final World world;
private final WorldData worldData;
private Chunk prev = null;
private CachedRegion prevCached = null;
private static final IBlockState AIR = Blocks.AIR.getDefaultState();
public BlockStateInterface(World world, WorldData worldData) {
this.worldData = worldData;
this.world = world;
}
public static Block getBlock(BlockPos pos) { // won't be called from the pathing thread because the pathing thread doesn't make a single blockpos pog
return get(pos).getBlock();
}
public static IBlockState get(BlockPos pos) {
return get(pos.getX(), pos.getY(), pos.getZ());
// this is the version thats called from updatestate and stuff, not from cost calculation
// doesn't need to be fast or cached actually
return Helper.HELPER.world().getBlockState(pos);
}
public static IBlockState get(int x, int y, int z) {
return get(Helper.HELPER.world(), x, y, z);
}
public static IBlockState get(World world, int x, int y, int z) {
public IBlockState get0(int x, int y, int z) {
// Invalid vertical position
if (y < 0 || y >= 256) {
@ -77,7 +86,6 @@ public class BlockStateInterface implements Helper {
// except here, it's 512x512 tiles instead of 16x16, so even better repetition
CachedRegion cached = prevCached;
if (cached == null || cached.getX() != x >> 9 || cached.getZ() != z >> 9) {
WorldData worldData = Baritone.INSTANCE.getWorldProvider().getCurrentWorld();
if (worldData == null) {
return AIR;
}
@ -95,12 +103,12 @@ public class BlockStateInterface implements Helper {
return type;
}
public static boolean isLoaded(CalculationContext context, int x, int z) {
public boolean isLoaded(int x, int z) {
Chunk prevChunk = prev;
if (prevChunk != null && prevChunk.x == x >> 4 && prevChunk.z == z >> 4) {
return true;
}
prevChunk = context.world().getChunk(x >> 4, z >> 4);
prevChunk = world.getChunk(x >> 4, z >> 4);
if (prevChunk.isLoaded()) {
prev = prevChunk;
return true;
@ -109,28 +117,14 @@ public class BlockStateInterface implements Helper {
if (prevRegion != null && prevRegion.getX() == x >> 9 && prevRegion.getZ() == z >> 9) {
return prevRegion.isCached(x & 511, z & 511);
}
WorldData world = Baritone.INSTANCE.getWorldProvider().getCurrentWorld();
if (world == null) {
if (worldData == null) {
return false;
}
prevRegion = world.cache.getRegion(x >> 9, z >> 9);
prevRegion = worldData.cache.getRegion(x >> 9, z >> 9);
if (prevRegion == null) {
return false;
}
prevCached = prevRegion;
return prevRegion.isCached(x & 511, z & 511);
}
public static void clearCachedChunk() {
prev = null;
prevCached = null;
}
public static Block getBlock(BlockPos pos) {
return get(pos).getBlock();
}
public static Block getBlock(int x, int y, int z) {
return get(x, y, z).getBlock();
}
}