diff --git a/src/api/java/baritone/api/BaritoneAPI.java b/src/api/java/baritone/api/BaritoneAPI.java
index aa9491db..dec7ec13 100644
--- a/src/api/java/baritone/api/BaritoneAPI.java
+++ b/src/api/java/baritone/api/BaritoneAPI.java
@@ -20,6 +20,9 @@ package baritone.api;
import baritone.api.behavior.*;
import baritone.api.cache.IWorldProvider;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
/**
* API exposure for various things implemented in Baritone.
*
@@ -28,37 +31,37 @@ import baritone.api.cache.IWorldProvider;
* @author Brady
* @since 9/23/2018
*/
-public class BaritoneAPI {
+public final class BaritoneAPI {
- // General
- private static final Settings settings = new Settings();
- private static IWorldProvider worldProvider;
+ private final static IBaritoneProvider baritone;
+ private final static Settings settings;
- // Behaviors
- private static IFollowBehavior followBehavior;
- private static ILookBehavior lookBehavior;
- private static IMemoryBehavior memoryBehavior;
- private static IMineBehavior mineBehavior;
- private static IPathingBehavior pathingBehavior;
+ static {
+ ServiceLoader baritoneLoader = ServiceLoader.load(IBaritoneProvider.class);
+ Iterator instances = baritoneLoader.iterator();
+ baritone = instances.next();
+
+ settings = new Settings();
+ }
public static IFollowBehavior getFollowBehavior() {
- return followBehavior;
+ return baritone.getFollowBehavior();
}
public static ILookBehavior getLookBehavior() {
- return lookBehavior;
+ return baritone.getLookBehavior();
}
public static IMemoryBehavior getMemoryBehavior() {
- return memoryBehavior;
+ return baritone.getMemoryBehavior();
}
public static IMineBehavior getMineBehavior() {
- return mineBehavior;
+ return baritone.getMineBehavior();
}
public static IPathingBehavior getPathingBehavior() {
- return pathingBehavior;
+ return baritone.getPathingBehavior();
}
public static Settings getSettings() {
@@ -66,34 +69,6 @@ public class BaritoneAPI {
}
public static IWorldProvider getWorldProvider() {
- return worldProvider;
+ return baritone.getWorldProvider();
}
-
- /**
- * FOR INTERNAL USE ONLY
- */
- public static void registerProviders(
- IWorldProvider worldProvider
- ) {
- BaritoneAPI.worldProvider = worldProvider;
- }
-
- /**
- * FOR INTERNAL USE ONLY
- */
- // @formatter:off
- public static void registerDefaultBehaviors(
- IFollowBehavior followBehavior,
- ILookBehavior lookBehavior,
- IMemoryBehavior memoryBehavior,
- IMineBehavior mineBehavior,
- IPathingBehavior pathingBehavior
- ) {
- BaritoneAPI.followBehavior = followBehavior;
- BaritoneAPI.lookBehavior = lookBehavior;
- BaritoneAPI.memoryBehavior = memoryBehavior;
- BaritoneAPI.mineBehavior = mineBehavior;
- BaritoneAPI.pathingBehavior = pathingBehavior;
- }
- // @formatter:on
}
diff --git a/src/api/java/baritone/api/IBaritoneProvider.java b/src/api/java/baritone/api/IBaritoneProvider.java
new file mode 100644
index 00000000..03b457bb
--- /dev/null
+++ b/src/api/java/baritone/api/IBaritoneProvider.java
@@ -0,0 +1,40 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone.api;
+
+import baritone.api.behavior.*;
+import baritone.api.cache.IWorldProvider;
+
+/**
+ * @author Brady
+ * @since 9/29/2018
+ */
+public interface IBaritoneProvider {
+
+ IFollowBehavior getFollowBehavior();
+
+ ILookBehavior getLookBehavior();
+
+ IMemoryBehavior getMemoryBehavior();
+
+ IMineBehavior getMineBehavior();
+
+ IPathingBehavior getPathingBehavior();
+
+ IWorldProvider getWorldProvider();
+}
diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java
index 4a764bcc..b7904d00 100755
--- a/src/main/java/baritone/Baritone.java
+++ b/src/main/java/baritone/Baritone.java
@@ -88,8 +88,6 @@ public enum Baritone {
// We might want to change this...
this.settings = BaritoneAPI.getSettings();
- BaritoneAPI.registerProviders(WorldProvider.INSTANCE);
-
this.behaviors = new ArrayList<>();
{
registerBehavior(PathingBehavior.INSTANCE);
@@ -98,16 +96,6 @@ public enum Baritone {
registerBehavior(LocationTrackingBehavior.INSTANCE);
registerBehavior(FollowBehavior.INSTANCE);
registerBehavior(MineBehavior.INSTANCE);
-
- // TODO: Clean this up
- // Maybe combine this call in someway with the registerBehavior calls?
- BaritoneAPI.registerDefaultBehaviors(
- FollowBehavior.INSTANCE,
- LookBehavior.INSTANCE,
- MemoryBehavior.INSTANCE,
- MineBehavior.INSTANCE,
- PathingBehavior.INSTANCE
- );
}
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
registerEventListener(BaritoneAutoTest.INSTANCE);
diff --git a/src/main/java/baritone/BaritoneProvider.java b/src/main/java/baritone/BaritoneProvider.java
new file mode 100644
index 00000000..370a398e
--- /dev/null
+++ b/src/main/java/baritone/BaritoneProvider.java
@@ -0,0 +1,61 @@
+/*
+ * This file is part of Baritone.
+ *
+ * Baritone is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Baritone is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Baritone. If not, see .
+ */
+
+package baritone;
+
+import baritone.api.IBaritoneProvider;
+import baritone.api.behavior.*;
+import baritone.api.cache.IWorldProvider;
+import baritone.behavior.*;
+import baritone.cache.WorldProvider;
+
+/**
+ * @author Brady
+ * @since 9/29/2018
+ */
+public final class BaritoneProvider implements IBaritoneProvider {
+
+ @Override
+ public IFollowBehavior getFollowBehavior() {
+ return FollowBehavior.INSTANCE;
+ }
+
+ @Override
+ public ILookBehavior getLookBehavior() {
+ return LookBehavior.INSTANCE;
+ }
+
+ @Override
+ public IMemoryBehavior getMemoryBehavior() {
+ return MemoryBehavior.INSTANCE;
+ }
+
+ @Override
+ public IMineBehavior getMineBehavior() {
+ return MineBehavior.INSTANCE;
+ }
+
+ @Override
+ public IPathingBehavior getPathingBehavior() {
+ return PathingBehavior.INSTANCE;
+ }
+
+ @Override
+ public IWorldProvider getWorldProvider() {
+ return WorldProvider.INSTANCE;
+ }
+}
diff --git a/src/main/resources/META-INF/services/baritone.api.IBaritoneProvider b/src/main/resources/META-INF/services/baritone.api.IBaritoneProvider
new file mode 100644
index 00000000..934db7d3
--- /dev/null
+++ b/src/main/resources/META-INF/services/baritone.api.IBaritoneProvider
@@ -0,0 +1 @@
+baritone.BaritoneProvider
\ No newline at end of file