Massive brain
This commit is contained in:
parent
ebd3ce42d0
commit
99da815f49
@ -21,12 +21,30 @@ import baritone.api.pathing.goals.Goal;
|
|||||||
|
|
||||||
public interface ICustomGoalProcess extends IBaritoneProcess {
|
public interface ICustomGoalProcess extends IBaritoneProcess {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the pathing goal
|
||||||
|
*
|
||||||
|
* @param goal The new goal
|
||||||
|
*/
|
||||||
void setGoal(Goal goal);
|
void setGoal(Goal goal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts path calculation and execution.
|
||||||
|
*/
|
||||||
void path();
|
void path();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The current goal
|
||||||
|
*/
|
||||||
|
Goal getGoal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the goal and begins the path execution.
|
||||||
|
*
|
||||||
|
* @param goal The new goal
|
||||||
|
*/
|
||||||
default void setGoalAndPath(Goal goal) {
|
default void setGoalAndPath(Goal goal) {
|
||||||
setGoal(goal);
|
this.setGoal(goal);
|
||||||
path();
|
this.path();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,17 @@ import java.util.Objects;
|
|||||||
* @author leijurv
|
* @author leijurv
|
||||||
*/
|
*/
|
||||||
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current goal
|
||||||
|
*/
|
||||||
private Goal goal;
|
private Goal goal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current process state.
|
||||||
|
*
|
||||||
|
* @see State
|
||||||
|
*/
|
||||||
private State state;
|
private State state;
|
||||||
|
|
||||||
public CustomGoalProcess(Baritone baritone) {
|
public CustomGoalProcess(Baritone baritone) {
|
||||||
@ -42,50 +52,47 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
|||||||
@Override
|
@Override
|
||||||
public void setGoal(Goal goal) {
|
public void setGoal(Goal goal) {
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
state = State.GOAL_SET;
|
this.state = State.GOAL_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void path() {
|
public void path() {
|
||||||
if (goal == null) {
|
if (this.goal == null) {
|
||||||
goal = baritone.getPathingBehavior().getGoal();
|
this.goal = baritone.getPathingBehavior().getGoal();
|
||||||
}
|
}
|
||||||
state = State.PATH_REQUESTED;
|
this.state = State.PATH_REQUESTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum State {
|
@Override
|
||||||
NONE,
|
public Goal getGoal() {
|
||||||
GOAL_SET,
|
return this.goal;
|
||||||
PATH_REQUESTED,
|
|
||||||
EXECUTING,
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return state != State.NONE;
|
return this.state != State.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||||
switch (state) {
|
switch (this.state) {
|
||||||
case GOAL_SET:
|
case GOAL_SET:
|
||||||
if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), goal)) {
|
if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), this.goal)) {
|
||||||
state = State.NONE;
|
this.state = State.NONE;
|
||||||
}
|
}
|
||||||
return new PathingCommand(goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||||
case PATH_REQUESTED:
|
case PATH_REQUESTED:
|
||||||
PathingCommand ret = new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
PathingCommand ret = new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||||
state = State.EXECUTING;
|
this.state = State.EXECUTING;
|
||||||
return ret;
|
return ret;
|
||||||
case EXECUTING:
|
case EXECUTING:
|
||||||
if (calcFailed) {
|
if (calcFailed) {
|
||||||
onLostControl();
|
onLostControl();
|
||||||
}
|
}
|
||||||
if (goal == null || goal.isInGoal(playerFeet())) {
|
if (this.goal == null || this.goal.isInGoal(playerFeet())) {
|
||||||
onLostControl(); // we're there xd
|
onLostControl(); // we're there xd
|
||||||
}
|
}
|
||||||
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
return new PathingCommand(this.goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
@ -93,12 +100,19 @@ public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomG
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLostControl() {
|
public void onLostControl() {
|
||||||
state = State.NONE;
|
this.state = State.NONE;
|
||||||
goal = null;
|
this.goal = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String displayName() {
|
public String displayName() {
|
||||||
return "Custom Goal " + goal;
|
return "Custom Goal " + this.goal;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected enum State {
|
||||||
|
NONE,
|
||||||
|
GOAL_SET,
|
||||||
|
PATH_REQUESTED,
|
||||||
|
EXECUTING
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user