diff --git a/src/main/java/baritone/bot/pathing/movement/IMovement.java b/src/main/java/baritone/bot/pathing/movement/IMovement.java new file mode 100644 index 00000000..7ab38c0c --- /dev/null +++ b/src/main/java/baritone/bot/pathing/movement/IMovement.java @@ -0,0 +1,13 @@ +package baritone.bot.pathing.movement; + +public interface IMovement { + + /** + * Handles the execution of the latest Movement + * State, and offers a Status to the calling class. + * + * @return Status + */ + MovementState.MovementStatus update(); + +} diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index a833e2b2..dcf915f5 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -1,7 +1,6 @@ package baritone.bot.pathing.movement; import baritone.bot.Baritone; -import baritone.bot.event.AbstractGameEventListener; import baritone.bot.pathing.movement.MovementState.MovementStatus; import baritone.bot.utils.Helper; import baritone.bot.utils.ToolSet; @@ -12,10 +11,9 @@ import net.minecraft.util.math.Vec3d; import java.util.Optional; -public abstract class Movement implements AbstractGameEventListener, Helper, MovementHelper { - - protected MovementState currentState; +public abstract class Movement implements IMovement, Helper, MovementHelper { + protected MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING); protected final BlockPos src; protected final BlockPos dest; @@ -39,23 +37,29 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov protected Movement(BlockPos src, BlockPos dest, BlockPos[] toBreak, BlockPos[] toPlace, Vec3d rotationTarget) { this(src, dest, toBreak, toPlace); - currentState = new MovementState() - .setLookDirection(rotationTarget) - .setStatus(MovementStatus.WAITING); +// currentState = new MovementState() +// .setGoal(new ) +// .setStatus(MovementStatus.WAITING); } public abstract double calculateCost(ToolSet ts); // TODO pass in information like whether it's allowed to place throwaway blocks - @Override - public void onTick() { - MovementState latestState = updateState(); - Optional orientation = latestState.getGoal().rotation; - if (orientation.isPresent()) { - Tuple rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), - orientation.get()); - mc.player.setPositionAndRotation(mc.player.posX, mc.player.posY, mc.player.posZ, - rotation.getFirst(), rotation.getSecond()); + public MovementStatus update() { + if(isPrepared(state)) { + if (!currentState.isPresent()) { + currentState = Optional.of(new MovementState() + .setStatus(MovementStatus.WAITING) + .setGoal()); + } } + if(isFinished()) { + + } + MovementState latestState = updateState(); + Tuple rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), + latestState.getGoal().rotation); + mc.player.setPositionAndRotation(mc.player.posX, mc.player.posY, mc.player.posZ, + rotation.getFirst(), rotation.getSecond()); //TODO calculate movement inputs from latestState.getGoal().position latestState.inputState.forEach((input, forced) -> { Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced); @@ -67,6 +71,13 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov return; } + private boolean prepare(MovementState state) { + Optional cruftPos; + for(BlockPos blockPos : positionsToBreak) { + world().getBlockState(blockPos).getBlock()(world()) + } + } + public boolean isFinished() { return (currentState.getStatus() != MovementStatus.RUNNING && currentState.getStatus() != MovementStatus.WAITING); @@ -91,5 +102,9 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov * * @return */ - public abstract MovementState updateState(); + public MovementState updateState(MovementState state) { + if(!prepare(state)) + return state.setStatus(MovementStatus.PREPPING); + 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 e6927311..26716a9b 100644 --- a/src/main/java/baritone/bot/pathing/movement/MovementState.java +++ b/src/main/java/baritone/bot/pathing/movement/MovementState.java @@ -5,14 +5,15 @@ import net.minecraft.util.math.Vec3d; import java.util.HashMap; import java.util.Map; -import java.util.Optional; public class MovementState { - protected MovementStatus status; - public MovementGoal goal = new MovementGoal(); + private MovementStatus status; + private MovementGoal goal; protected final Map inputState = new HashMap<>(); + private Vec3d interme; + public MovementState setStatus(MovementStatus status) { this.status = status; return this; @@ -28,18 +29,18 @@ public class MovementState { *

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

* getFirst() -> YAW * getSecond() -> PITCH */ - public Optional rotation; + public Vec3d rotation; - public MovementGoal() { - this.position = Optional.empty(); - this.rotation = Optional.empty(); + public MovementGoal(Vec3d position, Vec3d rotation) { + this.position = position; + this.rotation = rotation; } } @@ -47,23 +48,8 @@ public class MovementState { return goal; } - public MovementState setPosition(Vec3d posGoal) { - this.goal.position = Optional.of(posGoal); - return this; - } - - public MovementState clearPosition() { - this.goal.position = Optional.empty(); - return this; - } - - public MovementState setLookDirection(Vec3d rotGoal) { - this.goal.rotation = Optional.of(rotGoal); - return this; - } - - public MovementState clearLookDirection() { - this.goal.rotation = Optional.empty(); + public MovementState setGoal(MovementGoal goal) { + this.goal = goal; return this; } @@ -77,6 +63,6 @@ public class MovementState { } public enum MovementStatus { - WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED; + PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED; } } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java index dee137a7..2c6f36ff 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java @@ -3,6 +3,7 @@ package baritone.bot.pathing.movement.movements; import baritone.bot.InputOverrideHandler; import baritone.bot.pathing.movement.Movement; import baritone.bot.pathing.movement.MovementState; +import baritone.bot.pathing.movement.MovementState.MovementStatus; import baritone.bot.utils.ToolSet; import net.minecraft.util.math.BlockPos; @@ -23,10 +24,20 @@ public class MovementAscend extends Movement { } @Override - public MovementState updateState() { - MovementState latestState = currentState.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); - if (playerFeet().equals(dest)) - latestState.setStatus(MovementState.MovementStatus.SUCCESS); - return latestState; + public MovementState updateState(MovementState state) { + super.updateState(state); + switch(state.getStatus()) { + case PREPPING: + case UNREACHABLE: + case FAILED: + return state; + case WAITING: + case RUNNING: + MovementState latestState = currentState.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); + if (playerFeet().equals(dest)) + latestState.setStatus(MovementStatus.SUCCESS); + default: + return state; + } } } diff --git a/src/main/java/baritone/bot/utils/Helper.java b/src/main/java/baritone/bot/utils/Helper.java index 542e11af..516c7955 100755 --- a/src/main/java/baritone/bot/utils/Helper.java +++ b/src/main/java/baritone/bot/utils/Helper.java @@ -4,6 +4,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; /** * @author Brady @@ -13,6 +14,14 @@ public interface Helper { Minecraft mc = Minecraft.getMinecraft(); + default EntityPlayerSP player() { + return mc.player; + } + + default World world() { + return mc.world; + } + default BlockPos playerFeet() { return new BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ); }