cherry pick some movement fixes from builder
This commit is contained in:
parent
9b42aa3634
commit
b4d307d4cc
@ -18,7 +18,9 @@
|
||||
package baritone.pathing.movement;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.pathing.movement.ActionCosts;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.MovementState.MovementTarget;
|
||||
@ -35,6 +37,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP;
|
||||
|
||||
/**
|
||||
* Static helpers for cost calculation
|
||||
@ -485,4 +491,48 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
return state.getBlock() instanceof BlockLiquid
|
||||
&& state.getValue(BlockLiquid.LEVEL) != 0;
|
||||
}
|
||||
|
||||
static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, BlockPos placeAt, boolean preferDown) {
|
||||
IPlayerContext ctx = baritone.getPlayerContext();
|
||||
boolean found = false;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BlockPos against1 = placeAt.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
||||
//if (!((Baritone) baritone).getInventoryBehavior().selectThrowawayForLocation(placeAt.getX(), placeAt.getY(), placeAt.getZ())) { // get ready to place a throwaway block
|
||||
if (!throwaway(ctx, true)) {
|
||||
Helper.HELPER.logDebug("bb pls get me some blocks. dirt or cobble");
|
||||
state.setStatus(MovementStatus.UNREACHABLE);
|
||||
return PlaceResult.NO_OPTION;
|
||||
}
|
||||
double faceX = (placeAt.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (placeAt.getY() + against1.getY() + 1.0D) * 0.5D;
|
||||
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
|
||||
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance());
|
||||
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(placeAt)) {
|
||||
state.setTarget(new MovementState.MovementTarget(place, true));
|
||||
found = true;
|
||||
|
||||
if (!preferDown) {
|
||||
// if preferDown is true, we want the last option
|
||||
// if preferDown is false, we want the first
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ctx.getSelectedBlock().isPresent()) {
|
||||
BlockPos selectedBlock = ctx.getSelectedBlock().get();
|
||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||
// only way for selectedBlock.equals(placeAt) to be true is if it's replacable
|
||||
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(placeAt))) {
|
||||
return PlaceResult.READY_TO_PLACE;
|
||||
}
|
||||
}
|
||||
return found ? PlaceResult.ATTEMPTING : PlaceResult.NO_OPTION;
|
||||
}
|
||||
|
||||
enum PlaceResult {
|
||||
READY_TO_PLACE, ATTEMPTING, NO_OPTION;
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
@ -32,10 +31,6 @@ import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class MovementAscend extends Movement {
|
||||
|
||||
@ -162,55 +157,30 @@ public class MovementAscend extends Movement {
|
||||
|
||||
IBlockState jumpingOnto = BlockStateInterface.get(ctx, positionToPlace);
|
||||
if (!MovementHelper.canWalkOn(ctx, positionToPlace, jumpingOnto)) {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BlockPos anAgainst = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||
if (anAgainst.equals(src)) {
|
||||
continue;
|
||||
}
|
||||
if (MovementHelper.canPlaceAgainst(ctx, anAgainst)) {
|
||||
if (!MovementHelper.throwaway(ctx, true)) {//get ready to place a throwaway block
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
double faceX = (dest.getX() + anAgainst.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + anAgainst.getY()) * 0.5D;
|
||||
double faceZ = (dest.getZ() + anAgainst.getZ() + 1.0D) * 0.5D;
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||
|
||||
ctx.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||
if (Objects.equals(selectedBlock, anAgainst) && selectedBlock.offset(side).equals(positionToPlace)) {
|
||||
ticksWithoutPlacement++;
|
||||
if (MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false) == PlaceResult.READY_TO_PLACE) {
|
||||
state.setInput(Input.SNEAK, true);
|
||||
if (ctx.player().isSneaking()) {
|
||||
state.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
}
|
||||
if (ticksWithoutPlacement > 10) {
|
||||
// After 10 ticks without placement, we might be standing in the way, move back
|
||||
state.setInput(Input.MOVE_BACK, true);
|
||||
}
|
||||
} else {
|
||||
state.setInput(Input.CLICK_LEFT, true); // break whatever replaceable block is in the way
|
||||
}
|
||||
//System.out.println("Trying to look at " + anAgainst + ", actually looking at" + selectedBlock);
|
||||
});
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
MovementHelper.moveTowards(ctx, state, dest);
|
||||
if (MovementHelper.isBottomSlab(jumpingOnto) && !MovementHelper.isBottomSlab(BlockStateInterface.get(ctx, src.down()))) {
|
||||
return state; // don't jump while walking from a non double slab into a bottom slab
|
||||
}
|
||||
|
||||
if (Baritone.settings().assumeStep.get()) {
|
||||
if (Baritone.settings().assumeStep.get() || ctx.playerFeet().equals(src.up())) {
|
||||
// no need to hit space if we're already jumping
|
||||
return state;
|
||||
}
|
||||
|
||||
if (ctx.playerFeet().equals(src.up())) {
|
||||
return state; // no need to hit space if we're already jumping
|
||||
}
|
||||
|
||||
if (headBonkClear()) {
|
||||
return state.setInput(Input.JUMP, true);
|
||||
}
|
||||
|
@ -20,9 +20,6 @@ package baritone.pathing.movement.movements;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
@ -35,9 +32,6 @@ import net.minecraft.block.BlockStairs;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class MovementParkour extends Movement {
|
||||
|
||||
@ -209,36 +203,10 @@ public class MovementParkour extends Movement {
|
||||
}
|
||||
} else if (!ctx.playerFeet().equals(src)) {
|
||||
if (ctx.playerFeet().equals(src.offset(direction)) || ctx.player().posY - ctx.playerFeet().getY() > 0.0001) {
|
||||
|
||||
if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround) {
|
||||
BlockPos positionToPlace = dest.down();
|
||||
for (int i = 4; i >= 0; i--) { // go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory
|
||||
BlockPos against1 = positionToPlace.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||
if (against1.up().equals(src.offset(direction, 3))) { // we can't turn around that fast
|
||||
continue;
|
||||
}
|
||||
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
||||
if (!MovementHelper.throwaway(ctx, true)) {//get ready to place a throwaway block
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + against1.getY()) * 0.5D;
|
||||
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
Rotation place = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
|
||||
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance());
|
||||
if (res != null && res.typeOfHit == RayTraceResult.Type.BLOCK && res.getBlockPos().equals(against1) && res.getBlockPos().offset(res.sideHit).equals(dest.down())) {
|
||||
state.setTarget(new MovementState.MovementTarget(place, true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.getSelectedBlock().ifPresent(selectedBlock -> {
|
||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||
if (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.offset(side).equals(dest.down())) {
|
||||
if (!MovementHelper.canWalkOn(ctx, dest.down()) && !ctx.player().onGround && MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), true) == PlaceResult.READY_TO_PLACE) {
|
||||
// go in the opposite order to check DOWN before all horizontals -- down is preferable because you don't have to look to the side while in midair, which could mess up the trajectory
|
||||
state.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (dist == 3) { // this is a 2 block gap, dest = src + direction * 3
|
||||
double xDiff = (src.x + 0.5) - ctx.player().posX;
|
||||
double zDiff = (src.z + 0.5) - ctx.player().posZ;
|
||||
|
@ -35,6 +35,8 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class MovementPillar extends Movement {
|
||||
|
||||
public MovementPillar(IBaritone baritone, BetterBlockPos start, BetterBlockPos end) {
|
||||
@ -224,7 +226,7 @@ public class MovementPillar extends Movement {
|
||||
if (!(fr instanceof BlockAir || fr.isReplaceable(ctx.world(), src))) {
|
||||
state.setInput(Input.CLICK_LEFT, true);
|
||||
blockIsThere = false;
|
||||
} else if (ctx.player().isSneaking()) { // 1 tick after we're able to place
|
||||
} else if (ctx.player().isSneaking() && (Objects.equals(src.down(), ctx.objectMouseOver().getBlockPos()) || Objects.equals(src, ctx.objectMouseOver().getBlockPos()))) {
|
||||
state.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import net.minecraft.block.BlockFenceGate;
|
||||
import net.minecraft.block.BlockSlab;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
@ -136,7 +135,7 @@ public class MovementTraverse extends Movement {
|
||||
}
|
||||
// now that we've checked all possible directions to side place, we actually need to backplace
|
||||
if (srcDown == Blocks.SOUL_SAND || (srcDown instanceof BlockSlab && !((BlockSlab) srcDown).isDouble())) {
|
||||
return COST_INF; // can't sneak and backplace against soul sand or half slabs =/
|
||||
return COST_INF; // can't sneak and backplace against soul sand or half slabs (regardless of whether it's top half or bottom half) =/
|
||||
}
|
||||
if (srcDown == Blocks.FLOWING_WATER || srcDown == Blocks.WATER) {
|
||||
return COST_INF; // this is obviously impossible
|
||||
@ -247,20 +246,6 @@ public class MovementTraverse extends Movement {
|
||||
return state;
|
||||
} else {
|
||||
wasTheBridgeBlockAlwaysThere = false;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
BlockPos against1 = dest.offset(HORIZONTALS_BUT_ALSO_DOWN____SO_EVERY_DIRECTION_EXCEPT_UP[i]);
|
||||
if (against1.equals(src)) {
|
||||
continue;
|
||||
}
|
||||
against1 = against1.down();
|
||||
if (MovementHelper.canPlaceAgainst(ctx, against1)) {
|
||||
if (!MovementHelper.throwaway(ctx, true)) { // get ready to place a throwaway block
|
||||
logDebug("bb pls get me some blocks. dirt or cobble");
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
if (!Baritone.settings().assumeSafeWalk.get()) {
|
||||
state.setInput(Input.SNEAK, true);
|
||||
}
|
||||
Block standingOn = BlockStateInterface.get(ctx, ctx.playerFeet().down()).getBlock();
|
||||
if (standingOn.equals(Blocks.SOUL_SAND) || standingOn instanceof BlockSlab) { // see issue #118
|
||||
double dist = Math.max(Math.abs(dest.getX() + 0.5 - ctx.player().posX), Math.abs(dest.getZ() + 0.5 - ctx.player().posZ));
|
||||
@ -270,30 +255,36 @@ public class MovementTraverse extends Movement {
|
||||
.setInput(Input.MOVE_BACK, true);
|
||||
}
|
||||
}
|
||||
state.setInput(Input.MOVE_BACK, false);
|
||||
double faceX = (dest.getX() + against1.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + against1.getY()) * 0.5D;
|
||||
double faceZ = (dest.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
state.setTarget(new MovementState.MovementTarget(RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations()), true));
|
||||
|
||||
EnumFacing side = ctx.objectMouseOver().sideHit;
|
||||
if (Objects.equals(ctx.getSelectedBlock().orElse(null), against1) && (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) && ctx.getSelectedBlock().get().offset(side).equals(positionToPlace)) {
|
||||
return state.setInput(Input.CLICK_RIGHT, true);
|
||||
double dist1 = Math.max(Math.abs(ctx.player().posX - (dest.getX() + 0.5D)), Math.abs(ctx.player().posZ - (dest.getZ() + 0.5D)));
|
||||
PlaceResult p = MovementHelper.attemptToPlaceABlock(state, baritone, dest.down(), false);
|
||||
if ((p == PlaceResult.READY_TO_PLACE || dist1 < 0.6) && !Baritone.settings().assumeSafeWalk.get()) {
|
||||
state.setInput(Input.SNEAK, true);
|
||||
}
|
||||
//System.out.println("Trying to look at " + against1 + ", actually looking at" + RayTraceUtils.getSelectedBlock());
|
||||
switch (p) {
|
||||
case READY_TO_PLACE: {
|
||||
if (ctx.player().isSneaking() || Baritone.settings().assumeSafeWalk.get()) {
|
||||
state.setInput(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
case ATTEMPTING: {
|
||||
if (dist1 > 0.83) {
|
||||
// might need to go forward a bit
|
||||
float yaw = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), VecUtils.getBlockPosCenter(dest), ctx.playerRotations()).getYaw();
|
||||
if (Math.abs(state.getTarget().rotation.getYaw() - yaw) < 0.1) {
|
||||
// but only if our attempted place is straight ahead
|
||||
return state.setInput(Input.MOVE_FORWARD, true);
|
||||
}
|
||||
} else if (ctx.playerRotations().isReallyCloseTo(state.getTarget().rotation)) {
|
||||
// well i guess theres something in the way
|
||||
return state.setInput(Input.CLICK_LEFT, true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
if (!Baritone.settings().assumeSafeWalk.get()) {
|
||||
state.setInput(Input.SNEAK, true);
|
||||
}
|
||||
if (whereAmI.equals(dest)) {
|
||||
// If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of
|
||||
// Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI);
|
||||
if (!MovementHelper.throwaway(ctx, true)) {// get ready to place a throwaway block
|
||||
logDebug("bb pls get me some blocks. dirt or cobble");
|
||||
return state.setStatus(MovementStatus.UNREACHABLE);
|
||||
}
|
||||
double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D;
|
||||
double faceY = (dest.getY() + src.getY() - 1.0D) * 0.5D;
|
||||
double faceZ = (dest.getZ() + src.getZ() + 1.0D) * 0.5D;
|
||||
@ -302,27 +293,28 @@ public class MovementTraverse extends Movement {
|
||||
|
||||
Rotation backToFace = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), new Vec3d(faceX, faceY, faceZ), ctx.playerRotations());
|
||||
float pitch = backToFace.getPitch();
|
||||
double dist = Math.max(Math.abs(ctx.player().posX - faceX), Math.abs(ctx.player().posZ - faceZ));
|
||||
if (dist < 0.29) {
|
||||
double dist2 = Math.max(Math.abs(ctx.player().posX - faceX), Math.abs(ctx.player().posZ - faceZ));
|
||||
if (dist2 < 0.29) { // see issue #208
|
||||
float yaw = RotationUtils.calcRotationFromVec3d(VecUtils.getBlockPosCenter(dest), ctx.playerHead(), ctx.playerRotations()).getYaw();
|
||||
state.setTarget(new MovementState.MovementTarget(new Rotation(yaw, pitch), true));
|
||||
state.setInput(Input.MOVE_BACK, true);
|
||||
} else {
|
||||
state.setTarget(new MovementState.MovementTarget(backToFace, true));
|
||||
}
|
||||
state.setInput(Input.SNEAK, true);
|
||||
if (Objects.equals(ctx.getSelectedBlock().orElse(null), goalLook)) {
|
||||
return state.setInput(Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
||||
}
|
||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
return state.setInput(Input.CLICK_LEFT, true);
|
||||
} else {
|
||||
if (ctx.playerRotations().isReallyCloseTo(state.getTarget().rotation)) {
|
||||
state.setInput(Input.CLICK_LEFT, true);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
MovementHelper.moveTowards(ctx, state, positionsToBreak[0]);
|
||||
return state;
|
||||
// TODO MovementManager.moveTowardsBlock(to); // move towards not look at because if we are bridging for a couple blocks in a row, it is faster if we dont spin around and walk forwards then spin around and place backwards for every block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean safeToCancel(MovementState state) {
|
||||
|
Loading…
Reference in New Issue
Block a user