From d79d56c2f987bd11dd7982db3b5c37f0ae1e36ca Mon Sep 17 00:00:00 2001 From: Brady Date: Tue, 13 Nov 2018 21:45:26 -0600 Subject: [PATCH] Expose all possible Baritone instances --- src/api/java/baritone/api/BaritoneAPI.java | 56 ++----------------- src/api/java/baritone/api/IBaritone.java | 6 -- .../java/baritone/api/IBaritoneProvider.java | 30 ++++++++++ src/main/java/baritone/Baritone.java | 24 +++----- src/main/java/baritone/BaritoneProvider.java | 23 +++++++- 5 files changed, 65 insertions(+), 74 deletions(-) diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java index b9dbcd04..c1227830 100644 --- a/src/api/java/baritone/api/BaritoneAPI.java +++ b/src/api/java/baritone/api/BaritoneAPI.java @@ -17,16 +17,6 @@ package baritone.api; -import baritone.api.behavior.ILookBehavior; -import baritone.api.behavior.IMemoryBehavior; -import baritone.api.behavior.IPathingBehavior; -import baritone.api.cache.IWorldProvider; -import baritone.api.cache.IWorldScanner; -import baritone.api.event.listener.IGameEventListener; -import baritone.api.process.ICustomGoalProcess; -import baritone.api.process.IFollowProcess; -import baritone.api.process.IGetToBlockProcess; -import baritone.api.process.IMineProcess; import baritone.api.utils.SettingsUtil; import java.util.Iterator; @@ -42,59 +32,23 @@ import java.util.ServiceLoader; */ public final class BaritoneAPI { - private static final IBaritone baritone; + private static final IBaritoneProvider provider; private static final Settings settings; static { ServiceLoader baritoneLoader = ServiceLoader.load(IBaritoneProvider.class); Iterator instances = baritoneLoader.iterator(); - baritone = instances.next().getBaritoneForPlayer(null); // PWNAGE + provider = instances.next(); settings = new Settings(); SettingsUtil.readAndApply(settings); } - public static IFollowProcess getFollowProcess() { - return baritone.getFollowProcess(); - } - - public static ILookBehavior getLookBehavior() { - return baritone.getLookBehavior(); - } - - public static IMemoryBehavior getMemoryBehavior() { - return baritone.getMemoryBehavior(); - } - - public static IMineProcess getMineProcess() { - return baritone.getMineProcess(); - } - - public static IPathingBehavior getPathingBehavior() { - return baritone.getPathingBehavior(); + public static IBaritoneProvider getProvider() { + return BaritoneAPI.provider; } public static Settings getSettings() { - return settings; - } - - public static IWorldProvider getWorldProvider() { - return baritone.getWorldProvider(); - } - - public static IWorldScanner getWorldScanner() { - return baritone.getWorldScanner(); - } - - public static ICustomGoalProcess getCustomGoalProcess() { - return baritone.getCustomGoalProcess(); - } - - public static IGetToBlockProcess getGetToBlockProcess() { - return baritone.getGetToBlockProcess(); - } - - public static void registerEventListener(IGameEventListener listener) { - baritone.registerEventListener(listener); + return BaritoneAPI.settings; } } diff --git a/src/api/java/baritone/api/IBaritone.java b/src/api/java/baritone/api/IBaritone.java index 7646cb8f..b462c620 100644 --- a/src/api/java/baritone/api/IBaritone.java +++ b/src/api/java/baritone/api/IBaritone.java @@ -72,12 +72,6 @@ public interface IBaritone { */ IWorldProvider getWorldProvider(); - /** - * @return The {@link IWorldScanner} instance - * @see IWorldScanner - */ - IWorldScanner getWorldScanner(); - IInputOverrideHandler getInputOverrideHandler(); ICustomGoalProcess getCustomGoalProcess(); diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java index 745842ce..b52e5603 100644 --- a/src/api/java/baritone/api/IBaritoneProvider.java +++ b/src/api/java/baritone/api/IBaritoneProvider.java @@ -17,13 +17,35 @@ package baritone.api; +import baritone.api.cache.IWorldScanner; import net.minecraft.client.entity.EntityPlayerSP; +import java.util.List; + /** * @author Leijurv */ public interface IBaritoneProvider { + /** + * Returns the primary {@link IBaritone} instance. This instance is persistent, and + * is represented by the local player that is created by the game itself, not a "bot" + * player through Baritone. + * + * @return The primary {@link IBaritone} instance. + */ + IBaritone getPrimaryBaritone(); + + /** + * Returns all of the active {@link IBaritone} instances. This includes the local one + * returned by {@link #getPrimaryBaritone()}. + * + * @see #getBaritoneForPlayer(EntityPlayerSP) + * + * @return All active {@link IBaritone} instances. + */ + List getAllBaritones(); + /** * Provides the {@link IBaritone} instance for a given {@link EntityPlayerSP}. This will likely be * replaced with {@code #getBaritoneForUser(IBaritoneUser)} when {@code bot-system} is merged. @@ -32,4 +54,12 @@ public interface IBaritoneProvider { * @return The {@link IBaritone} instance. */ IBaritone getBaritoneForPlayer(EntityPlayerSP player); + + /** + * Returns the {@link IWorldScanner} instance. This is not a type returned by + * {@link IBaritone} implementation, because it is not linked with {@link IBaritone}. + * + * @return The {@link IWorldScanner} instance. + */ + IWorldScanner getWorldScanner(); } diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index b752b63e..29cb2fb7 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -95,6 +95,7 @@ public enum Baritone implements IBaritone { private PathingControlManager pathingControlManager; + private IPlayerContext playerContext; private WorldProvider worldProvider; Baritone() { @@ -124,6 +125,7 @@ public enum Baritone implements IBaritone { getToBlockProcess = new GetToBlockProcess(this); } + this.playerContext = LocalPlayerContext.INSTANCE; this.worldProvider = new WorldProvider(); if (BaritoneAutoTest.ENABLE_AUTO_TEST) { @@ -141,11 +143,6 @@ public enum Baritone implements IBaritone { return this.gameEventHandler; } - @Override - public InputOverrideHandler getInputOverrideHandler() { - return this.inputOverrideHandler; - } - public List getBehaviors() { return this.behaviors; } @@ -155,6 +152,11 @@ public enum Baritone implements IBaritone { this.registerEventListener(behavior); } + @Override + public InputOverrideHandler getInputOverrideHandler() { + return this.inputOverrideHandler; + } + @Override public CustomGoalProcess getCustomGoalProcess() { // Iffy return customGoalProcess; @@ -167,7 +169,7 @@ public enum Baritone implements IBaritone { @Override public IPlayerContext getPlayerContext() { - return LocalPlayerContext.INSTANCE; + return playerContext; } @Override @@ -200,16 +202,6 @@ public enum Baritone implements IBaritone { return worldProvider; } - /** - * TODO-yeet This shouldn't be baritone-instance specific - * - * @return world scanner instance - */ - @Override - public WorldScanner getWorldScanner() { - return WorldScanner.INSTANCE; - } - @Override public void registerEventListener(IGameEventListener listener) { this.gameEventHandler.registerEventListener(listener); diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java index a80dfe5e..aa7e08e4 100644 --- a/src/main/java/baritone/BaritoneProvider.java +++ b/src/main/java/baritone/BaritoneProvider.java @@ -19,15 +19,36 @@ package baritone; import baritone.api.IBaritone; import baritone.api.IBaritoneProvider; +import baritone.api.cache.IWorldScanner; +import baritone.cache.WorldScanner; import net.minecraft.client.entity.EntityPlayerSP; +import java.util.Collections; +import java.util.List; + /** * @author Brady * @since 9/29/2018 */ public final class BaritoneProvider implements IBaritoneProvider { + + @Override + public IBaritone getPrimaryBaritone() { + return Baritone.INSTANCE; + } + + @Override + public List getAllBaritones() { + return Collections.singletonList(Baritone.INSTANCE); + } + @Override public IBaritone getBaritoneForPlayer(EntityPlayerSP player) { - return Baritone.INSTANCE; // pwnage + return Baritone.INSTANCE; + } + + @Override + public IWorldScanner getWorldScanner() { + return WorldScanner.INSTANCE; } }