it works
This commit is contained in:
parent
660efe5e16
commit
338fdb509a
@ -44,4 +44,6 @@ public interface IBaritoneProcess {
|
|||||||
double priority(); // tenor be like
|
double priority(); // tenor be like
|
||||||
|
|
||||||
IBaritone associatedWith(); // which bot is this associated with (5000000iq forward thinking)
|
IBaritone associatedWith(); // which bot is this associated with (5000000iq forward thinking)
|
||||||
|
|
||||||
|
String displayName();
|
||||||
}
|
}
|
||||||
|
@ -18,10 +18,12 @@
|
|||||||
package baritone.api.process;
|
package baritone.api.process;
|
||||||
|
|
||||||
public enum PathingCommandType {
|
public enum PathingCommandType {
|
||||||
SET_GOAL_AND_PATH, // if you do this one with a null goal it should continue
|
SET_GOAL_AND_PATH, // self explanatory, if you do this one with a null goal it should continue
|
||||||
REQUEST_PAUSE,
|
|
||||||
|
|
||||||
// if you do this one with a null goal it should cancel
|
REQUEST_PAUSE, // this one just pauses. it doesn't change the goal.
|
||||||
REVALIDATE_GOAL_AND_PATH, // idkkkkkkk
|
|
||||||
FORCE_REVALIDATE_GOAL_AND_PATH // idkkkkkkkkkkkkkkkkkkkkkkkk
|
CANCEL_AND_SET_GOAL, // cancel the current path, and set the goal (regardless of if it's null)
|
||||||
|
|
||||||
|
REVALIDATE_GOAL_AND_PATH, // set the goal, revalidate if cancelOnGoalInvalidation is true, then path. if the goal is null, it will cancel (but only if that setting is true)
|
||||||
|
FORCE_REVALIDATE_GOAL_AND_PATH // set the goal, revalidate current goal (cancel if no longer valid), cancel if the provided goal is null
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import baritone.api.BaritoneAPI;
|
|||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
import baritone.api.process.IBaritoneProcess;
|
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.behavior.LookBehavior;
|
import baritone.behavior.LookBehavior;
|
||||||
import baritone.behavior.MemoryBehavior;
|
import baritone.behavior.MemoryBehavior;
|
||||||
@ -114,8 +113,8 @@ public enum Baritone implements IBaritone {
|
|||||||
followProcess = new FollowProcess(this);
|
followProcess = new FollowProcess(this);
|
||||||
mineProcess = new MineProcess(this);
|
mineProcess = new MineProcess(this);
|
||||||
new ExampleBaritoneControl(this);
|
new ExampleBaritoneControl(this);
|
||||||
new CustomGoalProcess(this); // very high iq
|
customGoalProcess = new CustomGoalProcess(this); // very high iq
|
||||||
new GetToBlockProcess(this);
|
getToBlockProcess = new GetToBlockProcess(this);
|
||||||
}
|
}
|
||||||
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
|
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
|
||||||
registerEventListener(BaritoneAutoTest.INSTANCE);
|
registerEventListener(BaritoneAutoTest.INSTANCE);
|
||||||
@ -160,8 +159,12 @@ public enum Baritone implements IBaritone {
|
|||||||
this.registerEventListener(behavior);
|
this.registerEventListener(behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerProcess(IBaritoneProcess process) {
|
public CustomGoalProcess getCustomGoalProcess() {
|
||||||
|
return customGoalProcess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetToBlockProcess getGetToBlockProcess() { // very very high iq
|
||||||
|
return getToBlockProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,6 +52,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
private Goal goal;
|
private Goal goal;
|
||||||
|
|
||||||
|
private boolean safeToCancel;
|
||||||
|
private boolean pauseRequestedLastTick;
|
||||||
|
|
||||||
private volatile boolean isPathCalcInProgress;
|
private volatile boolean isPathCalcInProgress;
|
||||||
private final Object pathCalcLock = new Object();
|
private final Object pathCalcLock = new Object();
|
||||||
|
|
||||||
@ -81,7 +84,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
dispatchEvents();
|
dispatchEvents();
|
||||||
if (event.getType() == TickEvent.Type.OUT) {
|
if (event.getType() == TickEvent.Type.OUT) {
|
||||||
cancel();
|
secretInternalSegmentCancel();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tickPath();
|
tickPath();
|
||||||
@ -89,10 +92,17 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void tickPath() {
|
private void tickPath() {
|
||||||
|
baritone.getPathingControlManager().doTheThingWithTheStuff();
|
||||||
|
if (pauseRequestedLastTick && safeToCancel) {
|
||||||
|
pauseRequestedLastTick = false;
|
||||||
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
|
BlockBreakHelper.stopBreakingBlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean safe = current.onTick();
|
safeToCancel = current.onTick();
|
||||||
synchronized (pathPlanLock) {
|
synchronized (pathPlanLock) {
|
||||||
if (current.failed() || current.finished()) {
|
if (current.failed() || current.finished()) {
|
||||||
current = null;
|
current = null;
|
||||||
@ -134,7 +144,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// at this point, we know current is in progress
|
// at this point, we know current is in progress
|
||||||
if (safe && next != null && next.snipsnapifpossible()) {
|
if (safeToCancel && next != null && next.snipsnapifpossible()) {
|
||||||
// a movement just ended; jump directly onto the next path
|
// a movement just ended; jump directly onto the next path
|
||||||
logDebug("Splicing into planned next path early...");
|
logDebug("Splicing into planned next path early...");
|
||||||
queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
|
queuePathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY);
|
||||||
@ -191,13 +201,13 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition()));
|
return Optional.of(current.getPath().ticksRemainingFrom(current.getPosition()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGoal(Goal goal) {
|
public void secretInternalSetGoal(Goal goal) {
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean setGoalAndPath(Goal goal) {
|
public boolean secretInternalSetGoalAndPath(Goal goal) {
|
||||||
setGoal(goal);
|
secretInternalSetGoal(goal);
|
||||||
return path();
|
return secretInternalPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -225,22 +235,40 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
return this.current != null;
|
return this.current != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSafeToCancel() {
|
||||||
|
return current == null || safeToCancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void requestPause() {
|
||||||
|
pauseRequestedLastTick = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean cancelSegmentIfSafe() {
|
||||||
|
if (isSafeToCancel()) {
|
||||||
|
secretInternalSegmentCancel();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelEverything() {
|
public void cancelEverything() {
|
||||||
|
secretInternalSegmentCancel();
|
||||||
|
baritone.getPathingControlManager().cancelEverything();
|
||||||
}
|
}
|
||||||
|
|
||||||
// just cancel the current path
|
// just cancel the current path
|
||||||
public void cancel() {
|
public void secretInternalSegmentCancel() {
|
||||||
queuePathEvent(PathEvent.CANCELED);
|
queuePathEvent(PathEvent.CANCELED);
|
||||||
current = null;
|
current = null;
|
||||||
next = null;
|
next = null;
|
||||||
Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys();
|
baritone.getInputOverrideHandler().clearAllKeys();
|
||||||
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel);
|
AbstractNodeCostSearch.getCurrentlyRunning().ifPresent(AbstractNodeCostSearch::cancel);
|
||||||
BlockBreakHelper.stopBreakingBlock();
|
BlockBreakHelper.stopBreakingBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forceCancel() { // NOT exposed on public api
|
public void forceCancel() { // NOT exposed on public api
|
||||||
|
cancelEverything();
|
||||||
isPathCalcInProgress = false;
|
isPathCalcInProgress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +277,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
*
|
*
|
||||||
* @return true if this call started path calculation, false if it was already calculating or executing a path
|
* @return true if this call started path calculation, false if it was already calculating or executing a path
|
||||||
*/
|
*/
|
||||||
public boolean path() {
|
public boolean secretInternalPath() {
|
||||||
if (goal == null) {
|
if (goal == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,11 @@ import baritone.api.pathing.goals.Goal;
|
|||||||
import baritone.api.process.ICustomGoalProcess;
|
import baritone.api.process.ICustomGoalProcess;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.process.PathingCommandType;
|
import baritone.api.process.PathingCommandType;
|
||||||
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.utils.BaritoneProcessHelper;
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As set by ExampleBaritoneControl or something idk
|
* As set by ExampleBaritoneControl or something idk
|
||||||
*
|
*
|
||||||
@ -31,35 +34,72 @@ import baritone.utils.BaritoneProcessHelper;
|
|||||||
*/
|
*/
|
||||||
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
public class CustomGoalProcess extends BaritoneProcessHelper implements ICustomGoalProcess {
|
||||||
private Goal goal;
|
private Goal goal;
|
||||||
private boolean active;
|
private State state;
|
||||||
|
private int ticksExecuting;
|
||||||
|
|
||||||
public CustomGoalProcess(Baritone baritone) {
|
public CustomGoalProcess(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setGoal(Goal goal) {
|
public void setGoal(Goal goal) {
|
||||||
this.goal = goal;
|
this.goal = goal;
|
||||||
|
state = State.GOAL_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void path() {
|
public void path() {
|
||||||
active = true;
|
if (goal == null) {
|
||||||
|
goal = baritone.getPathingBehavior().getGoal();
|
||||||
|
}
|
||||||
|
state = State.PATH_REQUESTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum State {
|
||||||
|
NONE,
|
||||||
|
GOAL_SET,
|
||||||
|
PATH_REQUESTED,
|
||||||
|
EXECUTING,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isActive() {
|
public boolean isActive() {
|
||||||
return active;
|
return state != State.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PathingCommand onTick() {
|
public PathingCommand onTick() {
|
||||||
active = false; // only do this once
|
switch (state) {
|
||||||
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
case GOAL_SET:
|
||||||
|
if (!baritone.getPathingBehavior().isPathing() && Objects.equals(baritone.getPathingBehavior().getGoal(), goal)) {
|
||||||
|
state = State.NONE;
|
||||||
|
}
|
||||||
|
return new PathingCommand(goal, PathingCommandType.CANCEL_AND_SET_GOAL);
|
||||||
|
case PATH_REQUESTED:
|
||||||
|
PathingCommand ret = new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||||
|
state = State.EXECUTING;
|
||||||
|
ticksExecuting = 0;
|
||||||
|
return ret;
|
||||||
|
case EXECUTING:
|
||||||
|
if (ticksExecuting++ > 2 && !baritone.getPathingBehavior().isPathing() && !AbstractNodeCostSearch.getCurrentlyRunning().isPresent()) {
|
||||||
|
onLostControl();
|
||||||
|
}
|
||||||
|
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLostControl() {
|
public void onLostControl() {
|
||||||
active = false;
|
state = State.NONE;
|
||||||
|
goal = null;
|
||||||
|
ticksExecuting = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName() {
|
||||||
|
return "Custom Goal " + goal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,9 @@
|
|||||||
package baritone.process;
|
package baritone.process;
|
||||||
|
|
||||||
import baritone.Baritone;
|
import baritone.Baritone;
|
||||||
import baritone.api.process.IFollowProcess;
|
|
||||||
import baritone.api.pathing.goals.GoalNear;
|
import baritone.api.pathing.goals.GoalNear;
|
||||||
import baritone.api.pathing.goals.GoalXZ;
|
import baritone.api.pathing.goals.GoalXZ;
|
||||||
|
import baritone.api.process.IFollowProcess;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
import baritone.api.process.PathingCommandType;
|
import baritone.api.process.PathingCommandType;
|
||||||
import baritone.utils.BaritoneProcessHelper;
|
import baritone.utils.BaritoneProcessHelper;
|
||||||
@ -37,7 +37,7 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
|||||||
private Entity following;
|
private Entity following;
|
||||||
|
|
||||||
public FollowProcess(Baritone baritone) {
|
public FollowProcess(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -63,6 +63,11 @@ public final class FollowProcess extends BaritoneProcessHelper implements IFollo
|
|||||||
following = null;
|
following = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName() {
|
||||||
|
return "Follow " + following;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void follow(Entity entity) {
|
public void follow(Entity entity) {
|
||||||
this.following = entity;
|
this.following = entity;
|
||||||
|
@ -38,7 +38,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
int tickCount = 0;
|
int tickCount = 0;
|
||||||
|
|
||||||
public GetToBlockProcess(Baritone baritone) {
|
public GetToBlockProcess(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,6 +67,9 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
Baritone.INSTANCE.getExecutor().execute(this::rescan);
|
Baritone.INSTANCE.getExecutor().execute(this::rescan);
|
||||||
}
|
}
|
||||||
Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new));
|
Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new));
|
||||||
|
if (goal.isInGoal(playerFeet())) {
|
||||||
|
onLostControl();
|
||||||
|
}
|
||||||
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
return new PathingCommand(goal, PathingCommandType.SET_GOAL_AND_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +79,11 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
knownLocations = null;
|
knownLocations = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName() {
|
||||||
|
return "Get To Block " + gettingTo;
|
||||||
|
}
|
||||||
|
|
||||||
private void rescan() {
|
private void rescan() {
|
||||||
knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64);
|
knownLocations = MineProcess.searchWorld(Collections.singletonList(gettingTo), 64);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
private int tickCount;
|
private int tickCount;
|
||||||
|
|
||||||
public MineProcess(Baritone baritone) {
|
public MineProcess(Baritone baritone) {
|
||||||
super(baritone);
|
super(baritone, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -79,7 +79,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
}
|
}
|
||||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
||||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
||||||
Baritone.INSTANCE.getExecutor().execute(this::rescan);
|
baritone.getExecutor().execute(this::rescan);
|
||||||
}
|
}
|
||||||
if (Baritone.settings().legitMine.get()) {
|
if (Baritone.settings().legitMine.get()) {
|
||||||
addNearby();
|
addNearby();
|
||||||
@ -99,6 +99,11 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
mine(0, (Block[]) null);
|
mine(0, (Block[]) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String displayName() {
|
||||||
|
return "Mine " + mining;
|
||||||
|
}
|
||||||
|
|
||||||
private Goal updateGoal() {
|
private Goal updateGoal() {
|
||||||
List<BlockPos> locs = knownOreLocations;
|
List<BlockPos> locs = knownOreLocations;
|
||||||
if (!locs.isEmpty()) {
|
if (!locs.isEmpty()) {
|
||||||
@ -115,7 +120,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
|||||||
// only in non-Xray mode (aka legit mode) do we do this
|
// only in non-Xray mode (aka legit mode) do we do this
|
||||||
if (branchPoint == null) {
|
if (branchPoint == null) {
|
||||||
int y = Baritone.settings().legitMineYLevel.get();
|
int y = Baritone.settings().legitMineYLevel.get();
|
||||||
if (!associatedWith().getPathingBehavior().isPathing() && playerFeet().y == y) {
|
if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) {
|
||||||
// cool, path is over and we are at desired y
|
// cool, path is over and we are at desired y
|
||||||
branchPoint = playerFeet();
|
branchPoint = playerFeet();
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,8 +105,7 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup Baritone's pathing goal and (if needed) begin pathing
|
// Setup Baritone's pathing goal and (if needed) begin pathing
|
||||||
Baritone.INSTANCE.getPathingBehavior().setGoal(GOAL);
|
Baritone.INSTANCE.getCustomGoalProcess().setGoalAndPath(GOAL);
|
||||||
Baritone.INSTANCE.getPathingBehavior().path();
|
|
||||||
|
|
||||||
// If we have reached our goal, print a message and safely close the game
|
// If we have reached our goal, print a message and safely close the game
|
||||||
if (GOAL.isInGoal(playerFeet())) {
|
if (GOAL.isInGoal(playerFeet())) {
|
||||||
|
@ -23,7 +23,7 @@ import baritone.api.process.IBaritoneProcess;
|
|||||||
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
public abstract class BaritoneProcessHelper implements IBaritoneProcess, Helper {
|
||||||
public static final double DEFAULT_PRIORITY = 0;
|
public static final double DEFAULT_PRIORITY = 0;
|
||||||
|
|
||||||
private final Baritone baritone;
|
protected final Baritone baritone;
|
||||||
private final double priority;
|
private final double priority;
|
||||||
|
|
||||||
public BaritoneProcessHelper(Baritone baritone) {
|
public BaritoneProcessHelper(Baritone baritone) {
|
||||||
|
@ -33,6 +33,7 @@ import baritone.cache.WorldProvider;
|
|||||||
import baritone.pathing.calc.AbstractNodeCostSearch;
|
import baritone.pathing.calc.AbstractNodeCostSearch;
|
||||||
import baritone.pathing.movement.Movement;
|
import baritone.pathing.movement.Movement;
|
||||||
import baritone.pathing.movement.Moves;
|
import baritone.pathing.movement.Moves;
|
||||||
|
import baritone.process.CustomGoalProcess;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
import net.minecraft.client.multiplayer.ChunkProviderClient;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@ -99,6 +100,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
public boolean runCommand(String msg0) {
|
public boolean runCommand(String msg0) {
|
||||||
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
||||||
PathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
PathingBehavior pathingBehavior = baritone.getPathingBehavior();
|
||||||
|
PathingControlManager pathControl = baritone.getPathingControlManager();
|
||||||
|
CustomGoalProcess CGPgrey = baritone.getCustomGoalProcess();
|
||||||
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
||||||
for (Settings.Setting<Boolean> setting : toggleable) {
|
for (Settings.Setting<Boolean> setting : toggleable) {
|
||||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||||
@ -186,21 +189,19 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("unable to parse integer " + ex);
|
logDirect("unable to parse integer " + ex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
pathingBehavior.setGoal(goal);
|
CGPgrey.setGoal(goal);
|
||||||
logDirect("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("path")) {
|
if (msg.equals("path")) {
|
||||||
if (!pathingBehavior.path()) {
|
if (pathingBehavior.getGoal() == null) {
|
||||||
if (pathingBehavior.getGoal() == null) {
|
logDirect("No goal.");
|
||||||
logDirect("No goal.");
|
} else if (pathingBehavior.getGoal().isInGoal(playerFeet())) {
|
||||||
} else {
|
logDirect("Already in goal");
|
||||||
if (pathingBehavior.getGoal().isInGoal(playerFeet())) {
|
} else if (pathingBehavior.isPathing()) {
|
||||||
logDirect("Already in goal");
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
} else {
|
} else {
|
||||||
logDirect("Currently executing a path. Please cancel it first.");
|
CGPgrey.path();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -222,21 +223,20 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("axis")) {
|
if (msg.equals("axis")) {
|
||||||
pathingBehavior.setGoal(new GoalAxis());
|
CGPgrey.setGoalAndPath(new GoalAxis());
|
||||||
pathingBehavior.path();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("cancel") || msg.equals("stop")) {
|
if (msg.equals("cancel") || msg.equals("stop")) {
|
||||||
baritone.getMineProcess().cancel();
|
baritone.getMineProcess().cancel();
|
||||||
baritone.getFollowProcess().cancel();
|
baritone.getFollowProcess().cancel();
|
||||||
pathingBehavior.cancel();
|
pathingBehavior.cancelEverything();
|
||||||
logDirect("ok canceled");
|
logDirect("ok canceled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("forcecancel")) {
|
if (msg.equals("forcecancel")) {
|
||||||
baritone.getMineProcess().cancel();
|
baritone.getMineProcess().cancel();
|
||||||
baritone.getFollowProcess().cancel();
|
baritone.getFollowProcess().cancel();
|
||||||
pathingBehavior.cancel();
|
pathingBehavior.cancelEverything();
|
||||||
AbstractNodeCostSearch.forceCancel();
|
AbstractNodeCostSearch.forceCancel();
|
||||||
pathingBehavior.forceCancel();
|
pathingBehavior.forceCancel();
|
||||||
logDirect("ok force canceled");
|
logDirect("ok force canceled");
|
||||||
@ -259,15 +259,12 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Inverting goal of player feet");
|
logDirect("Inverting goal of player feet");
|
||||||
runAwayFrom = playerFeet();
|
runAwayFrom = playerFeet();
|
||||||
}
|
}
|
||||||
pathingBehavior.setGoal(new GoalRunAway(1, runAwayFrom) {
|
CGPgrey.setGoalAndPath(new GoalRunAway(1, runAwayFrom) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInGoal(int x, int y, int z) {
|
public boolean isInGoal(int x, int y, int z) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!pathingBehavior.path()) {
|
|
||||||
logDirect("Currently executing a path. Please cancel it first.");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.startsWith("follow")) {
|
if (msg.startsWith("follow")) {
|
||||||
@ -337,7 +334,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
if (msg.startsWith("thisway")) {
|
if (msg.startsWith("thisway")) {
|
||||||
try {
|
try {
|
||||||
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
||||||
pathingBehavior.setGoal(goal);
|
CGPgrey.setGoal(goal);
|
||||||
logDirect("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double.");
|
logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double.");
|
||||||
@ -406,13 +403,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<BlockPos> locs = baritone.getMineProcess().searchWorld(Collections.singletonList(block), 64);
|
baritone.getGetToBlockProcess().getToBlock(block);
|
||||||
if (locs.isEmpty()) {
|
|
||||||
logDirect("No locations for " + mining + " known, cancelling");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
pathingBehavior.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
|
||||||
pathingBehavior.path();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -423,10 +414,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
||||||
pathingBehavior.setGoal(goal);
|
CGPgrey.setGoalAndPath(goal);
|
||||||
if (!pathingBehavior.path() && !goal.isInGoal(playerFeet())) {
|
|
||||||
logDirect("Currently executing a path. Please cancel it first.");
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("spawn") || msg.equals("bed")) {
|
if (msg.equals("spawn") || msg.equals("bed")) {
|
||||||
@ -436,10 +424,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
// for some reason the default spawnpoint is underground sometimes
|
// for some reason the default spawnpoint is underground sometimes
|
||||||
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
||||||
logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
||||||
pathingBehavior.setGoal(goal);
|
CGPgrey.setGoalAndPath(goal);
|
||||||
} else {
|
} else {
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = new GoalGetToBlock(waypoint.getLocation());
|
||||||
pathingBehavior.setGoal(goal);
|
CGPgrey.setGoalAndPath(goal);
|
||||||
logDirect("Set goal to most recent bed " + goal);
|
logDirect("Set goal to most recent bed " + goal);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -455,8 +443,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("home not saved");
|
logDirect("home not saved");
|
||||||
} else {
|
} else {
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
||||||
pathingBehavior.setGoal(goal);
|
CGPgrey.setGoalAndPath(goal);
|
||||||
pathingBehavior.path();
|
|
||||||
logDirect("Going to saved home " + goal);
|
logDirect("Going to saved home " + goal);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,6 +21,7 @@ import baritone.Baritone;
|
|||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.process.IBaritoneProcess;
|
import baritone.api.process.IBaritoneProcess;
|
||||||
import baritone.api.process.PathingCommand;
|
import baritone.api.process.PathingCommand;
|
||||||
|
import baritone.behavior.PathingBehavior;
|
||||||
import baritone.pathing.path.PathExecutor;
|
import baritone.pathing.path.PathExecutor;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
@ -39,43 +40,51 @@ public class PathingControlManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerProcess(IBaritoneProcess process) {
|
public void registerProcess(IBaritoneProcess process) {
|
||||||
|
process.onLostControl(); // make sure it's reset
|
||||||
processes.add(process);
|
processes.add(process);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cancelEverything() {
|
||||||
|
for (IBaritoneProcess proc : processes) {
|
||||||
|
proc.onLostControl();
|
||||||
|
if (proc.isActive() && !proc.isTemporary()) { // it's okay for a temporary thing (like combat pause) to maintain control even if you say to cancel
|
||||||
|
// but not for a non temporary thing
|
||||||
|
throw new IllegalStateException(proc.displayName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void doTheThingWithTheStuff() {
|
public void doTheThingWithTheStuff() {
|
||||||
PathingCommand cmd = doTheStuff();
|
PathingCommand cmd = doTheStuff();
|
||||||
if (cmd == null) {
|
if (cmd == null) {
|
||||||
baritone.getPathingBehavior().cancel();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
PathingBehavior p = baritone.getPathingBehavior();
|
||||||
switch (cmd.commandType) {
|
switch (cmd.commandType) {
|
||||||
case REQUEST_PAUSE:
|
case REQUEST_PAUSE:
|
||||||
// idk
|
p.requestPause();
|
||||||
// ask pathingbehavior if its safe
|
break;
|
||||||
|
case CANCEL_AND_SET_GOAL:
|
||||||
|
p.secretInternalSetGoal(cmd.goal);
|
||||||
|
p.cancelSegmentIfSafe();
|
||||||
|
break;
|
||||||
case FORCE_REVALIDATE_GOAL_AND_PATH:
|
case FORCE_REVALIDATE_GOAL_AND_PATH:
|
||||||
if (cmd.goal == null) {
|
p.secretInternalSetGoalAndPath(cmd.goal);
|
||||||
baritone.getPathingBehavior().cancel(); // todo only if its safe
|
if (cmd.goal == null || revalidateGoal(cmd.goal)) {
|
||||||
return;
|
// pwnage
|
||||||
}
|
p.cancelSegmentIfSafe();
|
||||||
// pwnage
|
|
||||||
baritone.getPathingBehavior().setGoal(cmd.goal);
|
|
||||||
if (revalidateGoal(cmd.goal)) {
|
|
||||||
baritone.getPathingBehavior().cancel(); // todo only if its safe
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case REVALIDATE_GOAL_AND_PATH:
|
case REVALIDATE_GOAL_AND_PATH:
|
||||||
if (cmd.goal == null) {
|
p.secretInternalSetGoalAndPath(cmd.goal);
|
||||||
baritone.getPathingBehavior().cancel(); // todo only if its safe
|
if (Baritone.settings().cancelOnGoalInvalidation.get() && (cmd.goal == null || revalidateGoal(cmd.goal))) {
|
||||||
return;
|
p.cancelSegmentIfSafe();
|
||||||
}
|
|
||||||
baritone.getPathingBehavior().setGoal(cmd.goal);
|
|
||||||
if (Baritone.settings().cancelOnGoalInvalidation.get() && revalidateGoal(cmd.goal)) {
|
|
||||||
baritone.getPathingBehavior().cancel(); // todo only if its safe
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case SET_GOAL_AND_PATH:
|
case SET_GOAL_AND_PATH:
|
||||||
// now this i can do
|
// now this i can do
|
||||||
if (cmd.goal != null) {
|
if (cmd.goal != null) {
|
||||||
baritone.getPathingBehavior().setGoalAndPath(cmd.goal);
|
baritone.getPathingBehavior().secretInternalSetGoalAndPath(cmd.goal);
|
||||||
}
|
}
|
||||||
// breaks are for wusses!!!!
|
// breaks are for wusses!!!!
|
||||||
}
|
}
|
||||||
@ -111,11 +120,12 @@ public class PathingControlManager {
|
|||||||
exec = proc.onTick();
|
exec = proc.onTick();
|
||||||
if (exec == null) {
|
if (exec == null) {
|
||||||
if (proc.isActive()) {
|
if (proc.isActive()) {
|
||||||
throw new IllegalStateException(proc + "");
|
throw new IllegalStateException(proc.displayName());
|
||||||
}
|
}
|
||||||
proc.onLostControl();
|
proc.onLostControl();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
System.out.println("Executing command " + exec.commandType + " " + exec.goal + " from " + proc.displayName());
|
||||||
found = true;
|
found = true;
|
||||||
cancelOthers = !proc.isTemporary();
|
cancelOthers = !proc.isTemporary();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user