Add features to Action scaffolding
This commit is contained in:
parent
cb238ec130
commit
f0488b24dd
@ -1,29 +1,31 @@
|
||||
package baritone.bot.pathing.actions;
|
||||
package baritone.bot.pathing.action;
|
||||
|
||||
import baritone.bot.Baritone;
|
||||
import baritone.bot.behavior.Behavior;
|
||||
import baritone.bot.utils.Utils;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import baritone.bot.pathing.action.ActionState.ActionStatus;
|
||||
|
||||
public abstract class Action extends Behavior {
|
||||
|
||||
protected ActionState currentState;
|
||||
|
||||
Action(BlockPos dest) {
|
||||
public Action(BlockPos dest) {
|
||||
BlockPos playerEyePos = new BlockPos(player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||
Tuple<Float, Float> desiredRotation = Utils.calcRotationFromCoords(
|
||||
Utils.calcCenterFromCoords(dest, world),
|
||||
playerEyePos);
|
||||
|
||||
// There's honestly not a good reason for this (Builder Pattern), I just believed strongly in it
|
||||
currentState = new ActionState().setDesiredMovement(dest)
|
||||
.setDesiredLook(desiredRotation)
|
||||
.setFinished(false);
|
||||
currentState = new ActionState()
|
||||
.setGoal(new ActionState.ActionGoal(dest, desiredRotation))
|
||||
.setStatus(ActionStatus.WAITING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lowest denominator of the dynamic costs.
|
||||
* TODO: Investigate performant ways to assign costs to actions
|
||||
* TODO: Investigate performant ways to assign costs to action
|
||||
*
|
||||
* @return Cost
|
||||
*/
|
||||
@ -32,9 +34,20 @@ public abstract class Action extends Behavior {
|
||||
@Override
|
||||
public void onTick() {
|
||||
ActionState latestState = calcState();
|
||||
currentState = latestState;
|
||||
player.setPositionAndRotation(player.posX, player.posY, player.posZ,
|
||||
latestState.desiredRotation.getFirst(), latestState.desiredRotation.getSecond());
|
||||
latestState.getGoal().rotation.getFirst(), latestState.getGoal().rotation.getSecond());
|
||||
latestState.inputState.forEach((input, forced) -> {
|
||||
Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced);
|
||||
});
|
||||
currentState = latestState;
|
||||
|
||||
if(isFinished())
|
||||
return;
|
||||
}
|
||||
|
||||
public boolean isFinished() {
|
||||
return(currentState.getStatus() != ActionStatus.RUNNING
|
||||
&& currentState.getStatus() != ActionStatus.WAITING);
|
||||
}
|
||||
|
||||
/**
|
@ -1,4 +1,4 @@
|
||||
package baritone.bot.pathing.actions;
|
||||
package baritone.bot.pathing.action;
|
||||
|
||||
public interface ActionCosts {
|
||||
/**
|
63
src/main/java/baritone/bot/pathing/action/ActionState.java
Normal file
63
src/main/java/baritone/bot/pathing/action/ActionState.java
Normal file
@ -0,0 +1,63 @@
|
||||
package baritone.bot.pathing.action;
|
||||
|
||||
import baritone.bot.InputOverrideHandler.Input;
|
||||
import baritone.bot.utils.DefaultHashMap;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ActionState {
|
||||
|
||||
protected ActionStatus status;
|
||||
public ActionGoal goal;
|
||||
protected final Map<Input, Boolean> inputState = new DefaultHashMap<>(false);
|
||||
|
||||
public ActionState setStatus(ActionStatus status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActionStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public static class ActionGoal {
|
||||
/**
|
||||
* Necessary movement to achieve
|
||||
* <p>
|
||||
* TODO: Decide desiredMovement type
|
||||
*/
|
||||
protected BlockPos position;
|
||||
/**
|
||||
* Yaw and pitch angles that must be matched
|
||||
* <p>
|
||||
* getFirst() -> YAW
|
||||
* getSecond() -> PITCH
|
||||
*/
|
||||
protected Tuple<Float, Float> rotation;
|
||||
|
||||
public ActionGoal(BlockPos position, Tuple<Float, Float> rotation) {
|
||||
this.position = position;
|
||||
this.rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
public ActionGoal getGoal() {
|
||||
return goal;
|
||||
}
|
||||
|
||||
public ActionState setGoal(ActionGoal goal) {
|
||||
this.goal = goal;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ActionState setInput(Input input, boolean forced) {
|
||||
this.inputState.put(input, forced);
|
||||
return this;
|
||||
}
|
||||
|
||||
public enum ActionStatus {
|
||||
WAITING, RUNNING, SUCCESS, UNREACHABLE, FAILED;
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
package baritone.bot.pathing.actions;
|
||||
package baritone.bot.pathing.action.actions;
|
||||
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import baritone.bot.pathing.action.Action;
|
||||
import baritone.bot.pathing.action.ActionState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ActionAscend extends Action {
|
||||
|
||||
ActionAscend(BlockPos dest) {
|
@ -1,54 +0,0 @@
|
||||
package baritone.bot.pathing.actions;
|
||||
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class ActionState {
|
||||
|
||||
/**
|
||||
* Is Action finished?
|
||||
*/
|
||||
protected boolean finished;
|
||||
|
||||
public boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
public ActionState setFinished(boolean finished) {
|
||||
this.finished = finished;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Necessary movement to achieve
|
||||
*
|
||||
* TODO: Decide desiredMovement type
|
||||
*/
|
||||
protected BlockPos desiredMovement;
|
||||
|
||||
public BlockPos getDesiredMovement() {
|
||||
return desiredMovement;
|
||||
}
|
||||
|
||||
public ActionState setDesiredMovement(BlockPos desiredMovement) {
|
||||
this.desiredMovement = desiredMovement;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Yaw and pitch angles that must be matched
|
||||
*
|
||||
* getFirst() -> YAW
|
||||
* getSecond() -> PITCH
|
||||
*/
|
||||
protected Tuple<Float, Float> desiredRotation;
|
||||
|
||||
public Tuple<Float, Float> getDesiredRotation() {
|
||||
return desiredRotation;
|
||||
}
|
||||
|
||||
public ActionState setDesiredLook(Tuple<Float, Float> desiredRotation) {
|
||||
this.desiredRotation = desiredRotation;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package baritone.bot.pathing.goals;
|
||||
|
||||
import baritone.bot.pathing.actions.ActionCosts;
|
||||
import baritone.bot.pathing.action.ActionCosts;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
package baritone.bot.pathing.movements;
|
||||
|
||||
import baritone.bot.pathing.actions.Action;
|
||||
import baritone.bot.pathing.action.Action;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.List;
|
||||
@ -8,7 +8,7 @@ import java.util.List;
|
||||
public abstract class Movement {
|
||||
|
||||
/**
|
||||
* Flat list of ordered actions
|
||||
* Flat list of ordered action
|
||||
*/
|
||||
protected List<Action> actions;
|
||||
|
||||
|
@ -3,10 +3,13 @@ package baritone.bot.utils;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DefaultHashMap<K, V> extends HashMap<K, V> {
|
||||
|
||||
protected V defaultValue;
|
||||
|
||||
public DefaultHashMap(V defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public V get(Object k) {
|
||||
return containsKey(k) ? super.get(k) : defaultValue;
|
||||
|
@ -57,7 +57,7 @@ public class Path {
|
||||
}
|
||||
path.add(0, start.pos);
|
||||
/*Out.log("Final path: " + path);
|
||||
Out.log("Final actions: " + actions);
|
||||
Out.log("Final action: " + action);
|
||||
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(actions.get(i) + ": " + xDiff + "," + yDiff + "," + zDiff);//print it all out
|
||||
Out.log(action.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 actions list
|
||||
* Where are we in the path? This is an index in the action list
|
||||
*/
|
||||
int pathPosition = 0;
|
||||
|
||||
@ -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 actions are not parallel, so this is a right angle
|
||||
if (curr.dx() != next.dx() || curr.dz() != next.dz()) {//two action 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();
|
||||
|
@ -97,7 +97,7 @@ public class PathFinder {
|
||||
return new Path(startNode, currentNode, goal, numNodes);
|
||||
}
|
||||
//long constructStart = System.nanoTime();
|
||||
Action[] possibleActions = getConnectedPositions(currentNodePos);//actions that we could take that start at myPos, in random order
|
||||
Action[] possibleActions = getConnectedPositions(currentNodePos);//action that we could take that start at myPos, in random order
|
||||
shuffle(possibleActions);
|
||||
//long constructEnd = System.nanoTime();
|
||||
//System.out.println(constructEnd - constructStart);
|
||||
|
Loading…
Reference in New Issue
Block a user