fix weird behavior where allowBreak false broke #goto

This commit is contained in:
Leijurv 2021-04-03 16:41:45 -07:00
parent fe491e4a7d
commit 43d5458a25
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A

View File

@ -30,6 +30,7 @@ import baritone.api.utils.input.Input;
import baritone.pathing.movement.CalculationContext;
import baritone.utils.BaritoneProcessHelper;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ContainerPlayer;
import net.minecraft.util.math.BlockPos;
@ -57,7 +58,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
start = ctx.playerFeet();
blacklist = new ArrayList<>();
arrivalTickCount = 0;
rescan(new ArrayList<>(), new CalculationContext(baritone));
rescan(new ArrayList<>(), new GetToBlockCalculationContext(false));
}
@Override
@ -68,7 +69,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
@Override
public synchronized PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (knownLocations == null) {
rescan(new ArrayList<>(), new CalculationContext(baritone));
rescan(new ArrayList<>(), new GetToBlockCalculationContext(false));
}
if (knownLocations.isEmpty()) {
if (Baritone.settings().exploreForBlocks.value && !calcFailed) {
@ -77,6 +78,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
public boolean isInGoal(int x, int y, int z) {
return false;
}
@Override
public double heuristic() {
return Double.NEGATIVE_INFINITY;
@ -106,7 +108,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
List<BlockPos> current = new ArrayList<>(knownLocations);
CalculationContext context = new CalculationContext(baritone, true);
CalculationContext context = new GetToBlockCalculationContext(true);
Baritone.getExecutor().execute(() -> rescan(current, context));
}
if (goal.isInGoal(ctx.playerFeet()) && goal.isInGoal(baritone.getPathingBehavior().pathStart()) && isSafeToCancel) {
@ -151,6 +153,20 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
return !newBlacklist.isEmpty();
}
// this is to signal to MineProcess that we don't care about the allowBreak setting
// it is NOT to be used to actually calculate a path
public class GetToBlockCalculationContext extends CalculationContext {
public GetToBlockCalculationContext(boolean forUseOnAnotherThread) {
super(GetToBlockProcess.super.baritone, forUseOnAnotherThread);
}
@Override
public double breakCostMultiplierAt(int x, int y, int z, IBlockState current) {
return 1;
}
}
// safer than direct double comparison from distanceSq
private boolean areAdjacent(BlockPos posA, BlockPos posB) {
int diffX = Math.abs(posA.getX() - posB.getX());