forked from RepoMirrors/baritone
fix a bunch of bugs with placement
This commit is contained in:
parent
963641a818
commit
bf12763a10
|
@ -45,10 +45,6 @@ public interface IMovement {
|
||||||
*/
|
*/
|
||||||
boolean safeToCancel();
|
boolean safeToCancel();
|
||||||
|
|
||||||
double recalculateCost();
|
|
||||||
|
|
||||||
double calculateCostWithoutCaching();
|
|
||||||
|
|
||||||
boolean calculatedWhileLoaded();
|
boolean calculatedWhileLoaded();
|
||||||
|
|
||||||
BetterBlockPos getSrc();
|
BetterBlockPos getSrc();
|
||||||
|
|
|
@ -25,7 +25,6 @@ import baritone.api.event.events.TickEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.cache.ContainerMemory;
|
import baritone.cache.ContainerMemory;
|
||||||
import baritone.cache.Waypoint;
|
import baritone.cache.Waypoint;
|
||||||
import baritone.pathing.movement.CalculationContext;
|
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockBed;
|
import net.minecraft.block.BlockBed;
|
||||||
|
@ -196,7 +195,7 @@ public final class MemoryBehavior extends Behavior {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockPos neighboringConnectedBlock(BlockPos in) {
|
private BlockPos neighboringConnectedBlock(BlockPos in) {
|
||||||
BlockStateInterface bsi = new CalculationContext(baritone).bsi;
|
BlockStateInterface bsi = baritone.bsi;
|
||||||
Block block = bsi.get0(in).getBlock();
|
Block block = bsi.get0(in).getBlock();
|
||||||
if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
|
if (block != Blocks.TRAPPED_CHEST && block != Blocks.CHEST) {
|
||||||
return null; // other things that have contents, but can be placed adjacent without combining
|
return null; // other things that have contents, but can be placed adjacent without combining
|
||||||
|
|
|
@ -361,6 +361,10 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CalculationContext secretInternalGetCalculationContext() {
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See issue #209
|
* See issue #209
|
||||||
*
|
*
|
||||||
|
|
|
@ -76,31 +76,28 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||||
this(baritone, src, dest, toBreak, null);
|
this(baritone, src, dest, toBreak, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public double getCost() throws NullPointerException {
|
||||||
public double getCost() {
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCost(CalculationContext context) {
|
||||||
if (cost == null) {
|
if (cost == null) {
|
||||||
cost = calculateCost(new CalculationContext(baritone));
|
cost = calculateCost(context);
|
||||||
}
|
}
|
||||||
return cost;
|
return cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract double calculateCost(CalculationContext context);
|
public abstract double calculateCost(CalculationContext context);
|
||||||
|
|
||||||
@Override
|
public double recalculateCost(CalculationContext context) {
|
||||||
public double recalculateCost() {
|
|
||||||
cost = null;
|
cost = null;
|
||||||
return getCost();
|
return getCost(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void override(double cost) {
|
public void override(double cost) {
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double calculateCostWithoutCaching() {
|
|
||||||
return calculateCost(new CalculationContext(baritone));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the execution of the latest Movement
|
* Handles the execution of the latest Movement
|
||||||
* State, and offers a Status to the calling class.
|
* State, and offers a Status to the calling class.
|
||||||
|
|
|
@ -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
|
// 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();
|
currentMovementOriginalCostEstimate = movement.getCost();
|
||||||
for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) {
|
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.");
|
logDebug("Something has changed in the world and a future movement has become impossible. Cancelling.");
|
||||||
cancel();
|
cancel();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double currentCost = movement.recalculateCost();
|
double currentCost = ((Movement) movement).recalculateCost(behavior.secretInternalGetCalculationContext());
|
||||||
if (currentCost >= ActionCosts.COST_INF && canCancel) {
|
if (currentCost >= ActionCosts.COST_INF && canCancel) {
|
||||||
logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
|
logDebug("Something has changed in the world and this movement has become impossible. Cancelling.");
|
||||||
cancel();
|
cancel();
|
||||||
|
|
|
@ -465,6 +465,9 @@ public class BuilderProcess extends BaritoneProcessHelper implements IBuilderPro
|
||||||
}
|
}
|
||||||
|
|
||||||
public Goal placementgoal(BlockPos pos, BuilderCalculationContext bcc) {
|
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;
|
boolean allowSameLevel = ctx.world().getBlockState(pos.up()).getBlock() != Blocks.AIR;
|
||||||
for (EnumFacing facing : Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP) {
|
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)) {
|
if (MovementHelper.canPlaceAgainst(ctx, pos.offset(facing)) && ctx.world().mayPlace(bcc.getSchematic(pos.getX(), pos.getY(), pos.getZ()).getBlock(), pos, false, facing, null)) {
|
||||||
|
|
|
@ -558,7 +558,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||||
while (moves.contains(null)) {
|
while (moves.contains(null)) {
|
||||||
moves.remove(null);
|
moves.remove(null);
|
||||||
}
|
}
|
||||||
moves.sort(Comparator.comparingDouble(Movement::getCost));
|
moves.sort(Comparator.comparingDouble(move -> move.getCost(new CalculationContext(baritone))));
|
||||||
for (Movement move : moves) {
|
for (Movement move : moves) {
|
||||||
String[] parts = move.getClass().toString().split("\\.");
|
String[] parts = move.getClass().toString().split("\\.");
|
||||||
double cost = move.getCost();
|
double cost = move.getCost();
|
||||||
|
|
Loading…
Reference in New Issue