From 604ef2bb64e98c61d6201e3c41fa9336bfc04be0 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Mon, 5 Nov 2018 20:01:46 -0800 Subject: [PATCH] misc cleanup --- src/main/java/baritone/Baritone.java | 14 +++++++------- .../java/baritone/behavior/PathingBehavior.java | 4 ++-- src/main/java/baritone/cache/CachedWorld.java | 4 ++-- src/main/java/baritone/cache/WorldData.java | 2 +- src/main/java/baritone/cache/WorldProvider.java | 4 ++-- src/main/java/baritone/event/GameEventHandler.java | 8 +++++++- .../java/baritone/pathing/movement/Movement.java | 6 ------ .../java/baritone/process/GetToBlockProcess.java | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/baritone/Baritone.java b/src/main/java/baritone/Baritone.java index 50320289..69dc1b2a 100755 --- a/src/main/java/baritone/Baritone.java +++ b/src/main/java/baritone/Baritone.java @@ -67,7 +67,7 @@ public enum Baritone implements IBaritone { private GameEventHandler gameEventHandler; private Settings settings; private File dir; - private ThreadPoolExecutor threadPool; + private List behaviors; private PathingBehavior pathingBehavior; @@ -82,16 +82,16 @@ public enum Baritone implements IBaritone { private PathingControlManager pathingControlManager; + private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); + Baritone() { - this.gameEventHandler = new GameEventHandler(); + this.gameEventHandler = new GameEventHandler(this); } public synchronized void init() { if (initialized) { return; } - this.threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>()); - // Acquire the "singleton" instance of the settings directly from the API // We might want to change this... @@ -148,7 +148,7 @@ public enum Baritone implements IBaritone { return this.behaviors; } - public Executor getExecutor() { + public static Executor getExecutor() { return threadPool; } @@ -215,7 +215,7 @@ public enum Baritone implements IBaritone { return Baritone.INSTANCE.settings; // yolo } - public File getDir() { - return this.dir; + public static File getDir() { + return Baritone.INSTANCE.dir; // should be static I guess } } diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index d2a55127..77c9839d 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -78,7 +78,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, toDispatch.drainTo(curr); calcFailedLastTick = curr.contains(PathEvent.CALC_FAILED); for (PathEvent event : curr) { - Baritone.INSTANCE.getGameEventHandler().onPathEvent(event); + baritone.getGameEventHandler().onPathEvent(event); } } @@ -370,7 +370,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, isPathCalcInProgress = true; } CalculationContext context = new CalculationContext(); // not safe to create on the other thread, it looks up a lot of stuff in minecraft - Baritone.INSTANCE.getExecutor().execute(() -> { + Baritone.getExecutor().execute(() -> { if (talkAboutIt) { logDebug("Starting to search for path from " + start + " to " + goal); } diff --git a/src/main/java/baritone/cache/CachedWorld.java b/src/main/java/baritone/cache/CachedWorld.java index 14b66839..48e4ccb2 100644 --- a/src/main/java/baritone/cache/CachedWorld.java +++ b/src/main/java/baritone/cache/CachedWorld.java @@ -67,8 +67,8 @@ public final class CachedWorld implements ICachedWorld, Helper { System.out.println("Cached world directory: " + directory); // Insert an invalid region element cachedRegions.put(0, null); - Baritone.INSTANCE.getExecutor().execute(new PackerThread()); - Baritone.INSTANCE.getExecutor().execute(() -> { + Baritone.getExecutor().execute(new PackerThread()); + Baritone.getExecutor().execute(() -> { try { Thread.sleep(30000); while (true) { diff --git a/src/main/java/baritone/cache/WorldData.java b/src/main/java/baritone/cache/WorldData.java index b489d933..36a239fa 100644 --- a/src/main/java/baritone/cache/WorldData.java +++ b/src/main/java/baritone/cache/WorldData.java @@ -43,7 +43,7 @@ public class WorldData implements IWorldData { } public void onClose() { - Baritone.INSTANCE.getExecutor().execute(() -> { + Baritone.getExecutor().execute(() -> { System.out.println("Started saving the world in a new thread"); cache.save(); }); diff --git a/src/main/java/baritone/cache/WorldProvider.java b/src/main/java/baritone/cache/WorldProvider.java index 2aef54c6..e3a53bba 100644 --- a/src/main/java/baritone/cache/WorldProvider.java +++ b/src/main/java/baritone/cache/WorldProvider.java @@ -74,8 +74,8 @@ public enum WorldProvider implements IWorldProvider, Helper { } else { //remote - directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP); - readme = Baritone.INSTANCE.getDir(); + directory = new File(Baritone.getDir(), mc.getCurrentServerData().serverIP); + readme = Baritone.getDir(); } // lol wtf is this baritone folder in my minecraft save? try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) { diff --git a/src/main/java/baritone/event/GameEventHandler.java b/src/main/java/baritone/event/GameEventHandler.java index e7cd5847..fd031a0a 100644 --- a/src/main/java/baritone/event/GameEventHandler.java +++ b/src/main/java/baritone/event/GameEventHandler.java @@ -37,8 +37,14 @@ import java.util.ArrayList; */ public final class GameEventHandler implements IGameEventListener, Helper { + private final Baritone baritone; + private final ArrayList listeners = new ArrayList<>(); + public GameEventHandler(Baritone baritone) { + this.baritone = baritone; + } + @Override public final void onTick(TickEvent event) { listeners.forEach(l -> l.onTick(event)); @@ -51,7 +57,7 @@ public final class GameEventHandler implements IGameEventListener, Helper { @Override public final void onProcessKeyBinds() { - InputOverrideHandler inputHandler = Baritone.INSTANCE.getInputOverrideHandler(); + InputOverrideHandler inputHandler = baritone.getInputOverrideHandler(); // Simulate the key being held down this tick for (InputOverrideHandler.Input input : InputOverrideHandler.Input.values()) { diff --git a/src/main/java/baritone/pathing/movement/Movement.java b/src/main/java/baritone/pathing/movement/Movement.java index aacd7f9f..0bdedbf0 100644 --- a/src/main/java/baritone/pathing/movement/Movement.java +++ b/src/main/java/baritone/pathing/movement/Movement.java @@ -226,12 +226,6 @@ public abstract class Movement implements IMovement, Helper, MovementHelper { state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced)); } - public void cancel() { - currentState.getInputStates().replaceAll((input, forced) -> false); - currentState.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced)); - currentState.setStatus(MovementStatus.CANCELED); - } - @Override public void reset() { currentState = new MovementState().setStatus(MovementStatus.PREPPING); diff --git a/src/main/java/baritone/process/GetToBlockProcess.java b/src/main/java/baritone/process/GetToBlockProcess.java index d35b4fb4..94e02e03 100644 --- a/src/main/java/baritone/process/GetToBlockProcess.java +++ b/src/main/java/baritone/process/GetToBlockProcess.java @@ -73,7 +73,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get(); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - Baritone.INSTANCE.getExecutor().execute(this::rescan); + Baritone.getExecutor().execute(this::rescan); } Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)); if (goal.isInGoal(playerFeet())) {