diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index 2e5b07e6..cd7a3e1f 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -1,6 +1,9 @@ package baritone.bot.pathing.movement; import baritone.bot.Baritone; +import baritone.bot.InputOverrideHandler; +import baritone.bot.behavior.impl.LookBehavior; +import baritone.bot.behavior.impl.LookBehaviorUtils; import baritone.bot.pathing.movement.MovementState.MovementStatus; import baritone.bot.utils.BlockStateInterface; import baritone.bot.utils.Helper; @@ -12,6 +15,8 @@ import net.minecraft.util.math.Vec3d; import java.util.Optional; +import static baritone.bot.InputOverrideHandler.*; + public abstract class Movement implements Helper, MovementHelper { private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING); @@ -52,22 +57,10 @@ public abstract class Movement implements Helper, MovementHelper { * @return Status */ public MovementStatus update() { -// if(isPrepared(state)) { -// if (!currentState.isPresent()) { -// currentState = Optional.of(new MovementState() -// .setStatus(MovementStatus.WAITING) -// .setGoal()); -// } -// } - if(isFinished()) { - - } MovementState latestState = updateState(currentState); - Tuple rotation = Utils.calcRotationFromVec3d(player().getPositionEyes(1.0F), - latestState.getGoal().rotation); - player().setPositionAndRotation(player().posX, player().posY, player().posZ, - rotation.getFirst(), rotation.getSecond()); + latestState.getTarget().rotation.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) -> { Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced); }); @@ -79,14 +72,20 @@ public abstract class Movement implements Helper, MovementHelper { return currentState.getStatus(); } - private boolean prepare(MovementState state) { + private boolean prepared(MovementState state) { if(state.getStatus() == MovementStatus.WAITING) { return true; } Optional cruftPos; for(BlockPos blockPos : positionsToBreak) { if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) { - + Optional> reachable = LookBehaviorUtils.reachable(blockPos); + reachable.ifPresent(rotation -> { + state.setTarget(new MovementState.MovementTarget()) + state.setInput(Input.CLICK_LEFT, true); + }); + if (reachable.isPresent()) + return false; } } return true; @@ -94,6 +93,7 @@ public abstract class Movement implements Helper, MovementHelper { public boolean isFinished() { return (currentState.getStatus() != MovementStatus.RUNNING + && currentState.getStatus() != MovementStatus.PREPPING && currentState.getStatus() != MovementStatus.WAITING); } @@ -117,8 +117,11 @@ public abstract class Movement implements Helper, MovementHelper { * @return */ public MovementState updateState(MovementState state) { - if(!prepare(state)) + if(!prepared(state)) return state.setStatus(MovementStatus.PREPPING); + else if(state.getStatus() == MovementStatus.PREPPING) { + state.setInput(Input.CLICK_LEFT, false); + } return state; } } diff --git a/src/main/java/baritone/bot/pathing/movement/MovementState.java b/src/main/java/baritone/bot/pathing/movement/MovementState.java index 26716a9b..e5aebed9 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementState.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementState.java @@ -1,19 +1,20 @@ package baritone.bot.pathing.movement; import baritone.bot.InputOverrideHandler.Input; +import baritone.bot.utils.Rotation; import net.minecraft.util.math.Vec3d; import java.util.HashMap; import java.util.Map; +import java.util.Optional; public class MovementState { private MovementStatus status; - private MovementGoal goal; + private MovementTarget goal; + private MovementTarget target; protected final Map inputState = new HashMap<>(); - private Vec3d interme; - public MovementState setStatus(MovementStatus status) { this.status = status; return this; @@ -23,36 +24,44 @@ public class MovementState { return status; } - public static class MovementGoal { + public static class MovementTarget { /** * Necessary movement to achieve *

* TODO: Decide desiredMovement type */ - public Vec3d position; + public Optional position; /** * Yaw and pitch angles that must be matched *

* getFirst() -> YAW * getSecond() -> PITCH */ - public Vec3d rotation; + public Optional rotation; - public MovementGoal(Vec3d position, Vec3d rotation) { - this.position = position; - this.rotation = rotation; + public MovementTarget(Vec3d position, Rotation rotation) { + this.position = Optional.of(position); + this.rotation = Optional.of(rotation); } } - public MovementGoal getGoal() { + public MovementTarget getGoal() { return goal; } - public MovementState setGoal(MovementGoal goal) { + public MovementState setGoal(MovementTarget goal) { this.goal = goal; return this; } + public MovementTarget getTarget() { + return target; + } + + public void setTarget(MovementTarget target) { + this.target = target; + } + public MovementState setInput(Input input, boolean forced) { inputState.put(input, forced); return this; diff --git a/src/main/java/baritone/bot/utils/Rotation.java b/src/main/java/baritone/bot/utils/Rotation.java new file mode 100644 index 00000000..cc5232ff --- /dev/null +++ b/src/main/java/baritone/bot/utils/Rotation.java @@ -0,0 +1,9 @@ +package baritone.bot.utils; + +import net.minecraft.util.Tuple; + +public class Rotation extends Tuple { + public Rotation(Float yaw, Float pitch) { + super(yaw, pitch); + } +}