Skip to content

Commit

Permalink
fix weird behavior where allowBreak false broke #goto
Browse files Browse the repository at this point in the history
  • Loading branch information
leijurv committed Apr 3, 2021
1 parent fe491e4 commit 43d5458
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/main/java/baritone/process/GetToBlockProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void getToBlock(BlockOptionalMeta block) {
start = ctx.playerFeet();
blacklist = new ArrayList<>();
arrivalTickCount = 0;
rescan(new ArrayList<>(), new CalculationContext(baritone));
rescan(new ArrayList<>(), new GetToBlockCalculationContext(false));
}

@Override
Expand All @@ -68,7 +69,7 @@ public boolean isActive() {
@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) {
Expand All @@ -77,6 +78,7 @@ public synchronized PathingCommand onTick(boolean calcFailed, boolean isSafeToCa
public boolean isInGoal(int x, int y, int z) {
return false;
}

@Override
public double heuristic() {
return Double.NEGATIVE_INFINITY;
Expand Down Expand Up @@ -106,7 +108,7 @@ public double heuristic() {
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) {
Expand Down Expand Up @@ -151,6 +153,20 @@ public synchronized boolean blacklistClosest() {
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());
Expand Down

0 comments on commit 43d5458

Please sign in to comment.