diff --git a/src/api/java/baritone/api/pathing/movement/IMovement.java b/src/api/java/baritone/api/pathing/movement/IMovement.java index c9b9ea4b..dae8668d 100644 --- a/src/api/java/baritone/api/pathing/movement/IMovement.java +++ b/src/api/java/baritone/api/pathing/movement/IMovement.java @@ -45,10 +45,6 @@ public interface IMovement { */ boolean safeToCancel(); - double recalculateCost(); - - double calculateCostWithoutCaching(); - boolean calculatedWhileLoaded(); BetterBlockPos getSrc(); diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index 390ac859..34fd6b41 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -25,7 +25,6 @@ import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; import baritone.cache.ContainerMemory; import baritone.cache.Waypoint; -import baritone.pathing.movement.CalculationContext; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; import net.minecraft.block.BlockBed; @@ -196,7 +195,7 @@ public final class MemoryBehavior extends Behavior { } private BlockPos neighboringConnectedBlock(BlockPos in) { - BlockStateInterface bsi = new CalculationContext(baritone).bsi; + BlockStateInterface bsi = baritone.bsi; Block block = bsi.get0(in).getBlock(); if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) { return null; // other things that have contents, but can be placed adjacent without combining diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index bc3443a7..bda02de1 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -361,6 +361,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, } } + public CalculationContext secretInternalGetCalculationContext() { + return context; + } + /** * See issue #209 * diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index 07ee79aa..96b650e7 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -76,31 +76,28 @@ public abstract class Movement implements IMovement, MovementHelper { this(baritone, src, dest, toBreak, null); } - @Override - public double getCost() { + public double getCost() throws NullPointerException { + return cost; + } + + public double getCost(CalculationContext context) { if (cost == null) { - cost = calculateCost(new CalculationContext(baritone)); + cost = calculateCost(context); } return cost; } public abstract double calculateCost(CalculationContext context); - @Override - public double recalculateCost() { + public double recalculateCost(CalculationContext context) { cost = null; - return getCost(); + return getCost(context); } public void override(double cost) { this.cost = cost; } - @Override - public double calculateCostWithoutCaching() { - return calculateCost(new CalculationContext(baritone)); - } - /** * Handles the execution of the latest Movement * State, and offers a Status to the calling class. diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index d4897eec..4d3b5f3b 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -232,14 +232,14 @@ public class PathExecutor implements IPathExecutor, Helper { // do this only once, when the movement starts, and deliberately get the cost as cached when this path was calculated, not the cost as it is right now currentMovementOriginalCostEstimate = movement.getCost(); for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { - if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF && canCancel) { + if (((Movement) path.movements().get(pathPosition + i)).calculateCost(behavior.secretInternalGetCalculationContext()) >= ActionCosts.COST_INF && canCancel) { logDebug("Something has changed in the world and a future movement has become impossible. Cancelling."); cancel(); return true; } } } - double currentCost = movement.recalculateCost(); + double currentCost = ((Movement) movement).recalculateCost(behavior.secretInternalGetCalculationContext()); if (currentCost >= ActionCosts.COST_INF && canCancel) { logDebug("Something has changed in the world and this movement has become impossible. Cancelling."); cancel(); diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index 98e114c1..e7c2f65a 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -465,6 +465,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro } public Goal placementgoal(BlockPos pos, BuilderCalculationContext bcc) { + if (ctx.world().getBlockState(pos).getBlock() != Blocks.AIR) { + return new GoalPlace(pos); + } boolean allowSameLevel = ctx.world().getBlockState(pos.up()).getBlock() != Blocks.AIR; for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP) { if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && ctx.world().mayPlace(bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()).getBlock(), pos, false, facing, null)) { diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index ccca14ba..d3626569 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -558,7 +558,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper { while (moves.contains(null)) { moves.remove(null); } - moves.sort(Comparator.comparingDouble(Movement::getCost)); + moves.sort(Comparator.comparingDouble(move -> move.getCost(new CalculationContext(baritone)))); for (Movement move : moves) { String[] parts = move.getClass().toString().split("\\."); double cost = move.getCost();