From f6f057c8cb7cc52511afa9785363bf3b38cc8659 Mon Sep 17 00:00:00 2001 From: Howard Stark Date: Thu, 2 Aug 2018 23:40:27 -0400 Subject: [PATCH] Refactoring --- .../bot/event/events/type/EventState.java | 4 ++-- .../java/baritone/bot/pathing/calc/Path.java | 4 ++++ .../bot/pathing/movement/Movement.java | 10 ++++++++-- .../movement/movements/MovementAscend.java | 2 +- src/main/resources/baritone/Baritone.java | 2 +- .../resources/baritone/pathfinding/Path.java | 18 +++++++++--------- .../baritone/pathfinding/PathFinder.java | 2 +- .../baritone/pathfinding/actions/Action.java | 2 +- .../actions/ActionPlaceOrBreak.java | 6 +++--- .../resources/baritone/ui/LookManager.java | 8 ++++---- 10 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/main/java/baritone/bot/event/events/type/EventState.java b/src/main/java/baritone/bot/event/events/type/EventState.java index f8090edb..9c7b60eb 100644 --- a/src/main/java/baritone/bot/event/events/type/EventState.java +++ b/src/main/java/baritone/bot/event/events/type/EventState.java @@ -7,13 +7,13 @@ package baritone.bot.event.events.type; public enum EventState { /** - * Indicates that whatever action the event is being + * Indicates that whatever movement the event is being * dispatched as a result of is about to occur. */ PRE, /** - * Indicates that whatever action the event is being + * Indicates that whatever movement the event is being * dispatched as a result of has already occured. */ POST diff --git a/src/main/java/baritone/bot/pathing/calc/Path.java b/src/main/java/baritone/bot/pathing/calc/Path.java index 2fd71cb3..20a0aeac 100644 --- a/src/main/java/baritone/bot/pathing/calc/Path.java +++ b/src/main/java/baritone/bot/pathing/calc/Path.java @@ -1,5 +1,9 @@ package baritone.bot.pathing.calc; +<<<<<<< Updated upstream +======= +import baritone.bot.pathing.movement.Movement; +>>>>>>> Stashed changes import baritone.bot.pathing.goals.Goal; import baritone.bot.pathing.movement.Movement; import net.minecraft.util.math.BlockPos; diff --git a/src/main/java/baritone/bot/pathing/movement/Movement.java b/src/main/java/baritone/bot/pathing/movement/Movement.java index 5e9bc3bd..a7021207 100644 --- a/src/main/java/baritone/bot/pathing/movement/Movement.java +++ b/src/main/java/baritone/bot/pathing/movement/Movement.java @@ -45,7 +45,7 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov @Override public void onTick() { - MovementState latestState = calcState(); + MovementState latestState = updateState(); Optional orientation = latestState.getGoal().rotation; if (orientation.isPresent()) { Tuple rotation = Utils.calcRotationFromVec3d(mc.player.getPositionEyes(1.0F), @@ -60,6 +60,7 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov currentState = latestState; if (isFinished()) + onFinish(); return; } @@ -76,11 +77,16 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov return dest; } + /** + * Run cleanup on state finish + */ + public abstract void onFinish(); + /** * Calculate latest movement state. * Gets called once a tick. * * @return */ - public abstract MovementState calcState(); + public abstract MovementState updateState(); } diff --git a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java index 126b8931..7ca7cc67 100644 --- a/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java +++ b/src/main/java/baritone/bot/pathing/movement/movements/MovementAscend.java @@ -18,7 +18,7 @@ public class MovementAscend extends Movement { } @Override - public MovementState calcState() { + public MovementState updateState() { MovementState latestState = currentState.setInput(InputOverrideHandler.Input.JUMP, true).setInput(InputOverrideHandler.Input.MOVE_FORWARD, true); if (playerFeet().equals(dest)) latestState.setStatus(MovementState.MovementStatus.SUCCESS); diff --git a/src/main/resources/baritone/Baritone.java b/src/main/resources/baritone/Baritone.java index 020db3f6..4e11745e 100644 --- a/src/main/resources/baritone/Baritone.java +++ b/src/main/resources/baritone/Baritone.java @@ -191,7 +191,7 @@ public class Baritone { } } else { if (Action.isWater(theWorld.getBlockState(playerFeet).getBlock())) { - //if (Action.isWater(theWorld.getBlockState(playerFeet.down()).getBlock()) || !Action.canWalkOn(playerFeet.down()) || Action.isWater(theWorld.getBlockState(playerFeet.up()).getBlock())) { + //if (Movement.isWater(theWorld.getBlockState(playerFeet.down()).getBlock()) || !Movement.canWalkOn(playerFeet.down()) || Movement.isWater(theWorld.getBlockState(playerFeet.up()).getBlock())) { //if water is deeper than one block, or we can't walk on what's below the water, or our head is in water, jump Out.log("Jumping because in water"); MovementManager.jumping = true; diff --git a/src/main/resources/baritone/pathfinding/Path.java b/src/main/resources/baritone/pathfinding/Path.java index 46291b03..07c3383f 100644 --- a/src/main/resources/baritone/pathfinding/Path.java +++ b/src/main/resources/baritone/pathfinding/Path.java @@ -57,7 +57,7 @@ public class Path { } path.add(0, start.pos); /*Out.log("Final path: " + path); - Out.log("Final action: " + action); + Out.log("Final movement: " + movement); for (int i = 0; i < path.size() - 1; i++) {//print it all out int oldX = path.get(i).getX(); int oldY = path.get(i).getY(); @@ -68,7 +68,7 @@ public class Path { int xDiff = newX - oldX; int yDiff = newY - oldY; int zDiff = newZ - oldZ; - Out.log(action.get(i) + ": " + xDiff + "," + yDiff + "," + zDiff);//print it all out + Out.log(movement.get(i) + ": " + xDiff + "," + yDiff + "," + zDiff);//print it all out }*/ } @@ -96,7 +96,7 @@ public class Path { } } /** - * Where are we in the path? This is an index in the action list + * Where are we in the path? This is an index in the movement list */ int pathPosition = 0; @@ -141,12 +141,12 @@ public class Path { */ static final int MAX_TICKS_AWAY = 20 * 10; /** - * How many ticks have elapsed on this action + * How many ticks have elapsed on this movement */ int ticksOnCurrent = 0; /** * Did I fail, either by being too far away for too long, or by having an - * action take too long + * movement take too long */ public boolean failed = false; @@ -201,7 +201,7 @@ public class Path { if ((actions.get(pathPosition) instanceof ActionBridge) && (actions.get(pathPosition + 1) instanceof ActionBridge)) { ActionBridge curr = (ActionBridge) actions.get(pathPosition); ActionBridge next = (ActionBridge) actions.get(pathPosition + 1); - if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two action are not parallel, so this is a right angle + if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two movement are not parallel, so this is a right angle if (curr.amIGood() && next.amIGood()) {//nothing in the way BlockPos cornerToCut1 = new BlockPos(next.to.getX() - next.from.getX() + curr.from.getX(), next.to.getY(), next.to.getZ() - next.from.getZ() + curr.from.getZ()); BlockPos cornerToCut2 = cornerToCut1.up(); @@ -230,19 +230,19 @@ public class Path { MovementManager.clearMovement(); Action action = actions.get(pathPosition); if (action.calculateCost0(new ToolSet()) >= Action.COST_INF) { - Out.gui("Something has changed in the world and this action has become impossible. Cancelling.", Out.Mode.Standard); + Out.gui("Something has changed in the world and this movement has become impossible. Cancelling.", Out.Mode.Standard); pathPosition = path.size() + 3; failed = true; return true; } if (action.tick()) { - Out.log("Action done, next path"); + Out.log("Movement done, next path"); pathPosition++; ticksOnCurrent = 0; } else { ticksOnCurrent++; if (ticksOnCurrent > action.cost(null) + 100) { - Out.gui("This action has taken too long (" + ticksOnCurrent + " ticks, expected " + action.cost(null) + "). Cancelling.", Out.Mode.Standard); + Out.gui("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + action.cost(null) + "). Cancelling.", Out.Mode.Standard); pathPosition = path.size() + 3; failed = true; return true; diff --git a/src/main/resources/baritone/pathfinding/PathFinder.java b/src/main/resources/baritone/pathfinding/PathFinder.java index 0d2ba85f..a8c5a72e 100644 --- a/src/main/resources/baritone/pathfinding/PathFinder.java +++ b/src/main/resources/baritone/pathfinding/PathFinder.java @@ -97,7 +97,7 @@ public class PathFinder { return new Path(startNode, currentNode, goal, numNodes); } //long constructStart = System.nanoTime(); - Action[] possibleActions = getConnectedPositions(currentNodePos);//action that we could take that start at myPos, in random order + Action[] possibleActions = getConnectedPositions(currentNodePos);//movement that we could take that start at myPos, in random order shuffle(possibleActions); //long constructEnd = System.nanoTime(); //System.out.println(constructEnd - constructStart); diff --git a/src/main/resources/baritone/pathfinding/actions/Action.java b/src/main/resources/baritone/pathfinding/actions/Action.java index 0b17aa15..eddcb2b5 100644 --- a/src/main/resources/baritone/pathfinding/actions/Action.java +++ b/src/main/resources/baritone/pathfinding/actions/Action.java @@ -199,7 +199,7 @@ public abstract class Action { } /** - * Tick this action + * Tick this movement * * @return is it done */ diff --git a/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java b/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java index 37ddc04c..dad30aee 100644 --- a/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java +++ b/src/main/resources/baritone/pathfinding/actions/ActionPlaceOrBreak.java @@ -26,7 +26,7 @@ import net.minecraft.util.math.BlockPos; */ public abstract class ActionPlaceOrBreak extends Action { - public final BlockPos[] positionsToBreak;//the positions that need to be broken before this action can ensue + public final BlockPos[] positionsToBreak;//the positions that need to be broken before this movement can ensue public final BlockPos[] positionsToPlace;//the positions where we need to place a block before this aciton can ensue public final Block[] blocksToBreak;//the blocks at those positions public final Block[] blocksToPlace; @@ -45,7 +45,7 @@ public abstract class ActionPlaceOrBreak extends Action { } } - public double getTotalHardnessOfBlocksToBreak() {//of all the blocks we need to break before starting this action, what's the sum of how hard they are (phrasing) + public double getTotalHardnessOfBlocksToBreak() {//of all the blocks we need to break before starting this movement, what's the sum of how hard they are (phrasing) ToolSet ts = new ToolSet(); return this.getTotalHardnessOfBlocksToBreak(ts); } @@ -148,7 +148,7 @@ public abstract class ActionPlaceOrBreak extends Action { //one of the blocks that needs to be there isn't there //so basically someone mined out our path from under us // - //this doesn't really do anything, because all the cases for positionToPlace are handled in their respective action tick0s (e.g. pillar and bridge) + //this doesn't really do anything, because all the cases for positionToPlace are handled in their respective movement tick0s (e.g. pillar and bridge) } } return tick0(); diff --git a/src/main/resources/baritone/ui/LookManager.java b/src/main/resources/baritone/ui/LookManager.java index 17c9cada..ff2b09ef 100644 --- a/src/main/resources/baritone/ui/LookManager.java +++ b/src/main/resources/baritone/ui/LookManager.java @@ -33,24 +33,24 @@ public class LookManager extends Manager { static float desiredNextYaw = 0; static float desiredNextPitch = 0; /** - * The desired yaw, as set by whatever action is happening. Remember to also + * The desired yaw, as set by whatever movement is happening. Remember to also * set lookingYaw to true if you really want the yaw to change * */ static float desiredYaw; /** - * The desired pitch, as set by whatever action is happening. Remember to + * The desired pitch, as set by whatever movement is happening. Remember to * also set lookingPitch to true if you really want the yaw to change * */ static float desiredPitch; /** - * Set to true if the action wants the player's yaw to be moved towards + * Set to true if the movement wants the player's yaw to be moved towards * desiredYaw */ static boolean lookingYaw = false; /** - * Set to true if the action wants the player's pitch to be moved towards + * Set to true if the movement wants the player's pitch to be moved towards * desiredPitch */ static boolean lookingPitch = false;