Skip to content
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

IExecutionControl API class #4125

Open
wants to merge 1 commit into
base: 1.19.4
Choose a base branch
from
Open

Conversation

RacoonDog
Copy link

  • Adds the convenience method IBaritone.createExecutionControl() which returns an IExecutionControl for creating a Baritone process who's sole purpose is to pause/resume Baritone.
  • Replaces the IBaritoneProcess in ExecutionControlCommands with an IExecutionControl, simplifying the class greatly.

The goal being to encourage 3rd party API users to employ proper methods for pausing/resuming Baritone as opposed to using the command system.

Pausing is simplified from:

private static boolean paused = false;

static {
    BaritoneAPI.getProvider().getPrimaryBaritone().getPathingControlManager().registerProcess(new IBaritoneProcess() {
        @Override
        public boolean isActive() {
            return paused;
        }
    
        @Override
        public PathingCommand onTick(boolean b, boolean b1) {
            BaritoneAPI.getProvider().getPrimaryBaritone().getInputOverrideHandler().clearAllKeys();
            return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
        }
    
        @Override
        public boolean isTemporary() {
            return true;
       }

        @Override
        public void onLostControl() {}

        @Override
        public double priority() {
            return 0d;
        }

        @Override
        public String displayName0() {
            return "Pause Controls";
        }
    });
}

public static void pauseBaritone() {
    paused = true;
}

to

private static final IExecutionControl EXECUTION_CONTROL = BaritoneAPI.getProvider().getPrimaryBaritone().createExecutionControl("Pause Controls", 0d);

public static void pauseBaritone() {
    EXECUTION_CONTROL.pause();
}

@RickyTheRacc
Copy link

W

@RacoonDog
Copy link
Author

I was debating whether I should make IExecutionControl extend IBaritoneProcess since it's, at its core, just a wrapper and would maybe enable more functinality, but it would also create confusion since IExecutionControl.paused() would have the same return value as IBaritoneProcess.isActive().

I could also just make a getter in IExecutionControl for the underlying IBaritoneProcess I guess...

pls give input

@ZacSharp
Copy link
Collaborator

ZacSharp commented Sep 6, 2023

I get your point about simplifying basic Baritone integration, but I'm not sure whether creating a new type of component just for this purpose is the way to go. I think providing just a concrete implementation of IBaritoneProcess is enough and the factory method for the one-call setup should be a static method on that class rather than an instance method on Baritone and it should do the registration after the constructor is done.

I'd also suggest choosing a different name since when I first read the title of this pr I though you were working on #3565. Maybe something like SimplePauserProcess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants