🅱️ erge

This commit is contained in:
Leijurv 2018-08-05 20:48:02 -04:00
commit 67b9532f99
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 50 additions and 28 deletions

View File

@ -1,17 +1,20 @@
package baritone.bot.pathing.movement;
import baritone.bot.Baritone;
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;
import baritone.bot.utils.ToolSet;
import baritone.bot.utils.Utils;
import net.minecraft.util.Tuple;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import java.util.Optional;
import static baritone.bot.InputOverrideHandler.Input;
public abstract class Movement implements Helper, MovementHelper {
private MovementState currentState = new MovementState().setStatus(MovementStatus.PREPPING);
@ -108,22 +111,11 @@ 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);
});
@ -135,14 +127,21 @@ 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;
@ -150,6 +149,7 @@ public abstract class Movement implements Helper, MovementHelper {
public boolean isFinished() {
return (currentState.getStatus() != MovementStatus.RUNNING
&& currentState.getStatus() != MovementStatus.PREPPING
&& currentState.getStatus() != MovementStatus.WAITING);
}
@ -173,8 +173,12 @@ 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);
}
}