diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 69dc1b2a..6df47147 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -82,6 +82,8 @@ public enum Baritone implements IBaritone { private PathingControlManager pathingControlManager; + private WorldProvider worldProvider; + private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); Baritone() { @@ -115,6 +117,8 @@ public enum Baritone implements IBaritone { getToBlockProcess = new GetToBlockProcess(this); } + this.worldProvider = new WorldProvider(); + if (BaritoneAutoTest.ENABLE_AUTO_TEST) { registerEventListener(BaritoneAutoTest.INSTANCE); } @@ -194,7 +198,7 @@ public enum Baritone implements IBaritone { @Override public WorldProvider getWorldProvider() { - return WorldProvider.INSTANCE; + return worldProvider; } @Override diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 510cecff..1e8e069a 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -26,7 +26,6 @@ import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.type.EventState; import baritone.cache.Waypoint; -import baritone.cache.WorldProvider; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import net.minecraft.block.BlockBed; @@ -122,13 +121,13 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior, H @Override public void onBlockInteract(BlockInteractEvent event) { if (event.getType() == BlockInteractEvent.Type.USE && BlockStateInterface.getBlock(event.getPos()) instanceof BlockBed) { - WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos())); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("bed", Waypoint.Tag.BED, event.getPos())); } } @Override public void onPlayerDeath() { - WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, playerFeet())); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("death", Waypoint.Tag.DEATH, playerFeet())); } private Optional getInventoryFromWindow(int windowId) { @@ -143,7 +142,7 @@ public final class MemoryBehavior extends Behavior implements IMemoryBehavior, H } private WorldDataContainer getCurrentContainer() { - return this.worldDataContainers.computeIfAbsent(WorldProvider.INSTANCE.getCurrentWorld(), data -> new WorldDataContainer()); + return this.worldDataContainers.computeIfAbsent(baritone.getWorldProvider().getCurrentWorld(), data -> new WorldDataContainer()); } @Override diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index ad04755b..b775902e 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -190,7 +190,7 @@ public final class CachedWorld implements ICachedWorld, Helper { * If we are still in this world and dimension, return player feet, otherwise return most recently modified chunk */ private BlockPos guessPosition() { - WorldData data = WorldProvider.INSTANCE.getCurrentWorld(); + WorldData data = Baritone.INSTANCE.getWorldProvider().getCurrentWorld(); if (data != null && data.getCachedWorld() == this) { return playerFeet(); } diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 45b46fdb..d6f3aab1 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -39,11 +39,9 @@ import java.util.function.Consumer; * @author Brady * @since 8/4/2018 11:06 AM */ -public enum WorldProvider implements IWorldProvider, Helper { +public class WorldProvider implements IWorldProvider, Helper { - INSTANCE; - - private final Map worldCache = new HashMap<>(); + private static final Map worldCache = new HashMap<>(); // this is how the bots have the same cached world private WorldData currentWorld; diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index b42b3e06..2859731a 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -79,7 +79,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { && mc.world.getChunkProvider().isChunkGeneratedAt(event.getX(), event.getZ()); if (isPostPopulate || isPreUnload) { - WorldProvider.INSTANCE.ifWorldLoaded(world -> { + baritone.getWorldProvider().ifWorldLoaded(world -> { Chunk chunk = mc.world.getChunk(event.getX(), event.getZ()); world.getCachedWorld().queueForPacking(chunk); }); @@ -96,7 +96,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onWorldEvent(WorldEvent event) { - WorldProvider cache = WorldProvider.INSTANCE; + WorldProvider cache = baritone.getWorldProvider(); BlockStateInterface.clearCachedChunk(); diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 41c11ea5..9d69959d 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -65,7 +65,7 @@ public final class AStarPathFinder extends AbstractNodeCostSearch implements Hel } MutableMoveResult res = new MutableMoveResult(); HashSet favored = favoredPositions.orElse(null); - BetterWorldBorder worldBorder = new BetterWorldBorder(world().getWorldBorder()); + BetterWorldBorder worldBorder = new BetterWorldBorder(calcContext.world().getWorldBorder()); BlockStateInterface.clearCachedChunk(); long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); @@ -100,7 +100,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(newX, newZ)) { + if ((newX >> 4 != currentNode.x >> 4 || newZ >> 4 != currentNode.z >> 4) && !BlockStateInterface.isLoaded(calcContext, 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++; diff --git a/src/main/java/baritone/pathing/calc/Path.java b/src/main/java/baritone/pathing/calc/Path.java index 58e1e661..0b5b2cc7 100644 --- a/src/main/java/baritone/pathing/calc/Path.java +++ b/src/main/java/baritone/pathing/calc/Path.java @@ -148,7 +148,7 @@ class Path extends PathBase { } verified = true; boolean failed = assembleMovements(); - movements.forEach(Movement::checkLoadedChunk); + movements.forEach(m -> m.checkLoadedChunk(context)); if (failed) { // at least one movement became impossible during calculation CutoffPath res = new CutoffPath(this, movements().size()); diff --git a/src/main/java/baritone/pathing/movement/CalculationContext.java b/src/main/java/baritone/pathing/movement/CalculationContext.java index 10aa03c0..5f367f00 100644 --- a/src/main/java/baritone/pathing/movement/CalculationContext.java +++ b/src/main/java/baritone/pathing/movement/CalculationContext.java @@ -19,14 +19,18 @@ package baritone.pathing.movement; import baritone.Baritone; import baritone.api.pathing.movement.ActionCosts; +import baritone.utils.BlockStateInterface; import baritone.utils.Helper; import baritone.utils.ToolSet; import baritone.utils.pathing.BetterWorldBorder; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; /** @@ -75,6 +79,18 @@ public class CalculationContext { this.worldBorder = new BetterWorldBorder(world.getWorldBorder()); } + public IBlockState get(int x, int y, int z) { + return BlockStateInterface.get(world, x, y, z); + } + + public IBlockState get(BlockPos pos) { + return get(pos.getX(), pos.getY(), pos.getZ()); + } + + public Block getBlock(int x, int y, int z) { + return get(x, y, z).getBlock(); + } + public boolean canPlaceThrowawayAt(int x, int y, int z) { if (!hasThrowaway()) { // only true if allowPlace is true, see constructor return false; diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index f5c569c0..f11e1955 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -21,7 +21,9 @@ import baritone.Baritone; import baritone.api.pathing.movement.IMovement; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.*; -import baritone.utils.*; +import baritone.utils.BlockStateInterface; +import baritone.utils.Helper; +import baritone.utils.InputOverrideHandler; import net.minecraft.block.BlockLiquid; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -226,8 +228,8 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { return getDest().subtract(getSrc()); } - public void checkLoadedChunk() { - calculatedWhileLoaded = !(world().getChunk(getDest()) instanceof EmptyChunk); + public void checkLoadedChunk(CalculationContext context) { + calculatedWhileLoaded = !(context.world().getChunk(getDest()) instanceof EmptyChunk); } @Override diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index b20cbf5f..a7e9c378 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -21,7 +21,10 @@ import baritone.Baritone; import baritone.api.pathing.movement.ActionCosts; import baritone.api.utils.*; import baritone.pathing.movement.MovementState.MovementTarget; -import baritone.utils.*; +import baritone.utils.BlockStateInterface; +import baritone.utils.Helper; +import baritone.utils.InputOverrideHandler; +import baritone.utils.ToolSet; import net.minecraft.block.*; import net.minecraft.block.properties.PropertyBool; import net.minecraft.block.state.IBlockState; @@ -41,16 +44,16 @@ import net.minecraft.world.chunk.EmptyChunk; */ public interface MovementHelper extends ActionCosts, Helper { - static boolean avoidBreaking(int x, int y, int z, IBlockState state) { + static boolean avoidBreaking(CalculationContext context, int x, int y, int z, IBlockState state) { Block b = state.getBlock(); return b == Blocks.ICE // ice becomes water, and water can mess up the path || b instanceof BlockSilverfish // obvious reasons - // call BlockStateInterface.get directly with x,y,z. no need to make 5 new BlockPos for no reason - || BlockStateInterface.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side - || BlockStateInterface.get(x + 1, y, z).getBlock() instanceof BlockLiquid - || BlockStateInterface.get(x - 1, y, z).getBlock() instanceof BlockLiquid - || BlockStateInterface.get(x, y, z + 1).getBlock() instanceof BlockLiquid - || BlockStateInterface.get(x, y, z - 1).getBlock() instanceof BlockLiquid; + // call context.get directly with x,y,z. no need to make 5 new BlockPos for no reason + || context.get(x, y + 1, z).getBlock() instanceof BlockLiquid//don't break anything touching liquid on any side + || context.get(x + 1, y, z).getBlock() instanceof BlockLiquid + || context.get(x - 1, y, z).getBlock() instanceof BlockLiquid + || context.get(x, y, z + 1).getBlock() instanceof BlockLiquid + || context.get(x, y, z - 1).getBlock() instanceof BlockLiquid; } /** @@ -60,14 +63,14 @@ public interface MovementHelper extends ActionCosts, Helper { * @return */ static boolean canWalkThrough(BetterBlockPos pos) { - return canWalkThrough(pos.x, pos.y, pos.z, BlockStateInterface.get(pos)); + return canWalkThrough(new CalculationContext(), pos.x, pos.y, pos.z, BlockStateInterface.get(pos)); } - static boolean canWalkThrough(int x, int y, int z) { - return canWalkThrough(x, y, z, BlockStateInterface.get(x, y, z)); + static boolean canWalkThrough(CalculationContext context, int x, int y, int z) { + return canWalkThrough(context, x, y, z, context.get(x, y, z)); } - static boolean canWalkThrough(int x, int y, int z, IBlockState state) { + static boolean canWalkThrough(CalculationContext context, int x, int y, int z, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR) { // early return for most common case return true; @@ -108,7 +111,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (Baritone.settings().assumeWalkOnWater.get()) { return false; } - IBlockState up = BlockStateInterface.get(x, y + 1, z); + IBlockState up = context.get(x, y + 1, z); if (up.getBlock() instanceof BlockLiquid || up.getBlock() instanceof BlockLilyPad) { return false; } @@ -126,8 +129,8 @@ public interface MovementHelper extends ActionCosts, Helper { * * @return */ - static boolean fullyPassable(int x, int y, int z) { - return fullyPassable(BlockStateInterface.get(x, y, z)); + static boolean fullyPassable(CalculationContext context, int x, int y, int z) { + return fullyPassable(context.get(x, y, z)); } static boolean fullyPassable(IBlockState state) { @@ -242,7 +245,7 @@ public interface MovementHelper extends ActionCosts, Helper { * * @return */ - static boolean canWalkOn(int x, int y, int z, IBlockState state) { + static boolean canWalkOn(CalculationContext context, int x, int y, int z, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.AIR || block == Blocks.MAGMA) { // early return for most common case (air) @@ -264,7 +267,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (isWater(block)) { // since this is called literally millions of times per second, the benefit of not allocating millions of useless "pos.up()" // BlockPos s that we'd just garbage collect immediately is actually noticeable. I don't even think its a decrease in readability - Block up = BlockStateInterface.get(x, y + 1, z).getBlock(); + Block up = context.get(x, y + 1, z).getBlock(); if (up == Blocks.WATERLILY) { return true; } @@ -292,19 +295,19 @@ public interface MovementHelper extends ActionCosts, Helper { } static boolean canWalkOn(BetterBlockPos pos, IBlockState state) { - return canWalkOn(pos.x, pos.y, pos.z, state); + return canWalkOn(new CalculationContext(), pos.x, pos.y, pos.z, state); } static boolean canWalkOn(BetterBlockPos pos) { - return canWalkOn(pos.x, pos.y, pos.z, BlockStateInterface.get(pos)); + return canWalkOn(new CalculationContext(), pos.x, pos.y, pos.z, BlockStateInterface.get(pos)); } - static boolean canWalkOn(int x, int y, int z) { - return canWalkOn(x, y, z, BlockStateInterface.get(x, y, z)); + static boolean canWalkOn(CalculationContext context, int x, int y, int z) { + return canWalkOn(context, x, y, z, context.get(x, y, z)); } - static boolean canPlaceAgainst(int x, int y, int z) { - return canPlaceAgainst(BlockStateInterface.get(x, y, z)); + static boolean canPlaceAgainst(CalculationContext context, int x, int y, int z) { + return canPlaceAgainst(context.get(x, y, z)); } static boolean canPlaceAgainst(BlockPos pos) { @@ -317,16 +320,16 @@ public interface MovementHelper extends ActionCosts, Helper { } static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, boolean includeFalling) { - return getMiningDurationTicks(context, x, y, z, BlockStateInterface.get(x, y, z), includeFalling); + return getMiningDurationTicks(context, x, y, z, context.get(x, y, z), includeFalling); } static double getMiningDurationTicks(CalculationContext context, int x, int y, int z, IBlockState state, boolean includeFalling) { Block block = state.getBlock(); - if (!canWalkThrough(x, y, z, state)) { + if (!canWalkThrough(context, x, y, z, state)) { if (!context.canBreakAt(x, y, z)) { return COST_INF; } - if (avoidBreaking(x, y, z, state)) { + if (avoidBreaking(context, x, y, z, state)) { return COST_INF; } if (block instanceof BlockLiquid) { @@ -341,7 +344,7 @@ public interface MovementHelper extends ActionCosts, Helper { double result = m / strVsBlock; result += context.breakBlockAdditionalCost(); if (includeFalling) { - IBlockState above = BlockStateInterface.get(x, y + 1, z); + IBlockState above = context.get(x, y + 1, z); if (above.getBlock() instanceof BlockFalling) { result += getMiningDurationTicks(context, x, y + 1, z, above, true); } @@ -357,10 +360,6 @@ public interface MovementHelper extends ActionCosts, Helper { && state.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.BOTTOM; } - static boolean isBottomSlab(BlockPos pos) { - return isBottomSlab(BlockStateInterface.get(pos)); - } - /** * AutoTool */ diff --git a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java index cd0744e4..1d161554 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementAscend.java @@ -58,20 +58,20 @@ public class MovementAscend extends Movement { } public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { - IBlockState srcDown = BlockStateInterface.get(x, y - 1, z); + IBlockState srcDown = context.get(x, y - 1, z); if (srcDown.getBlock() == Blocks.LADDER || srcDown.getBlock() == Blocks.VINE) { return COST_INF; } // we can jump from soul sand, but not from a bottom slab boolean jumpingFromBottomSlab = MovementHelper.isBottomSlab(srcDown); - IBlockState toPlace = BlockStateInterface.get(destX, y, destZ); + IBlockState toPlace = context.get(destX, y, destZ); boolean jumpingToBottomSlab = MovementHelper.isBottomSlab(toPlace); if (jumpingFromBottomSlab && !jumpingToBottomSlab) { return COST_INF;// the only thing we can ascend onto from a bottom slab is another bottom slab } boolean hasToPlace = false; - if (!MovementHelper.canWalkOn(destX, y, destZ, toPlace)) { + if (!MovementHelper.canWalkOn(context, destX, y, destZ, toPlace)) { if (!context.canPlaceThrowawayAt(destX, y, destZ)) { return COST_INF; } @@ -87,7 +87,7 @@ public class MovementAscend extends Movement { if (againstX == x && againstZ == z) { continue; } - if (MovementHelper.canPlaceAgainst(againstX, y, againstZ)) { + if (MovementHelper.canPlaceAgainst(context, againstX, y, againstZ)) { hasToPlace = true; break; } @@ -97,7 +97,7 @@ public class MovementAscend extends Movement { } } IBlockState srcUp2 = null; - if (BlockStateInterface.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(x, y + 1, z) || !((srcUp2 = BlockStateInterface.get(x, y + 2, z)).getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us + if (context.get(x, y + 3, z).getBlock() instanceof BlockFalling && (MovementHelper.canWalkThrough(context, x, y + 1, z) || !((srcUp2 = context.get(x, y + 2, z)).getBlock() instanceof BlockFalling))) {//it would fall on us and possibly suffocate us // HOWEVER, we assume that we're standing in the start position // that means that src and src.up(1) are both air // maybe they aren't now, but they will be by the time this starts @@ -138,7 +138,7 @@ public class MovementAscend extends Movement { totalCost += context.placeBlockCost(); } if (srcUp2 == null) { - srcUp2 = BlockStateInterface.get(x, y + 2, z); + srcUp2 = context.get(x, y + 2, z); } totalCost += MovementHelper.getMiningDurationTicks(context, x, y + 2, z, srcUp2, false); // TODO MAKE ABSOLUTELY SURE we don't need includeFalling here, from the falling check above if (totalCost >= COST_INF) { @@ -204,7 +204,7 @@ public class MovementAscend extends Movement { return state.setStatus(MovementStatus.UNREACHABLE); } MovementHelper.moveTowards(state, dest); - if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(src.down())) { + if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(src.down()))) { return state; // don't jump while walking from a non double slab into a bottom slab } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java index a8874989..84f0d781 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDescend.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDescend.java @@ -24,7 +24,6 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; -import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; import baritone.utils.pathing.MutableMoveResult; import net.minecraft.block.Block; @@ -58,13 +57,13 @@ public class MovementDescend extends Movement { } public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) { - Block fromDown = BlockStateInterface.get(x, y - 1, z).getBlock(); + Block fromDown = context.get(x, y - 1, z).getBlock(); if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { return; } double totalCost = 0; - IBlockState destDown = BlockStateInterface.get(destX, y - 1, destZ); + IBlockState destDown = context.get(destX, y - 1, destZ); totalCost += MovementHelper.getMiningDurationTicks(context, destX, y - 1, destZ, destDown, false); if (totalCost >= COST_INF) { return; @@ -88,8 +87,8 @@ public class MovementDescend extends Movement { //A is plausibly breakable by either descend or fall //C, D, etc determine the length of the fall - IBlockState below = BlockStateInterface.get(destX, y - 2, destZ); - if (!MovementHelper.canWalkOn(destX, y - 2, destZ, below)) { + IBlockState below = context.get(destX, y - 2, destZ); + if (!MovementHelper.canWalkOn(context, destX, y - 2, destZ, below)) { dynamicFallCost(context, x, y, z, destX, destZ, totalCost, below, res); return; } @@ -112,13 +111,13 @@ public class MovementDescend extends Movement { } public static void dynamicFallCost(CalculationContext context, int x, int y, int z, int destX, int destZ, double frontBreak, IBlockState below, MutableMoveResult res) { - if (frontBreak != 0 && BlockStateInterface.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) { + if (frontBreak != 0 && context.get(destX, y + 2, destZ).getBlock() instanceof BlockFalling) { // if frontBreak is 0 we can actually get through this without updating the falling block and making it actually fall // but if frontBreak is nonzero, we're breaking blocks in front, so don't let anything fall through this column, // and potentially replace the water we're going to fall into return; } - if (!MovementHelper.canWalkThrough(destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { + if (!MovementHelper.canWalkThrough(context, destX, y - 2, destZ, below) && below.getBlock() != Blocks.WATER) { return; } for (int fallHeight = 3; true; fallHeight++) { @@ -128,9 +127,9 @@ public class MovementDescend extends Movement { // this check prevents it from getting the block at y=-1 and crashing return; } - IBlockState ontoBlock = BlockStateInterface.get(destX, newY, destZ); + IBlockState ontoBlock = context.get(destX, newY, destZ); double tentativeCost = WALK_OFF_BLOCK_COST + FALL_N_BLOCKS_COST[fallHeight] + frontBreak; - if (ontoBlock.getBlock() == Blocks.WATER && !MovementHelper.isFlowing(ontoBlock) && BlockStateInterface.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { // TODO flowing check required here? + if (ontoBlock.getBlock() == Blocks.WATER && !MovementHelper.isFlowing(ontoBlock) && context.getBlock(destX, newY + 1, destZ) != Blocks.WATERLILY) { // TODO flowing check required here? // lilypads are canWalkThrough, but we can't end a fall that should be broken by water if it's covered by a lilypad // however, don't return impossible in the lilypad scenario, because we could still jump right on it (water that's below a lilypad is canWalkOn so it works) if (Baritone.settings().assumeWalkOnWater.get()) { @@ -146,10 +145,10 @@ public class MovementDescend extends Movement { if (ontoBlock.getBlock() == Blocks.FLOWING_WATER) { return; } - if (MovementHelper.canWalkThrough(destX, newY, destZ, ontoBlock)) { + if (MovementHelper.canWalkThrough(context, destX, newY, destZ, ontoBlock)) { continue; } - if (!MovementHelper.canWalkOn(destX, newY, destZ, ontoBlock)) { + if (!MovementHelper.canWalkOn(context, destX, newY, destZ, ontoBlock)) { return; } if (MovementHelper.isBottomSlab(ontoBlock)) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java index 9848d671..8e5dd910 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDiagonal.java @@ -23,7 +23,6 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; -import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -57,16 +56,16 @@ public class MovementDiagonal extends Movement { } public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { - Block fromDown = BlockStateInterface.get(x, y - 1, z).getBlock(); + Block fromDown = context.get(x, y - 1, z).getBlock(); if (fromDown == Blocks.LADDER || fromDown == Blocks.VINE) { return COST_INF; } - IBlockState destInto = BlockStateInterface.get(destX, y, destZ); - if (!MovementHelper.canWalkThrough(destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(destX, y + 1, destZ)) { + IBlockState destInto = context.get(destX, y, destZ); + if (!MovementHelper.canWalkThrough(context, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context, destX, y + 1, destZ)) { return COST_INF; } - IBlockState destWalkOn = BlockStateInterface.get(destX, y - 1, destZ); - if (!MovementHelper.canWalkOn(destX, y - 1, destZ, destWalkOn)) { + IBlockState destWalkOn = context.get(destX, y - 1, destZ); + if (!MovementHelper.canWalkOn(context, destX, y - 1, destZ, destWalkOn)) { return COST_INF; } double multiplier = WALK_ONE_BLOCK_COST; @@ -77,16 +76,16 @@ public class MovementDiagonal extends Movement { if (fromDown == Blocks.SOUL_SAND) { multiplier += (WALK_ONE_OVER_SOUL_SAND_COST - WALK_ONE_BLOCK_COST) / 2; } - Block cuttingOver1 = BlockStateInterface.get(x, y - 1, destZ).getBlock(); + Block cuttingOver1 = context.get(x, y - 1, destZ).getBlock(); if (cuttingOver1 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver1)) { return COST_INF; } - Block cuttingOver2 = BlockStateInterface.get(destX, y - 1, z).getBlock(); + Block cuttingOver2 = context.get(destX, y - 1, z).getBlock(); if (cuttingOver2 == Blocks.MAGMA || MovementHelper.isLava(cuttingOver2)) { return COST_INF; } - IBlockState pb0 = BlockStateInterface.get(x, y, destZ); - IBlockState pb2 = BlockStateInterface.get(destX, y, z); + IBlockState pb0 = context.get(x, y, destZ); + IBlockState pb2 = context.get(destX, y, z); double optionA = MovementHelper.getMiningDurationTicks(context, x, y, destZ, pb0, false); double optionB = MovementHelper.getMiningDurationTicks(context, destX, y, z, pb2, false); if (optionA != 0 && optionB != 0) { @@ -94,13 +93,13 @@ public class MovementDiagonal extends Movement { // so no need to check pb1 as well, might as well return early here return COST_INF; } - IBlockState pb1 = BlockStateInterface.get(x, y + 1, destZ); + IBlockState pb1 = context.get(x, y + 1, destZ); optionA += MovementHelper.getMiningDurationTicks(context, x, y + 1, destZ, pb1, true); if (optionA != 0 && optionB != 0) { // same deal, if pb1 makes optionA nonzero and option B already was nonzero, pb3 can't affect the result return COST_INF; } - IBlockState pb3 = BlockStateInterface.get(destX, y + 1, z); + IBlockState pb3 = context.get(destX, y + 1, z); if (optionA == 0 && ((MovementHelper.avoidWalkingInto(pb2.getBlock()) && pb2.getBlock() != Blocks.WATER) || (MovementHelper.avoidWalkingInto(pb3.getBlock()) && pb3.getBlock() != Blocks.WATER))) { // at this point we're done calculating optionA, so we can check if it's actually possible to edge around in that direction return COST_INF; @@ -115,7 +114,7 @@ public class MovementDiagonal extends Movement { return COST_INF; } boolean water = false; - if (MovementHelper.isWater(BlockStateInterface.getBlock(x, y, z)) || MovementHelper.isWater(destInto.getBlock())) { + if (MovementHelper.isWater(context.getBlock(x, y, z)) || MovementHelper.isWater(destInto.getBlock())) { // Ignore previous multiplier // Whatever we were walking on (possibly soul sand) doesn't matter as we're actually floating on water // Not even touching the blocks below diff --git a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java index 0ac4f2b0..07c101e6 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementDownward.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementDownward.java @@ -23,7 +23,6 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; -import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -48,10 +47,10 @@ public class MovementDownward extends Movement { } public static double cost(CalculationContext context, int x, int y, int z) { - if (!MovementHelper.canWalkOn(x, y - 2, z)) { + if (!MovementHelper.canWalkOn(context, x, y - 2, z)) { return COST_INF; } - IBlockState d = BlockStateInterface.get(x, y - 1, z); + IBlockState d = context.get(x, y - 1, z); Block td = d.getBlock(); boolean ladder = td == Blocks.LADDER || td == Blocks.VINE; if (ladder) { diff --git a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java index 73aace38..2b255d62 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementParkour.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementParkour.java @@ -27,7 +27,9 @@ import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; -import baritone.utils.*; +import baritone.utils.BlockStateInterface; +import baritone.utils.Helper; +import baritone.utils.InputOverrideHandler; import baritone.utils.pathing.MutableMoveResult; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -65,30 +67,30 @@ public class MovementParkour extends Movement { if (!Baritone.settings().allowParkour.get()) { return; } - IBlockState standingOn = BlockStateInterface.get(x, y - 1, z); + IBlockState standingOn = context.get(x, y - 1, z); if (standingOn.getBlock() == Blocks.VINE || standingOn.getBlock() == Blocks.LADDER || MovementHelper.isBottomSlab(standingOn)) { return; } int xDiff = dir.getXOffset(); int zDiff = dir.getZOffset(); - IBlockState adj = BlockStateInterface.get(x + xDiff, y - 1, z + zDiff); + IBlockState adj = context.get(x + xDiff, y - 1, z + zDiff); if (MovementHelper.avoidWalkingInto(adj.getBlock()) && adj.getBlock() != Blocks.WATER && adj.getBlock() != Blocks.FLOWING_WATER) { // magma sucks return; } - if (MovementHelper.canWalkOn(x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) + if (MovementHelper.canWalkOn(context,x + xDiff, y - 1, z + zDiff, adj)) { // don't parkour if we could just traverse (for now) return; } - if (!MovementHelper.fullyPassable(x + xDiff, y, z + zDiff)) { + if (!MovementHelper.fullyPassable(context,x + xDiff, y, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(x + xDiff, y + 1, z + zDiff)) { + if (!MovementHelper.fullyPassable(context,x + xDiff, y + 1, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(x + xDiff, y + 2, z + zDiff)) { + if (!MovementHelper.fullyPassable(context,x + xDiff, y + 2, z + zDiff)) { return; } - if (!MovementHelper.fullyPassable(x, y + 2, z)) { + if (!MovementHelper.fullyPassable(context,x, y + 2, z)) { return; } int maxJump; @@ -104,11 +106,11 @@ public class MovementParkour extends Movement { for (int i = 2; i <= maxJump; i++) { // TODO perhaps dest.up(3) doesn't need to be fullyPassable, just canWalkThrough, possibly? for (int y2 = 0; y2 < 4; y2++) { - if (!MovementHelper.fullyPassable(x + xDiff * i, y + y2, z + zDiff * i)) { + if (!MovementHelper.fullyPassable(context,x + xDiff * i, y + y2, z + zDiff * i)) { return; } } - if (MovementHelper.canWalkOn(x + xDiff * i, y - 1, z + zDiff * i)) { + if (MovementHelper.canWalkOn(context,x + xDiff * i, y - 1, z + zDiff * i)) { res.x = x + xDiff * i; res.y = y; res.z = z + zDiff * i; @@ -128,7 +130,7 @@ public class MovementParkour extends Movement { } int destX = x + 4 * xDiff; int destZ = z + 4 * zDiff; - IBlockState toPlace = BlockStateInterface.get(destX, y - 1, destZ); + IBlockState toPlace = context.get(destX, y - 1, destZ); if (!context.canPlaceThrowawayAt(destX, y - 1, destZ)) { return; } @@ -141,7 +143,7 @@ public class MovementParkour extends Movement { if (againstX == x + xDiff * 3 && againstZ == z + zDiff * 3) { // we can't turn around that fast continue; } - if (MovementHelper.canPlaceAgainst(againstX, y - 1, againstZ)) { + if (MovementHelper.canPlaceAgainst(context,againstX, y - 1, againstZ)) { res.x = destX; res.y = y; res.z = destZ; @@ -259,4 +261,4 @@ public class MovementParkour extends Movement { } return state; } -} \ No newline at end of file +} diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 76006da5..846e4018 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -20,6 +20,7 @@ package baritone.pathing.movement.movements; import baritone.api.pathing.movement.MovementStatus; import baritone.api.utils.BetterBlockPos; import baritone.api.utils.Rotation; +import baritone.api.utils.RotationUtils; import baritone.api.utils.VecUtils; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -27,7 +28,6 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; -import baritone.api.utils.RotationUtils; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; @@ -46,9 +46,9 @@ public class MovementPillar extends Movement { } public static double cost(CalculationContext context, int x, int y, int z) { - Block fromDown = BlockStateInterface.get(x, y, z).getBlock(); + Block fromDown = context.get(x, y, z).getBlock(); boolean ladder = fromDown instanceof BlockLadder || fromDown instanceof BlockVine; - IBlockState fromDownDown = BlockStateInterface.get(x, y - 1, z); + IBlockState fromDownDown = context.get(x, y - 1, z); if (!ladder) { if (fromDownDown.getBlock() instanceof BlockLadder || fromDownDown.getBlock() instanceof BlockVine) { return COST_INF; @@ -57,17 +57,17 @@ public class MovementPillar extends Movement { return COST_INF; // can't pillar up from a bottom slab onto a non ladder } } - if (fromDown instanceof BlockVine && !hasAgainst(x, y, z)) { + if (fromDown instanceof BlockVine && !hasAgainst(context, x, y, z)) { return COST_INF; } - IBlockState toBreak = BlockStateInterface.get(x, y + 2, z); + IBlockState toBreak = context.get(x, y + 2, z); Block toBreakBlock = toBreak.getBlock(); if (toBreakBlock instanceof BlockFenceGate) { return COST_INF; } Block srcUp = null; if (MovementHelper.isWater(toBreakBlock) && MovementHelper.isWater(fromDown)) { - srcUp = BlockStateInterface.get(x, y + 1, z).getBlock(); + srcUp = context.get(x, y + 1, z).getBlock(); if (MovementHelper.isWater(srcUp)) { return LADDER_UP_ONE_COST; } @@ -83,11 +83,11 @@ public class MovementPillar extends Movement { if (toBreakBlock instanceof BlockLadder || toBreakBlock instanceof BlockVine) { hardness = 0; // we won't actually need to break the ladder / vine because we're going to use it } else { - IBlockState check = BlockStateInterface.get(x, y + 3, z); + IBlockState check = context.get(x, y + 3, z); if (check.getBlock() instanceof BlockFalling) { // see MovementAscend's identical check for breaking a falling block above our head if (srcUp == null) { - srcUp = BlockStateInterface.get(x, y + 1, z).getBlock(); + srcUp = context.get(x, y + 1, z).getBlock(); } if (!(toBreakBlock instanceof BlockFalling) || !(srcUp instanceof BlockFalling)) { return COST_INF; @@ -112,24 +112,24 @@ public class MovementPillar extends Movement { } } - public static boolean hasAgainst(int x, int y, int z) { - return BlockStateInterface.get(x + 1, y, z).isBlockNormalCube() || - BlockStateInterface.get(x - 1, y, z).isBlockNormalCube() || - BlockStateInterface.get(x, y, z + 1).isBlockNormalCube() || - BlockStateInterface.get(x, y, z - 1).isBlockNormalCube(); + public static boolean hasAgainst(CalculationContext context, int x, int y, int z) { + return context.get(x + 1, y, z).isBlockNormalCube() || + context.get(x - 1, y, z).isBlockNormalCube() || + context.get(x, y, z + 1).isBlockNormalCube() || + context.get(x, y, z - 1).isBlockNormalCube(); } - public static BlockPos getAgainst(BlockPos vine) { - if (BlockStateInterface.get(vine.north()).isBlockNormalCube()) { + public static BlockPos getAgainst(CalculationContext context, BetterBlockPos vine) { + if (context.get(vine.north()).isBlockNormalCube()) { return vine.north(); } - if (BlockStateInterface.get(vine.south()).isBlockNormalCube()) { + if (context.get(vine.south()).isBlockNormalCube()) { return vine.south(); } - if (BlockStateInterface.get(vine.east()).isBlockNormalCube()) { + if (context.get(vine.east()).isBlockNormalCube()) { return vine.east(); } - if (BlockStateInterface.get(vine.west()).isBlockNormalCube()) { + if (context.get(vine.west()).isBlockNormalCube()) { return vine.west(); } return null; @@ -166,7 +166,7 @@ public class MovementPillar extends Movement { boolean blockIsThere = MovementHelper.canWalkOn(src) || ladder; if (ladder) { - BlockPos against = vine ? getAgainst(src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite()); + BlockPos against = vine ? getAgainst(new CalculationContext(), src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite()); if (against == null) { logDebug("Unable to climb vines"); return state.setStatus(MovementStatus.UNREACHABLE); @@ -175,7 +175,7 @@ public class MovementPillar extends Movement { if (playerFeet().equals(against.up()) || playerFeet().equals(dest)) { return state.setStatus(MovementStatus.SUCCESS); } - if (MovementHelper.isBottomSlab(src.down())) { + if (MovementHelper.isBottomSlab(BlockStateInterface.get(src.down()))) { state.setInput(InputOverrideHandler.Input.JUMP, true); } /* @@ -244,4 +244,4 @@ public class MovementPillar extends Movement { } return super.prepared(state); } -} \ No newline at end of file +} diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index 0cf64a72..a4f32855 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -26,8 +26,6 @@ import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementState; import baritone.utils.BlockStateInterface; import baritone.utils.InputOverrideHandler; -import baritone.api.utils.RayTraceUtils; -import baritone.api.utils.RotationUtils; import net.minecraft.block.*; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; @@ -61,11 +59,11 @@ public class MovementTraverse extends Movement { } public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) { - IBlockState pb0 = BlockStateInterface.get(destX, y + 1, destZ); - IBlockState pb1 = BlockStateInterface.get(destX, y, destZ); - IBlockState destOn = BlockStateInterface.get(destX, y - 1, destZ); - Block srcDown = BlockStateInterface.getBlock(x, y - 1, z); - if (MovementHelper.canWalkOn(destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge + IBlockState pb0 = context.get(destX, y + 1, destZ); + IBlockState pb1 = context.get(destX, y, destZ); + IBlockState destOn = context.get(destX, y - 1, destZ); + Block srcDown = context.getBlock(x, y - 1, z); + if (MovementHelper.canWalkOn(context, destX, y - 1, destZ, destOn)) {//this is a walk, not a bridge double WC = WALK_ONE_BLOCK_COST; boolean water = false; if (MovementHelper.isWater(pb0.getBlock()) || MovementHelper.isWater(pb1.getBlock())) { @@ -123,7 +121,7 @@ public class MovementTraverse extends Movement { if (againstX == x && againstZ == z) { continue; } - if (MovementHelper.canPlaceAgainst(againstX, y - 1, againstZ)) { + if (MovementHelper.canPlaceAgainst(context, againstX, y - 1, againstZ)) { return WC + context.placeBlockCost() + hardness1 + hardness2; } } diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index 241fafa1..0fb2abc0 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -97,6 +97,6 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } private void rescan(List known) { - knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64, world(), known); + knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64, baritone.getWorldProvider(), world(), known); } } \ No newline at end of file diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index 27da4496..882456dd 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -22,15 +22,16 @@ import baritone.api.pathing.goals.*; import baritone.api.process.IMineProcess; import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; +import baritone.api.utils.RotationUtils; import baritone.cache.CachedChunk; import baritone.cache.ChunkPacker; import baritone.cache.WorldProvider; import baritone.cache.WorldScanner; +import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import baritone.utils.Helper; -import baritone.api.utils.RotationUtils; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; @@ -158,7 +159,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro if (Baritone.settings().legitMine.get()) { return; } - List locs = searchWorld(mining, ORE_LOCATIONS_COUNT, world(), already); + List locs = searchWorld(mining, ORE_LOCATIONS_COUNT, baritone.getWorldProvider(), world(), already); locs.addAll(droppedItemsScan(mining, world())); if (locs.isEmpty()) { logDebug("No locations for " + mining + " known, cancelling"); @@ -216,13 +217,13 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro /*public static List searchWorld(List mining, int max, World world) { }*/ - public static List searchWorld(List mining, int max, World world, List alreadyKnown) { + public static List searchWorld(List mining, int max, WorldProvider provider, World world, List alreadyKnown) { List locs = new ArrayList<>(); List uninteresting = new ArrayList<>(); //long b = System.currentTimeMillis(); for (Block m : mining) { if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(m)) { - locs.addAll(WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, 1)); + locs.addAll(provider.getCurrentWorld().getCachedWorld().getLocationsOf(ChunkPacker.blockToString(m), 1, 1)); } else { uninteresting.add(m); } @@ -279,7 +280,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro } public static boolean plausibleToBreak(BlockPos pos) { - if (MovementHelper.avoidBreaking(pos.getX(), pos.getY(), pos.getZ(), BlockStateInterface.get(pos))) { + if (MovementHelper.avoidBreaking(new CalculationContext(), pos.getX(), pos.getY(), pos.getZ(), BlockStateInterface.get(pos))) { return false; } // bedrock above and below makes it implausible, otherwise we're good diff --git a/src/main/java/baritone/utils/BlockStateInterface.java b/src/main/java/baritone/utils/BlockStateInterface.java index 7133fa12..d944484f 100644 --- a/src/main/java/baritone/utils/BlockStateInterface.java +++ b/src/main/java/baritone/utils/BlockStateInterface.java @@ -20,11 +20,12 @@ package baritone.utils; import baritone.Baritone; import baritone.cache.CachedRegion; import baritone.cache.WorldData; -import baritone.cache.WorldProvider; +import baritone.pathing.movement.CalculationContext; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; /** @@ -43,7 +44,12 @@ public class BlockStateInterface implements Helper { return get(pos.getX(), pos.getY(), pos.getZ()); } + 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) { // Invalid vertical position if (y < 0 || y >= 256) { @@ -61,7 +67,7 @@ public class BlockStateInterface implements Helper { if (cached != null && cached.x == x >> 4 && cached.z == z >> 4) { return cached.getBlockState(x, y, z); } - Chunk chunk = mc.world.getChunk(x >> 4, z >> 4); + Chunk chunk = world.getChunk(x >> 4, z >> 4); if (chunk.isLoaded()) { prev = chunk; return chunk.getBlockState(x, y, z); @@ -71,11 +77,11 @@ 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 world = WorldProvider.INSTANCE.getCurrentWorld(); - if (world == null) { + WorldData worldData = Baritone.INSTANCE.getWorldProvider().getCurrentWorld(); + if (worldData == null) { return AIR; } - CachedRegion region = world.cache.getRegion(x >> 9, z >> 9); + CachedRegion region = worldData.cache.getRegion(x >> 9, z >> 9); if (region == null) { return AIR; } @@ -89,12 +95,12 @@ public class BlockStateInterface implements Helper { return type; } - public static boolean isLoaded(int x, int z) { + public static boolean isLoaded(CalculationContext context, int x, int z) { Chunk prevChunk = prev; if (prevChunk != null && prevChunk.x == x >> 4 && prevChunk.z == z >> 4) { return true; } - prevChunk = mc.world.getChunk(x >> 4, z >> 4); + prevChunk = context.world().getChunk(x >> 4, z >> 4); if (prevChunk.isLoaded()) { prev = prevChunk; return true; @@ -103,7 +109,7 @@ 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 = WorldProvider.INSTANCE.getCurrentWorld(); + WorldData world = Baritone.INSTANCE.getWorldProvider().getCurrentWorld(); if (world == null) { return false; } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index 2fbf05f7..2f6bef6c 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -29,7 +29,6 @@ import baritone.behavior.Behavior; import baritone.behavior.PathingBehavior; import baritone.cache.ChunkPacker; import baritone.cache.Waypoint; -import baritone.cache.WorldProvider; import baritone.pathing.calc.AbstractNodeCostSearch; import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.Movement; @@ -215,7 +214,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { Chunk chunk = cli.getLoadedChunk(x, z); if (chunk != null) { count++; - WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().queueForPacking(chunk); + baritone.getWorldProvider().getCurrentWorld().getCachedWorld().queueForPacking(chunk); } } } @@ -291,18 +290,18 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("reloadall")) { - WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().reloadAllFromDisk(); + baritone.getWorldProvider().getCurrentWorld().getCachedWorld().reloadAllFromDisk(); logDirect("ok"); return true; } if (msg.equals("saveall")) { - WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().save(); + baritone.getWorldProvider().getCurrentWorld().getCachedWorld().save(); logDirect("ok"); return true; } if (msg.startsWith("find")) { String blockType = msg.substring(4).trim(); - LinkedList locs = WorldProvider.INSTANCE.getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, 4); + LinkedList locs = baritone.getWorldProvider().getCurrentWorld().getCachedWorld().getLocationsOf(blockType, 1, 4); logDirect("Have " + locs.size() + " locations"); for (BlockPos pos : locs) { Block actually = BlockStateInterface.get(pos).getBlock(); @@ -354,7 +353,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); return true; } - Set waypoints = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getByTag(tag); + Set waypoints = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getByTag(tag); // might as well show them from oldest to newest List sorted = new ArrayList<>(waypoints); sorted.sort(Comparator.comparingLong(IWaypoint::getCreationTimestamp)); @@ -382,7 +381,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { } name = parts[0]; } - WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, pos)); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint(name, Waypoint.Tag.USER, pos)); logDirect("Saved user defined position " + pos + " under name '" + name + "'. Say 'goto " + name + "' to set goal, say 'list user' to list custom waypoints."); return true; } @@ -399,7 +398,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { Block block = ChunkPacker.stringToBlock(mining); //logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); if (block == null) { - waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null); + waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getAllWaypoints().stream().filter(w -> w.getName().equalsIgnoreCase(mining)).max(Comparator.comparingLong(IWaypoint::getCreationTimestamp)).orElse(null); if (waypoint == null) { logDirect("No locations for " + mining + " known, cancelling"); return true; @@ -409,7 +408,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } } else { - waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(tag); + waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(tag); if (waypoint == null) { logDirect("None saved for tag " + tag); return true; @@ -420,7 +419,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("spawn") || msg.equals("bed")) { - IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED); + IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.BED); if (waypoint == null) { BlockPos spawnPoint = player().getBedLocation(); // for some reason the default spawnpoint is underground sometimes @@ -435,12 +434,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper { return true; } if (msg.equals("sethome")) { - WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet())); + baritone.getWorldProvider().getCurrentWorld().getWaypoints().addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet())); logDirect("Saved. Say home to set goal."); return true; } if (msg.equals("home")) { - IWaypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME); + IWaypoint waypoint = baritone.getWorldProvider().getCurrentWorld().getWaypoints().getMostRecentByTag(Waypoint.Tag.HOME); if (waypoint == null) { logDirect("home not saved"); } else { diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 27aa2bc1..31b3fc10 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -66,6 +66,9 @@ public interface Helper { } default WorldClient world() { + if (!mc.isCallingFromMinecraftThread()) { + throw new IllegalStateException("h00000000"); + } return mc.world; }