Finish Behavior simple implementation

This commit is contained in:
Howard Stark 2018-08-05 20:37:42 -04:00
parent 2edc7327ab
commit c1d61a63ae
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
3 changed files with 49 additions and 28 deletions

View File

@ -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<Float, Float> 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<BlockPos> cruftPos;
for(BlockPos blockPos : positionsToBreak) {
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;
@ -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;
}
}

View File

@ -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<Input, Boolean> 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
* <p>
* TODO: Decide desiredMovement type
*/
public Vec3d position;
public Optional<Vec3d> position;
/**
* Yaw and pitch angles that must be matched
* <p>
* getFirst() -> YAW
* getSecond() -> PITCH
*/
public Vec3d rotation;
public Optional<Rotation> 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;

View 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);
}
}