Finish Behavior simple implementation
This commit is contained in:
parent
2edc7327ab
commit
c1d61a63ae
@ -1,6 +1,9 @@
|
|||||||
package baritone.bot.pathing.movement;
|
package baritone.bot.pathing.movement;
|
||||||
|
|
||||||
import baritone.bot.Baritone;
|
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.pathing.movement.MovementState.MovementStatus;
|
||||||
import baritone.bot.utils.BlockStateInterface;
|
import baritone.bot.utils.BlockStateInterface;
|
||||||
import baritone.bot.utils.Helper;
|
import baritone.bot.utils.Helper;
|
||||||
@ -12,6 +15,8 @@ import net.minecraft.util.math.Vec3d;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static baritone.bot.InputOverrideHandler.*;
|
||||||
|
|
||||||
public abstract class Movement implements Helper, MovementHelper {
|
public abstract class Movement implements Helper, MovementHelper {
|
||||||
|
|
||||||
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||||
@ -52,22 +57,10 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
* @return Status
|
* @return Status
|
||||||
*/
|
*/
|
||||||
public MovementStatus update() {
|
public MovementStatus update() {
|
||||||
// if(isPrepared(state)) {
|
|
||||||
// if (!currentState.isPresent()) {
|
|
||||||
// currentState = Optional.of(new MovementState()
|
|
||||||
// .setStatus(MovementStatus.WAITING)
|
|
||||||
// .setGoal());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if(isFinished()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
MovementState latestState = updateState(currentState);
|
MovementState latestState = updateState(currentState);
|
||||||
Tuple<Float, Float> rotation = Utils.calcRotationFromVec3d(player().getPositionEyes(1.0F),
|
latestState.getTarget().rotation.ifPresent(LookBehavior.INSTANCE::updateTarget);
|
||||||
latestState.getGoal().rotation);
|
|
||||||
player().setPositionAndRotation(player().posX, player().posY, player().posZ,
|
|
||||||
rotation.getFirst(), rotation.getSecond());
|
|
||||||
//TODO calculate movement inputs from latestState.getGoal().position
|
//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.inputState.forEach((input, forced) -> {
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||||
});
|
});
|
||||||
@ -79,14 +72,20 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
return currentState.getStatus();
|
return currentState.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean prepare(MovementState state) {
|
private boolean prepared(MovementState state) {
|
||||||
if(state.getStatus() == MovementStatus.WAITING) {
|
if(state.getStatus() == MovementStatus.WAITING) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Optional<BlockPos> cruftPos;
|
Optional<BlockPos> cruftPos;
|
||||||
for(BlockPos blockPos : positionsToBreak) {
|
for(BlockPos blockPos : positionsToBreak) {
|
||||||
if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
|
if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
|
||||||
|
Optional<Tuple<Float, Float>> 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;
|
return true;
|
||||||
@ -94,6 +93,7 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
|
|
||||||
public boolean isFinished() {
|
public boolean isFinished() {
|
||||||
return (currentState.getStatus() != MovementStatus.RUNNING
|
return (currentState.getStatus() != MovementStatus.RUNNING
|
||||||
|
&& currentState.getStatus() != MovementStatus.PREPPING
|
||||||
&& currentState.getStatus() != MovementStatus.WAITING);
|
&& currentState.getStatus() != MovementStatus.WAITING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,8 +117,11 @@ public abstract class Movement implements Helper, MovementHelper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public MovementState updateState(MovementState state) {
|
public MovementState updateState(MovementState state) {
|
||||||
if(!prepare(state))
|
if(!prepared(state))
|
||||||
return state.setStatus(MovementStatus.PREPPING);
|
return state.setStatus(MovementStatus.PREPPING);
|
||||||
|
else if(state.getStatus() == MovementStatus.PREPPING) {
|
||||||
|
state.setInput(Input.CLICK_LEFT, false);
|
||||||
|
}
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
package baritone.bot.pathing.movement;
|
package baritone.bot.pathing.movement;
|
||||||
|
|
||||||
import baritone.bot.InputOverrideHandler.Input;
|
import baritone.bot.InputOverrideHandler.Input;
|
||||||
|
import baritone.bot.utils.Rotation;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class MovementState {
|
public class MovementState {
|
||||||
|
|
||||||
private MovementStatus status;
|
private MovementStatus status;
|
||||||
private MovementGoal goal;
|
private MovementTarget goal;
|
||||||
|
private MovementTarget target;
|
||||||
protected final Map<Input, Boolean> inputState = new HashMap<>();
|
protected final Map<Input, Boolean> inputState = new HashMap<>();
|
||||||
|
|
||||||
private Vec3d interme;
|
|
||||||
|
|
||||||
public MovementState setStatus(MovementStatus status) {
|
public MovementState setStatus(MovementStatus status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
return this;
|
return this;
|
||||||
@ -23,36 +24,44 @@ public class MovementState {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class MovementGoal {
|
public static class MovementTarget {
|
||||||
/**
|
/**
|
||||||
* Necessary movement to achieve
|
* Necessary movement to achieve
|
||||||
* <p>
|
* <p>
|
||||||
* TODO: Decide desiredMovement type
|
* TODO: Decide desiredMovement type
|
||||||
*/
|
*/
|
||||||
public Vec3d position;
|
public Optional<Vec3d> position;
|
||||||
/**
|
/**
|
||||||
* Yaw and pitch angles that must be matched
|
* Yaw and pitch angles that must be matched
|
||||||
* <p>
|
* <p>
|
||||||
* getFirst() -> YAW
|
* getFirst() -> YAW
|
||||||
* getSecond() -> PITCH
|
* getSecond() -> PITCH
|
||||||
*/
|
*/
|
||||||
public Vec3d rotation;
|
public Optional<Rotation> rotation;
|
||||||
|
|
||||||
public MovementGoal(Vec3d position, Vec3d rotation) {
|
public MovementTarget(Vec3d position, Rotation rotation) {
|
||||||
this.position = position;
|
this.position = Optional.of(position);
|
||||||
this.rotation = rotation;
|
this.rotation = Optional.of(rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovementGoal getGoal() {
|
public MovementTarget getGoal() {
|
||||||
return goal;
|
return goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MovementState setGoal(MovementGoal goal) {
|
public MovementState setGoal(MovementTarget goal) {
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MovementTarget getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(MovementTarget target) {
|
||||||
|
this.target = target;
|
||||||
|
}
|
||||||
|
|
||||||
public MovementState setInput(Input input, boolean forced) {
|
public MovementState setInput(Input input, boolean forced) {
|
||||||
inputState.put(input, forced);
|
inputState.put(input, forced);
|
||||||
return this;
|
return this;
|
||||||
|
9
src/main/java/baritone/bot/utils/Rotation.java
Normal file
9
src/main/java/baritone/bot/utils/Rotation.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package baritone.bot.utils;
|
||||||
|
|
||||||
|
import net.minecraft.util.Tuple;
|
||||||
|
|
||||||
|
public class Rotation extends Tuple<Float, Float> {
|
||||||
|
public Rotation(Float yaw, Float pitch) {
|
||||||
|
super(yaw, pitch);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user