Refactoring

This commit is contained in:
Howard Stark 2018-08-02 23:40:27 -04:00
parent 1f9dadce39
commit f6f057c8cb
No known key found for this signature in database
GPG Key ID: 9FA4E350B33067F3
10 changed files with 34 additions and 24 deletions

View File

@ -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

View File

@ -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;

View File

@ -45,7 +45,7 @@ public abstract class Movement implements AbstractGameEventListener, Helper, Mov
@Override
public void onTick() {
MovementState latestState = calcState();
MovementState latestState = updateState();
Optional<Vec3d> orientation = latestState.getGoal().rotation;
if (orientation.isPresent()) {
Tuple<Float, Float> 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();
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -199,7 +199,7 @@ public abstract class Action {
}
/**
* Tick this action
* Tick this movement
*
* @return is it done
*/

View File

@ -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();

View File

@ -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;