Pathing is functioning

This commit is contained in:
Howard Stark 2018-08-05 21:52:55 -04:00
parent 5b96e6cd57
commit 2f06857858
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
7 changed files with 33 additions and 12 deletions

View File

@ -1,6 +1,7 @@
package baritone.bot; package baritone.bot;
import baritone.bot.behavior.Behavior; import baritone.bot.behavior.Behavior;
import baritone.bot.behavior.impl.LookBehavior;
import baritone.bot.behavior.impl.PathingBehavior; import baritone.bot.behavior.impl.PathingBehavior;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,6 +43,7 @@ public enum Baritone {
this.inputOverrideHandler = new InputOverrideHandler(); this.inputOverrideHandler = new InputOverrideHandler();
this.behaviors = new ArrayList<>(); this.behaviors = new ArrayList<>();
behaviors.add(PathingBehavior.INSTANCE); behaviors.add(PathingBehavior.INSTANCE);
behaviors.add(LookBehavior.INSTANCE);
this.active = true; this.active = true;
this.initialized = true; this.initialized = true;

View File

@ -46,6 +46,8 @@ public final class InputOverrideHandler implements Helper {
* @param forced Whether or not the state is being forced * @param forced Whether or not the state is being forced
*/ */
public final void setInputForceState(Input input, boolean forced) { public final void setInputForceState(Input input, boolean forced) {
if(!forced)
System.out.println(input);
inputForceStateMap.put(input.getKeyBinding(), forced); inputForceStateMap.put(input.getKeyBinding(), forced);
} }

View File

@ -1,6 +1,7 @@
package baritone.bot.behavior.impl; package baritone.bot.behavior.impl;
import baritone.bot.behavior.Behavior; import baritone.bot.behavior.Behavior;
import baritone.bot.event.events.TickEvent;
import baritone.bot.utils.Rotation; import baritone.bot.utils.Rotation;
import java.util.Optional; import java.util.Optional;
@ -25,6 +26,11 @@ public class LookBehavior extends Behavior {
this.target = Optional.of(target); this.target = Optional.of(target);
} }
@Override
public void onTick(TickEvent event) {
this.onPlayerUpdate();
}
@Override @Override
public void onPlayerUpdate() { public void onPlayerUpdate() {
if(target.isPresent()) { if(target.isPresent()) {

View File

@ -112,8 +112,11 @@ public abstract class Movement implements Helper, MovementHelper {
MovementState latestState = updateState(currentState); MovementState latestState = updateState(currentState);
latestState.getTarget().rotation.ifPresent(LookBehavior.INSTANCE::updateTarget); latestState.getTarget().rotation.ifPresent(LookBehavior.INSTANCE::updateTarget);
//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.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)); latestState.inputState.forEach((input, forced) -> {
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
System.out.println(input + " AND " + forced);
});
latestState.inputState.replaceAll((input, forced) -> false); latestState.inputState.replaceAll((input, forced) -> false);
currentState = latestState; currentState = latestState;
@ -160,6 +163,8 @@ public abstract class Movement implements Helper, MovementHelper {
* Run cleanup on state finish and declare success. * Run cleanup on state finish and declare success.
*/ */
public void onFinish(MovementState state) { public void onFinish(MovementState state) {
state.inputState.replaceAll((input, forced) -> false);
state.inputState.forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
state.setStatus(MovementStatus.SUCCESS); state.setStatus(MovementStatus.SUCCESS);
} }

View File

@ -11,8 +11,8 @@ import java.util.Optional;
public class MovementState { public class MovementState {
private MovementStatus status; private MovementStatus status;
private MovementTarget goal; private MovementTarget goal = new MovementTarget(Optional.empty(), Optional.empty());
private MovementTarget target; private MovementTarget target = new MovementTarget(Optional.empty(), Optional.empty());
protected final Map<Input, Boolean> inputState = new HashMap<>(); protected final Map<Input, Boolean> inputState = new HashMap<>();
public MovementState setStatus(MovementStatus status) { public MovementState setStatus(MovementStatus status) {

View File

@ -73,11 +73,14 @@ public class MovementAscend extends Movement {
return state; return state;
case WAITING: case WAITING:
case RUNNING: case RUNNING:
state.setTarget(new MovementState.MovementTarget(Optional.empty(), Optional.of(Utils.calcRotationFromCoords(playerFeet(), positionsToBreak[0])))); if (playerFeet().equals(dest)) {
state.setStatus(MovementStatus.SUCCESS);
return state;
}
MovementState latestState = state.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); state.setTarget(new MovementState.MovementTarget(Optional.empty(), Optional.of(Utils.calcRotationFromCoords(playerFeet(), positionsToBreak[0]))));
if (playerFeet().equals(dest)) state.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
latestState.setStatus(MovementStatus.SUCCESS); return state;
default: default:
return state; return state;
} }

View File

@ -93,10 +93,13 @@ public class MovementTraverse extends Movement {
return state; return state;
case WAITING: case WAITING:
case RUNNING: case RUNNING:
state.setTarget(new MovementState.MovementTarget(Optional.empty(), Optional.of(Utils.calcRotationFromCoords(playerFeet(), positionsToBreak[0])))); if (playerFeet().equals(dest)) {
MovementState latestState = state.setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); state.setStatus(MovementState.MovementStatus.SUCCESS);
if (playerFeet().equals(dest)) return state;
latestState.setStatus(MovementState.MovementStatus.SUCCESS); }
state.setTarget(new MovementState.MovementTarget(Optional.empty(), Optional.of(Utils.calcRotationFromCoords(playerFeet(), positionsToBreak[1])))).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true);
return state;
default: default:
return state; return state;
} }