fix a bunch of bugs with placement

This commit is contained in:
Leijurv 2019-02-20 08:08:52 -08:00
parent 963641a818
commit bf12763a10
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
7 changed files with 19 additions and 20 deletions

View File

@ -45,10 +45,6 @@ public interface IMovement {
*/
boolean safeToCancel();
double recalculateCost();
double calculateCostWithoutCaching();
boolean calculatedWhileLoaded();
BetterBlockPos getSrc();

View File

@ -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

View File

@ -361,6 +361,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
}
}
public CalculationContext secretInternalGetCalculationContext() {
return context;
}
/**
* See issue #209
*

View File

@ -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.

View File

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

View File

@ -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)) {

View File

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