-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Patrol Command and Goal #3904
Conversation
public boolean isInGoal(int x, int y, int z) { | ||
boolean inGoal = waypoints.get(index).isInGoal(x, y, z); | ||
BlockPos playerPos = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().playerFeet(); | ||
if (playerPos.getX() == x && playerPos.getY() == y && playerPos.getZ() == z) { | ||
if (inGoal) { | ||
return getNextOrReturnTrue(); | ||
} | ||
return false; | ||
} else { | ||
return inGoal; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know (at least now, 27 minutes after submitting my previous review. Please forgive me) this pr is a draft, but since this is a pretty fundamental structural problem with this approach to patrolling I'll write it anyway.
If you want a changing goal you need some process to run the logic, both because goals are assumed to be stateless and because making them depend on game state like this can cause threading and performance problems.
Fix completed event status for arriving with goto. Add a process that wraps a command queue that sends the next when it gets the completed event from the current child process. That sound about right for what the structure should be @ZacSharp |
Can you elaborate on this a bit more please? |
so i phrased it in a way to implement it wider with the long ask for task queue. for this we would have to have a new term child process for this new task aggregator process in order to have it wrap the process that's performing the current task in order to know when it. And patrol would be an example of something the task aggregator could do by queueing multiple goto's |
I don't think this is the right approach either. Commands and processes aren't the right abstraction to create a state machine. It would need to be a new class I think. Processes aren't meant to contain each other and they don't reasonably have duration, and commands having duration is also weird. A command isn't a flexible enough interface to create a good state machine, you want to be able to pass in arbitrary classes (such as other states) rather than just strings. Setting a wait in CustomGoalProcess breaks down the abstraction in an icky way. Let me give an example from an internal spawnmason project, which uses a state machine to implement gringotts. Each state can return either a new state, or a The wait state would have this as equivalent:
Here are some more examples of states:
In that last one you can see interesting behavior such as passing
Would be cool to add something like this to upstream baritone :) The actual implementation is very simple:
|
A comment that ended up being my pen and paper for sorting my thoughts. Might contain inconsistencies and whatever. Not all of it reflects my current opinion anymore, but it would be a shame to just delete it. You don't need to read it.I think we can do two things here
Also I hate markdown for it's poor nestability. Why can't I just have a list in a spoiler in a list and still use The short version is: I don't think we need a new execution system for command queues but rather a means of executing commands "within a context", meaning that commands shouldn't go and set some global state to make Baritone do some thing. Instead they should return an object that, when executed by some means, makes Baritone do the thing. That way there's the clear caller -> callee relationship needed to have the command queue take care of it's children properly. Based on the current process system it could look like this// the object would be more than just a BooleanSupplier, but we don't need more functionality for this example
// also note that I ingored the fact that a command might not return a thing to execute (e.g. #help)
// in QueueCommand.java
public BooleanSupplier run(String label, IArgsConsumer args) {
Stack<BooleanSupplier> taskList = // create task list, e.g. with code like in createRunCommandTask
return () -> {
if (taskList.peek().get()) {
taskList.pop();
}
return taskList.isEmpty();
};
}
}
private BooleanSupplier createRunCommandTask(String command) {
Lazy<BooleanSupplier> action = new Lazy(() -> baritone.getCommandManager().execute(command));
return () -> action.get().get();
}
// in ExampleBaritoneControl.java
public void onSendChatMessage(ChatEvent event) {
// parse command
BooleanSupplier action = command.execute(label, args);
baritone.getExecutorProcess().setTask(action); // could also add, create a new process, whatever
} And with a CPS executor maybe like this// note that I ingored the fact that a command might not return a thing to execute (e.g. #help)
// in QueueCommand.java
public State run(String label, IArgsConsumer args, State andThen) {
State state = // create task list, e.g. with RunCommandStates
// we don't really need to decompose the list into a chain of states, we could also have a State continuously return to itself and run the next action
return state;
}
private static class RunCommandState extends State {
private final String command;
public RunCommandState(String command, State andThen) {
super(andThen);
this.command = command;
}
// override annotation omitted because GitHub can't handle it
StateOrPath update() {
return new PathOrState(baritone.getCommandManager().execute(command, andThen));
}
}
// in ExampleBaritoneControl.java
public void onSendChatMessage(ChatEvent event) {
// parse command
State state = command.execute(label, args, State.DONE);
baritone.getStateExecutor().setCurrentState(state);
}
// actually, we might not go for full CPS and instead have a ExecuteAndThen(first, second) state which
// runs its own state machine for the first state so we don't have to pass andThen literally everywhere
// the example leijurv provided wasn't pure CPS either EDIT: Actually let's do the crazy thing and plug in
|
Im not able to do this. |
The new goal type allows to have baritone path to multiple points of interest in succession. There is also a new command to use with the new goal type. The waypoint command got a update to add a waypoint to a patrol route.