vastly improve resilience to lagbacks, fixes #446
This commit is contained in:
@@ -30,9 +30,7 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraft.util.math.AxisAlignedBB;
|
import net.minecraft.util.math.AxisAlignedBB;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public abstract class Movement implements IMovement, MovementHelper {
|
public abstract class Movement implements IMovement, MovementHelper {
|
||||||
|
|
||||||
@@ -63,6 +61,8 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
public List<BlockPos> toPlaceCached = null;
|
public List<BlockPos> toPlaceCached = null;
|
||||||
public List<BlockPos> toWalkIntoCached = null;
|
public List<BlockPos> toWalkIntoCached = null;
|
||||||
|
|
||||||
|
private Set<BetterBlockPos> validPositionsCached = null;
|
||||||
|
|
||||||
private Boolean calculatedWhileLoaded;
|
private Boolean calculatedWhileLoaded;
|
||||||
|
|
||||||
protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
|
protected Movement(IBaritone baritone, BetterBlockPos src, BetterBlockPos dest, BetterBlockPos[] toBreak, BetterBlockPos toPlace) {
|
||||||
@@ -100,6 +100,16 @@ public abstract class Movement implements IMovement, MovementHelper {
|
|||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract Set<BetterBlockPos> calculateValidPositions();
|
||||||
|
|
||||||
|
public Set<BetterBlockPos> getValidPositions() {
|
||||||
|
if (validPositionsCached == null) {
|
||||||
|
validPositionsCached = calculateValidPositions();
|
||||||
|
Objects.requireNonNull(validPositionsCached);
|
||||||
|
}
|
||||||
|
return validPositionsCached;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
@@ -27,11 +27,14 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementAscend extends Movement {
|
public class MovementAscend extends Movement {
|
||||||
|
|
||||||
private int ticksWithoutPlacement = 0;
|
private int ticksWithoutPlacement = 0;
|
||||||
@@ -51,6 +54,17 @@ public class MovementAscend extends Movement {
|
|||||||
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
BetterBlockPos prior = new BetterBlockPos(src.subtract(getDirection()).up()); // sometimes we back up to place the block, also sprint ascends, also skip descend to straight ascend
|
||||||
|
return ImmutableSet.of(src,
|
||||||
|
src.up(),
|
||||||
|
dest,
|
||||||
|
prior,
|
||||||
|
prior.up()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
||||||
IBlockState toPlace = context.get(destX, y, destZ);
|
IBlockState toPlace = context.get(destX, y, destZ);
|
||||||
double additionalPlacementCost = 0;
|
double additionalPlacementCost = 0;
|
||||||
@@ -143,6 +157,10 @@ public class MovementAscend extends Movement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
|
if (ctx.playerFeet().y < src.y) {
|
||||||
|
// this check should run even when in preparing state (breaking blocks)
|
||||||
|
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
|
}
|
||||||
super.updateState(state);
|
super.updateState(state);
|
||||||
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
|
// TODO incorporate some behavior from ActionClimb (specifically how it waited until it was at most 1.2 blocks away before starting to jump
|
||||||
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
|
// for efficiency in ascending minimal height staircases, which is just repeated MovementAscend, so that it doesn't bonk its head on the ceiling repeatedly)
|
||||||
@@ -154,10 +172,6 @@ public class MovementAscend extends Movement {
|
|||||||
return state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.playerFeet().y < src.y) {
|
|
||||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
||||||
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
||||||
ticksWithoutPlacement++;
|
ticksWithoutPlacement++;
|
||||||
|
@@ -29,6 +29,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockFalling;
|
import net.minecraft.block.BlockFalling;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
@@ -37,6 +38,8 @@ import net.minecraft.init.Blocks;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementDescend extends Movement {
|
public class MovementDescend extends Movement {
|
||||||
|
|
||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
@@ -61,6 +64,11 @@ public class MovementDescend extends Movement {
|
|||||||
return result.cost;
|
return result.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
return ImmutableSet.of(src, dest.up(), dest);
|
||||||
|
}
|
||||||
|
|
||||||
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
||||||
double totalCost = 0;
|
double totalCost = 0;
|
||||||
IBlockState destDown = context.get(destX, y - 1, destZ);
|
IBlockState destDown = context.get(destX, y - 1, destZ);
|
||||||
|
@@ -28,6 +28,7 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.pathing.MutableMoveResult;
|
import baritone.utils.pathing.MutableMoveResult;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
@@ -36,6 +37,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementDiagonal extends Movement {
|
public class MovementDiagonal extends Movement {
|
||||||
|
|
||||||
@@ -64,6 +66,16 @@ public class MovementDiagonal extends Movement {
|
|||||||
return result.cost;
|
return result.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
BetterBlockPos diagA = new BetterBlockPos(src.x, src.y, dest.z);
|
||||||
|
BetterBlockPos diagB = new BetterBlockPos(dest.x, src.y, src.z);
|
||||||
|
if (dest.y != src.y) { // only if allowDiagonalDescend
|
||||||
|
return ImmutableSet.of(src, dest.up(), diagA, diagB, dest, diagA.down(), diagB.down());
|
||||||
|
}
|
||||||
|
return ImmutableSet.of(src, dest, diagA, diagB);
|
||||||
|
}
|
||||||
|
|
||||||
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
public static void cost(CalculationContext context, int x, int y, int z, int destX, int destZ, MutableMoveResult res) {
|
||||||
IBlockState destInto = context.get(destX, y, destZ);
|
IBlockState destInto = context.get(destX, y, destZ);
|
||||||
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) {
|
if (!MovementHelper.canWalkThrough(context.bsi, destX, y, destZ, destInto) || !MovementHelper.canWalkThrough(context.bsi, destX, y + 1, destZ)) {
|
||||||
@@ -171,8 +183,9 @@ public class MovementDiagonal extends Movement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.playerFeet().equals(dest)) {
|
if (ctx.playerFeet().equals(dest)) {
|
||||||
state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
return state;
|
} else if (!getValidPositions().contains(ctx.playerFeet())) {
|
||||||
|
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
if (sprint()) {
|
if (sprint()) {
|
||||||
state.setInput(Input.SPRINT, true);
|
state.setInput(Input.SPRINT, true);
|
||||||
@@ -181,7 +194,7 @@ public class MovementDiagonal extends Movement {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sprint() {
|
private boolean sprint() {
|
||||||
if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && !Baritone.settings().sprintInWater.value) {
|
if (MovementHelper.isLiquid(ctx, ctx.playerFeet()) && !Baritone.settings().sprintInWater.value) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -24,10 +24,13 @@ import baritone.pathing.movement.CalculationContext;
|
|||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementDownward extends Movement {
|
public class MovementDownward extends Movement {
|
||||||
|
|
||||||
private int numTicks = 0;
|
private int numTicks = 0;
|
||||||
@@ -47,6 +50,11 @@ public class MovementDownward extends Movement {
|
|||||||
return cost(context, src.x, src.y, src.z);
|
return cost(context, src.x, src.y, src.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
return ImmutableSet.of(src, dest);
|
||||||
|
}
|
||||||
|
|
||||||
public static double cost(CalculationContext context, int x, int y, int z) {
|
public static double cost(CalculationContext context, int x, int y, int z) {
|
||||||
if (!context.allowDownward) {
|
if (!context.allowDownward) {
|
||||||
return COST_INF;
|
return COST_INF;
|
||||||
@@ -73,6 +81,8 @@ public class MovementDownward extends Movement {
|
|||||||
|
|
||||||
if (ctx.playerFeet().equals(dest)) {
|
if (ctx.playerFeet().equals(dest)) {
|
||||||
return state.setStatus(MovementStatus.SUCCESS);
|
return state.setStatus(MovementStatus.SUCCESS);
|
||||||
|
} else if (!getValidPositions().contains(ctx.playerFeet())) {
|
||||||
|
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||||
}
|
}
|
||||||
double diffX = ctx.player().posX - (dest.getX() + 0.5);
|
double diffX = ctx.player().posX - (dest.getX() + 0.5);
|
||||||
double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
|
double diffZ = ctx.player().posZ - (dest.getZ() + 0.5);
|
||||||
|
@@ -42,7 +42,9 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementFall extends Movement {
|
public class MovementFall extends Movement {
|
||||||
|
|
||||||
@@ -63,6 +65,16 @@ public class MovementFall extends Movement {
|
|||||||
return result.cost;
|
return result.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
Set<BetterBlockPos> set = new HashSet<>();
|
||||||
|
set.add(src);
|
||||||
|
for (int y = src.y - dest.y; y >= 0; y--) {
|
||||||
|
set.add(dest.up(y));
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean willPlaceBucket() {
|
private boolean willPlaceBucket() {
|
||||||
CalculationContext context = new CalculationContext(baritone);
|
CalculationContext context = new CalculationContext(baritone);
|
||||||
MutableMoveResult result = new MutableMoveResult();
|
MutableMoveResult result = new MutableMoveResult();
|
||||||
|
@@ -34,6 +34,9 @@ import net.minecraft.block.state.IBlockState;
|
|||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementParkour extends Movement {
|
public class MovementParkour extends Movement {
|
||||||
|
|
||||||
private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
|
private static final BetterBlockPos[] EMPTY = new BetterBlockPos[]{};
|
||||||
@@ -174,6 +177,17 @@ public class MovementParkour extends Movement {
|
|||||||
return res.cost;
|
return res.cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
Set<BetterBlockPos> set = new HashSet<>();
|
||||||
|
for (int i = 0; i <= dist; i++) {
|
||||||
|
for (int y = 0; y < 2; y++) {
|
||||||
|
set.add(src.offset(direction, i).up(y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean safeToCancel(MovementState state) {
|
public boolean safeToCancel(MovementState state) {
|
||||||
// once this movement is instantiated, the state is default to PREPPING
|
// once this movement is instantiated, the state is default to PREPPING
|
||||||
|
@@ -30,6 +30,7 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
@@ -37,6 +38,7 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementPillar extends Movement {
|
public class MovementPillar extends Movement {
|
||||||
|
|
||||||
@@ -49,6 +51,11 @@ public class MovementPillar extends Movement {
|
|||||||
return cost(context, src.x, src.y, src.z);
|
return cost(context, src.x, src.y, src.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
return ImmutableSet.of(src, dest);
|
||||||
|
}
|
||||||
|
|
||||||
public static double cost(CalculationContext context, int x, int y, int z) {
|
public static double cost(CalculationContext context, int x, int y, int z) {
|
||||||
Block from = context.get(x, y, z).getBlock();
|
Block from = context.get(x, y, z).getBlock();
|
||||||
boolean ladder = from == Blocks.LADDER || from == Blocks.VINE;
|
boolean ladder = from == Blocks.LADDER || from == Blocks.VINE;
|
||||||
|
@@ -30,12 +30,15 @@ import baritone.pathing.movement.Movement;
|
|||||||
import baritone.pathing.movement.MovementHelper;
|
import baritone.pathing.movement.MovementHelper;
|
||||||
import baritone.pathing.movement.MovementState;
|
import baritone.pathing.movement.MovementState;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import net.minecraft.block.*;
|
import net.minecraft.block.*;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class MovementTraverse extends Movement {
|
public class MovementTraverse extends Movement {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,6 +61,11 @@ public class MovementTraverse extends Movement {
|
|||||||
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
return cost(context, src.x, src.y, src.z, dest.x, dest.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<BetterBlockPos> calculateValidPositions() {
|
||||||
|
return ImmutableSet.of(src, dest);
|
||||||
|
}
|
||||||
|
|
||||||
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
public static double cost(CalculationContext context, int x, int y, int z, int destX, int destZ) {
|
||||||
IBlockState pb0 = context.get(destX, y + 1, destZ);
|
IBlockState pb0 = context.get(destX, y + 1, destZ);
|
||||||
IBlockState pb1 = context.get(destX, y, destZ);
|
IBlockState pb1 = context.get(destX, y, destZ);
|
||||||
@@ -205,8 +213,8 @@ public class MovementTraverse extends Movement {
|
|||||||
|
|
||||||
if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
|
if (pb0.getBlock() instanceof BlockFenceGate || pb1.getBlock() instanceof BlockFenceGate) {
|
||||||
BlockPos blocked = !MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up()) ? positionsToBreak[0]
|
BlockPos blocked = !MovementHelper.isGatePassable(ctx, positionsToBreak[0], src.up()) ? positionsToBreak[0]
|
||||||
: !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1]
|
: !MovementHelper.isGatePassable(ctx, positionsToBreak[1], src) ? positionsToBreak[1]
|
||||||
: null;
|
: null;
|
||||||
if (blocked != null) {
|
if (blocked != null) {
|
||||||
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), blocked), ctx.playerRotations()), true))
|
return state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.calculateBlockCenter(ctx.world(), blocked), ctx.playerRotations()), true))
|
||||||
.setInput(Input.CLICK_RIGHT, true);
|
.setInput(Input.CLICK_RIGHT, true);
|
||||||
|
@@ -33,7 +33,6 @@ import baritone.pathing.movement.MovementHelper;
|
|||||||
import baritone.pathing.movement.movements.*;
|
import baritone.pathing.movement.movements.*;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.util.Tuple;
|
import net.minecraft.util.Tuple;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
@@ -100,14 +99,13 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
if (pathPosition >= path.length()) {
|
if (pathPosition >= path.length()) {
|
||||||
return true; // stop bugging me, I'm done
|
return true; // stop bugging me, I'm done
|
||||||
}
|
}
|
||||||
BetterBlockPos whereShouldIBe = path.positions().get(pathPosition);
|
Movement movement = (Movement) path.movements().get(pathPosition);
|
||||||
BetterBlockPos whereAmI = ctx.playerFeet();
|
BetterBlockPos whereAmI = ctx.playerFeet();
|
||||||
if (!whereShouldIBe.equals(whereAmI) && !Blocks.AIR.equals(BlockStateInterface.getBlock(ctx, whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip
|
if (!movement.getValidPositions().contains(whereAmI)) {
|
||||||
for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
|
for (int i = 0; i < pathPosition && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks
|
||||||
if (whereAmI.equals(path.positions().get(i))) {
|
if (((Movement) path.movements().get(i)).getValidPositions().contains(whereAmI)) {
|
||||||
logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i);
|
|
||||||
int previousPos = pathPosition;
|
int previousPos = pathPosition;
|
||||||
pathPosition = Math.max(i - 1, 0); // previous step might not actually be done
|
pathPosition = i;
|
||||||
for (int j = pathPosition; j <= previousPos; j++) {
|
for (int j = pathPosition; j <= previousPos; j++) {
|
||||||
path.movements().get(j).reset();
|
path.movements().get(j).reset();
|
||||||
}
|
}
|
||||||
@@ -173,10 +171,10 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
HashSet<BlockPos> newPlace = new HashSet<>();
|
HashSet<BlockPos> newPlace = new HashSet<>();
|
||||||
HashSet<BlockPos> newWalkInto = new HashSet<>();
|
HashSet<BlockPos> newWalkInto = new HashSet<>();
|
||||||
for (int i = pathPosition; i < path.movements().size(); i++) {
|
for (int i = pathPosition; i < path.movements().size(); i++) {
|
||||||
Movement movement = (Movement) path.movements().get(i);
|
Movement m = (Movement) path.movements().get(i);
|
||||||
newBreak.addAll(movement.toBreak(bsi));
|
newBreak.addAll(m.toBreak(bsi));
|
||||||
newPlace.addAll(movement.toPlace(bsi));
|
newPlace.addAll(m.toPlace(bsi));
|
||||||
newWalkInto.addAll(movement.toWalkInto(bsi));
|
newWalkInto.addAll(m.toWalkInto(bsi));
|
||||||
}
|
}
|
||||||
toBreak = newBreak;
|
toBreak = newBreak;
|
||||||
toPlace = newPlace;
|
toPlace = newPlace;
|
||||||
@@ -187,11 +185,13 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
if (end - start > 0) {
|
if (end - start > 0) {
|
||||||
System.out.println("Recalculating break and place took " + (end - start) + "ms");
|
System.out.println("Recalculating break and place took " + (end - start) + "ms");
|
||||||
}*/
|
}*/
|
||||||
IMovement movement = path.movements().get(pathPosition);
|
if (pathPosition < path.movements().size() - 1) {
|
||||||
if (!behavior.baritone.bsi.worldContainsLoadedChunk(movement.getDest().x, movement.getDest().z)) {
|
IMovement next = path.movements().get(pathPosition + 1);
|
||||||
logDebug("Pausing since destination is at edge of loaded chunks");
|
if (!behavior.baritone.bsi.worldContainsLoadedChunk(next.getDest().x, next.getDest().z)) {
|
||||||
clearKeys();
|
logDebug("Pausing since destination is at edge of loaded chunks");
|
||||||
return true;
|
clearKeys();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
boolean canCancel = movement.safeToCancel();
|
boolean canCancel = movement.safeToCancel();
|
||||||
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
if (costEstimateIndex == null || costEstimateIndex != pathPosition) {
|
||||||
@@ -206,7 +206,7 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double currentCost = ((Movement) movement).recalculateCost(behavior.secretInternalGetCalculationContext());
|
double currentCost = 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();
|
||||||
@@ -258,11 +258,13 @@ public class PathExecutor implements IPathExecutor, Helper {
|
|||||||
private Tuple<Double, BlockPos> closestPathPos(IPath path) {
|
private Tuple<Double, BlockPos> closestPathPos(IPath path) {
|
||||||
double best = -1;
|
double best = -1;
|
||||||
BlockPos bestPos = null;
|
BlockPos bestPos = null;
|
||||||
for (BlockPos pos : path.positions()) {
|
for (IMovement movement : path.movements()) {
|
||||||
double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos);
|
for (BlockPos pos : ((Movement) movement).getValidPositions()) {
|
||||||
if (dist < best || best == -1) {
|
double dist = VecUtils.entityDistanceToCenter(ctx.player(), pos);
|
||||||
best = dist;
|
if (dist < best || best == -1) {
|
||||||
bestPos = pos;
|
best = dist;
|
||||||
|
bestPos = pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Tuple<>(best, bestPos);
|
return new Tuple<>(best, bestPos);
|
||||||
|
Reference in New Issue
Block a user