From 785e5377e671395dd3b1faf92f4977abc66a8e60 Mon Sep 17 00:00:00 2001
From: Howard Stark <howard@getcoffee.io>
Date: Sun, 5 Aug 2018 21:17:54 -0400
Subject: [PATCH] Clean up Movement input behavior

---
 .../bot/pathing/movement/Movement.java         | 18 +++++++++---------
 .../bot/pathing/movement/MovementState.java    |  5 +++--
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java
index 90ee795e..b8e34739 100644
--- a/src/main/java/baritone/bot/pathing/movement/Movement.java
+++ b/src/main/java/baritone/bot/pathing/movement/Movement.java
@@ -113,13 +113,12 @@ public abstract class Movement implements Helper, MovementHelper {
         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);
-        });
+        latestState.inputState.forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
+        latestState.inputState.replaceAll((input, forced) -> false);
         currentState = latestState;
 
         if (isFinished())
-            onFinish();
+            onFinish(latestState);
 
         return currentState.getStatus();
     }
@@ -133,8 +132,8 @@ public abstract class Movement implements Helper, MovementHelper {
             if(MovementHelper.canWalkThrough(blockPos, BlockStateInterface.get(blockPos))) {
                 Optional<Rotation> reachable = LookBehaviorUtils.reachable(blockPos);
                 reachable.ifPresent(rotation -> {
-                    state.setTarget(new MovementState.MovementTarget(Optional.empty(), reachable));
-                    state.setInput(Input.CLICK_LEFT, true);
+                    state.setTarget(new MovementState.MovementTarget(Optional.empty(), reachable))
+                            .setInput(Input.CLICK_LEFT, true);
                 });
                 if (reachable.isPresent())
                     return false;
@@ -158,9 +157,11 @@ public abstract class Movement implements Helper, MovementHelper {
     }
 
     /**
-     * Run cleanup on state finish
+     * Run cleanup on state finish and declare success.
      */
-    public abstract void onFinish();
+    public void onFinish(MovementState state) {
+        state.setStatus(MovementStatus.SUCCESS);
+    }
 
     /**
      * Calculate latest movement state.
@@ -172,7 +173,6 @@ public abstract class Movement implements Helper, MovementHelper {
         if (!prepared(state))
             return state.setStatus(MovementStatus.PREPPING);
         else if (state.getStatus() == MovementStatus.PREPPING) {
-            state.setInput(Input.CLICK_LEFT, false);
             state.setStatus(MovementStatus.WAITING);
         }
         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 46ae3ba5..bfc7fb23 100644
--- a/src/main/java/baritone/bot/pathing/movement/MovementState.java
+++ b/src/main/java/baritone/bot/pathing/movement/MovementState.java
@@ -58,8 +58,9 @@ public class MovementState {
         return target;
     }
 
-    public void setTarget(MovementTarget target) {
+    public MovementState setTarget(MovementTarget target) {
         this.target = target;
+        return this;
     }
 
     public MovementState setInput(Input input, boolean forced) {
@@ -72,6 +73,6 @@ public class MovementState {
     }
 
     public enum MovementStatus {
-        PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED;
+        PREPPING, WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED, FINISHING;
     }
 }