General cleanups to the movement system.
This commit is contained in:
parent
732ab5273c
commit
fc082f42e7
@ -17,6 +17,7 @@ import static baritone.bot.InputOverrideHandler.Input;
|
||||
public abstract class Movement implements Helper, MovementHelper {
|
||||
|
||||
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||
|
||||
protected final BlockPos src;
|
||||
|
||||
protected final BlockPos dest;
|
||||
@ -24,12 +25,12 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
/**
|
||||
* The positions that need to be broken before this movement can ensue
|
||||
*/
|
||||
public final BlockPos[] positionsToBreak;
|
||||
protected final BlockPos[] positionsToBreak;
|
||||
|
||||
/**
|
||||
* The positions where we need to place a block before this movement can ensue
|
||||
*/
|
||||
public final BlockPos[] positionsToPlace;
|
||||
protected final BlockPos[] positionsToPlace;
|
||||
|
||||
private Double cost;
|
||||
|
||||
@ -75,11 +76,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
latestState.getTarget().getRotation().ifPresent(LookBehavior.INSTANCE::updateTarget);
|
||||
// TODO: calculate movement inputs from latestState.getGoal().position
|
||||
// latestState.getTarget().position.ifPresent(null); NULL CONSUMER REALLY SHOULDN'T BE THE FINAL THING YOU SHOULD REALLY REPLACE THIS WITH ALMOST ACTUALLY ANYTHING ELSE JUST PLEASE DON'T LEAVE IT AS IT IS THANK YOU KANYE
|
||||
latestState.inputState.forEach((input, forced) -> {
|
||||
latestState.getInputStates().forEach((input, forced) -> {
|
||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||
System.out.println(input + " AND " + forced);
|
||||
});
|
||||
latestState.inputState.replaceAll((input, forced) -> false);
|
||||
latestState.getInputStates().replaceAll((input, forced) -> false);
|
||||
currentState = latestState;
|
||||
|
||||
if (isFinished())
|
||||
@ -88,7 +89,6 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
return currentState.getStatus();
|
||||
}
|
||||
|
||||
|
||||
private boolean prepared(MovementState state) {
|
||||
if (state.getStatus() == MovementStatus.WAITING)
|
||||
return true;
|
||||
@ -123,14 +123,14 @@ public abstract class Movement implements Helper, MovementHelper {
|
||||
* Run cleanup on state finish and declare success.
|
||||
*/
|
||||
public void onFinish(MovementState state) {
|
||||
state.inputState.replaceAll((input, forced) -> false);
|
||||
state.inputState.forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
|
||||
state.getInputStates().replaceAll((input, forced) -> false);
|
||||
state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
|
||||
state.setStatus(MovementStatus.SUCCESS);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
currentState.inputState.replaceAll((input, forced) -> false);
|
||||
currentState.inputState.forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
|
||||
currentState.getInputStates().replaceAll((input, forced) -> false);
|
||||
currentState.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
|
||||
currentState.setStatus(MovementStatus.CANCELED);
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ public class MovementState {
|
||||
private MovementStatus status;
|
||||
private MovementTarget goal = new MovementTarget();
|
||||
private MovementTarget target = new MovementTarget();
|
||||
protected final Map<Input, Boolean> inputState = new HashMap<>();
|
||||
private final Map<Input, Boolean> inputState = new HashMap<>();
|
||||
|
||||
public MovementState setStatus(MovementStatus status) {
|
||||
this.status = status;
|
||||
@ -24,13 +24,50 @@ public class MovementState {
|
||||
return status;
|
||||
}
|
||||
|
||||
public MovementTarget getGoal() {
|
||||
return this.goal;
|
||||
}
|
||||
|
||||
public MovementState setGoal(MovementTarget goal) {
|
||||
this.goal = goal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementTarget getTarget() {
|
||||
return this.target;
|
||||
}
|
||||
|
||||
public MovementState setTarget(MovementTarget target) {
|
||||
this.target = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementState setInput(Input input, boolean forced) {
|
||||
this.inputState.put(input, forced);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getInput(Input input) {
|
||||
return this.inputState.getOrDefault(input, false);
|
||||
}
|
||||
|
||||
public Map<Input, Boolean> getInputStates() {
|
||||
return this.inputState;
|
||||
}
|
||||
|
||||
public enum MovementStatus {
|
||||
PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED, CANCELED
|
||||
}
|
||||
|
||||
public static class MovementTarget {
|
||||
|
||||
/**
|
||||
* Necessary movement to achieve
|
||||
* <p>
|
||||
* TODO: Decide desiredMovement type
|
||||
*/
|
||||
public Vec3d position;
|
||||
|
||||
/**
|
||||
* Yaw and pitch angles that must be matched
|
||||
* <p>
|
||||
@ -64,35 +101,4 @@ public class MovementState {
|
||||
return Optional.ofNullable(this.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public MovementTarget getGoal() {
|
||||
return goal;
|
||||
}
|
||||
|
||||
public MovementState setGoal(MovementTarget goal) {
|
||||
this.goal = goal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementTarget getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public MovementState setTarget(MovementTarget target) {
|
||||
this.target = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MovementState setInput(Input input, boolean forced) {
|
||||
inputState.put(input, forced);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean getInput(Input input) {
|
||||
return inputState.getOrDefault(input, false);
|
||||
}
|
||||
|
||||
public enum MovementStatus {
|
||||
PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED, CANCELED;
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,28 @@ import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementAscend extends Movement {
|
||||
BlockPos[] against = new BlockPos[3];
|
||||
|
||||
private BlockPos[] against = new BlockPos[3];
|
||||
|
||||
public MovementAscend(BlockPos src, BlockPos dest) {
|
||||
super(src, dest, new BlockPos[]{dest, src.up(2), dest.up()}, new BlockPos[]{dest.down()});
|
||||
super(src, dest, new BlockPos[] { dest, src.up(2), dest.up() }, new BlockPos[] { dest.down() });
|
||||
|
||||
BlockPos placementLocation = positionsToPlace[0];//end.down()
|
||||
BlockPos placementLocation = positionsToPlace[0]; // dest.down()
|
||||
int i = 0;
|
||||
if (!placementLocation.north().equals(src)) {
|
||||
against[i] = placementLocation.north();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.south().equals(src)) {
|
||||
against[i] = placementLocation.south();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.east().equals(src)) {
|
||||
against[i] = placementLocation.east();
|
||||
i++;
|
||||
}
|
||||
if (!placementLocation.west().equals(src)) {
|
||||
if (!placementLocation.north().equals(src))
|
||||
against[i++] = placementLocation.north();
|
||||
|
||||
if (!placementLocation.south().equals(src))
|
||||
against[i++] = placementLocation.south();
|
||||
|
||||
if (!placementLocation.east().equals(src))
|
||||
against[i++] = placementLocation.east();
|
||||
|
||||
if (!placementLocation.west().equals(src))
|
||||
against[i] = placementLocation.west();
|
||||
i++;
|
||||
}
|
||||
//TODO: add ability to place against .down() as well as the cardinal directions
|
||||
//useful for when you are starting a staircase without anything to place against
|
||||
|
||||
// TODO: add ability to place against .down() as well as the cardinal directions
|
||||
// useful for when you are starting a staircase without anything to place against
|
||||
// Counterpoint to the above TODO ^ you should move then pillar instead of ascend
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,9 @@ import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementDescend extends Movement {
|
||||
|
||||
public MovementDescend(BlockPos start, BlockPos end) {
|
||||
super(start, end, new BlockPos[]{end.up(2), end.up(), end}, new BlockPos[]{end.down()});
|
||||
super(start, end, new BlockPos[] { end.up(2), end.up(), end }, new BlockPos[] { end.down() });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,9 +9,10 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementDiagonal extends Movement {
|
||||
|
||||
public MovementDiagonal(BlockPos start, EnumFacing dir1, EnumFacing dir2) {
|
||||
this(start, start.offset(dir1), start.offset(dir2), dir2);
|
||||
//super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
||||
// super(start, start.offset(dir1).offset(dir2), new BlockPos[]{start.offset(dir1), start.offset(dir1).up(), start.offset(dir2), start.offset(dir2).up(), start.offset(dir1).offset(dir2), start.offset(dir1).offset(dir2).up()}, new BlockPos[]{start.offset(dir1).offset(dir2).down()});
|
||||
}
|
||||
|
||||
public MovementDiagonal(BlockPos start, BlockPos dir1, BlockPos dir2, EnumFacing drr2) {
|
||||
@ -19,7 +20,7 @@ public class MovementDiagonal extends Movement {
|
||||
}
|
||||
|
||||
public MovementDiagonal(BlockPos start, BlockPos end, BlockPos dir1, BlockPos dir2) {
|
||||
super(start, end, new BlockPos[]{dir1, dir1.up(), dir2, dir2.up(), end, end.up()}, new BlockPos[]{end.down()});
|
||||
super(start, end, new BlockPos[] { dir1, dir1.up(), dir2, dir2.up(), end, end.up() }, new BlockPos[] { end.down() });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -11,12 +11,13 @@ import net.minecraft.block.BlockVine;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class MovementDownward extends Movement {
|
||||
|
||||
private int numTicks = 0;
|
||||
|
||||
public MovementDownward(BlockPos start) {
|
||||
super(start, start.down(), new BlockPos[]{start.down()}, new BlockPos[0]);
|
||||
}
|
||||
|
||||
int numTicks = 0;
|
||||
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
|
@ -20,21 +20,8 @@ import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class MovementFall extends Movement {
|
||||
|
||||
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {
|
||||
BlockPos[] toBreak;
|
||||
int diffX = src.getX() - dest.getX();
|
||||
int diffZ = src.getZ() - dest.getZ();
|
||||
int diffY = src.getY() - dest.getY();
|
||||
toBreak = new BlockPos[diffY + 2];
|
||||
for (int i = 0; i < toBreak.length; i++) {
|
||||
toBreak[i] = new BlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ);
|
||||
}
|
||||
return toBreak;
|
||||
}
|
||||
|
||||
|
||||
public MovementFall(BlockPos src, BlockPos dest) {
|
||||
super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[]{dest.down()});
|
||||
super(src, dest, MovementFall.buildPositionsToBreak(src, dest), new BlockPos[] { dest.down() });
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -92,4 +79,15 @@ public class MovementFall extends Movement {
|
||||
}
|
||||
}
|
||||
|
||||
private static BlockPos[] buildPositionsToBreak(BlockPos src, BlockPos dest) {
|
||||
BlockPos[] toBreak;
|
||||
int diffX = src.getX() - dest.getX();
|
||||
int diffZ = src.getZ() - dest.getZ();
|
||||
int diffY = src.getY() - dest.getY();
|
||||
toBreak = new BlockPos[diffY + 2];
|
||||
for (int i = 0; i < toBreak.length; i++) {
|
||||
toBreak[i] = new BlockPos(src.getX() - diffX, src.getY() + 1 - i, src.getZ() - diffZ);
|
||||
}
|
||||
return toBreak;
|
||||
}
|
||||
}
|
||||
|
@ -22,27 +22,28 @@ import java.util.Objects;
|
||||
|
||||
public class MovementTraverse extends Movement {
|
||||
|
||||
BlockPos[] against = new BlockPos[3];
|
||||
private BlockPos[] against = new BlockPos[3];
|
||||
|
||||
/**
|
||||
* Did we have to place a bridge block or was it always there
|
||||
*/
|
||||
private boolean wasTheBridgeBlockAlwaysThere = true;
|
||||
|
||||
public MovementTraverse(BlockPos from, BlockPos to) {
|
||||
super(from, to, new BlockPos[]{to.up(), to}, new BlockPos[]{to.down()});
|
||||
int i = 0;
|
||||
if (!to.north().equals(from)) {
|
||||
against[i] = to.north().down();
|
||||
i++;
|
||||
}
|
||||
if (!to.south().equals(from)) {
|
||||
against[i] = to.south().down();
|
||||
i++;
|
||||
}
|
||||
if (!to.east().equals(from)) {
|
||||
against[i] = to.east().down();
|
||||
i++;
|
||||
}
|
||||
if (!to.west().equals(from)) {
|
||||
if (!to.north().equals(from))
|
||||
against[i++] = to.north().down();
|
||||
|
||||
if (!to.south().equals(from))
|
||||
against[i++] = to.south().down();
|
||||
|
||||
if (!to.east().equals(from))
|
||||
against[i++] = to.east().down();
|
||||
|
||||
if (!to.west().equals(from))
|
||||
against[i] = to.west().down();
|
||||
i++;
|
||||
}
|
||||
|
||||
//note: do NOT add ability to place against .down().down()
|
||||
}
|
||||
|
||||
@ -80,8 +81,6 @@ public class MovementTraverse extends Movement {
|
||||
}
|
||||
}
|
||||
|
||||
boolean wasTheBridgeBlockAlwaysThere = true;//did we have to place a bridge block or was it always there
|
||||
|
||||
@Override
|
||||
public MovementState updateState(MovementState state) {
|
||||
super.updateState(state);
|
||||
@ -115,7 +114,7 @@ public class MovementTraverse extends Movement {
|
||||
return state;
|
||||
}
|
||||
if (wasTheBridgeBlockAlwaysThere) {
|
||||
//player().setSprinting(true);
|
||||
// player().setSprinting(true);
|
||||
}
|
||||
moveTowards(positionsToBreak[0]);
|
||||
return state;
|
||||
@ -123,7 +122,7 @@ public class MovementTraverse extends Movement {
|
||||
wasTheBridgeBlockAlwaysThere = false;
|
||||
for (BlockPos against1 : against) {
|
||||
if (BlockStateInterface.get(against1).isBlockNormalCube()) {
|
||||
if (!MovementHelper.switchtothrowaway()) {//get ready to place a throwaway block
|
||||
if (!MovementHelper.switchtothrowaway()) { // get ready to place a throwaway block
|
||||
displayChatMessageRaw("bb pls get me some blocks. dirt or cobble");
|
||||
return state;
|
||||
}
|
||||
@ -138,7 +137,7 @@ public class MovementTraverse extends Movement {
|
||||
if (LookBehaviorUtils.getSelectedBlock().get().offset(side).equals(positionsToPlace[0])) {
|
||||
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);
|
||||
} else {
|
||||
//Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);
|
||||
// Out.gui("Wrong. " + side + " " + LookBehaviorUtils.getSelectedBlock().get().offset(side) + " " + positionsToPlace[0], Out.Mode.Debug);
|
||||
}
|
||||
}
|
||||
System.out.println("Trying to look at " + against1 + ", actually looking at" + LookBehaviorUtils.getSelectedBlock());
|
||||
@ -147,33 +146,32 @@ public class MovementTraverse extends Movement {
|
||||
}
|
||||
state.setInput(InputOverrideHandler.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.switchtothrowaway()) {//get ready to place a throwaway block
|
||||
// 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.switchtothrowaway()) {// get ready to place a throwaway block
|
||||
displayChatMessageRaw("bb pls get me some blocks. dirt or cobble");
|
||||
return state;
|
||||
}
|
||||
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;
|
||||
//faceX,faceY,faceZ is the middle of the face between from and to
|
||||
BlockPos goalLook = src.down();//this is the block we were just standing on, and the one we want to place against
|
||||
// faceX, faceY, faceZ is the middle of the face between from and to
|
||||
BlockPos goalLook = src.down(); // this is the block we were just standing on, and the one we want to place against
|
||||
state.setTarget(new MovementState.MovementTarget(Utils.calcRotationFromVec3d(playerHead(), new Vec3d(faceX, faceY, faceZ), playerRotations())));
|
||||
|
||||
state.setInput(InputOverrideHandler.Input.MOVE_BACK, true);
|
||||
state.setInput(InputOverrideHandler.Input.SNEAK, true);
|
||||
if (Objects.equals(LookBehaviorUtils.getSelectedBlock().orElse(null), goalLook)) {
|
||||
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true);//wait to right click until we are able to place
|
||||
state.setInput(InputOverrideHandler.Input.CLICK_RIGHT, true); // wait to right click until we are able to place
|
||||
return state;
|
||||
}
|
||||
//Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
// Out.log("Trying to look at " + goalLook + ", actually looking at" + Baritone.whatAreYouLookingAt());
|
||||
return state;
|
||||
} else {
|
||||
moveTowards(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
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user