misc cleanup

This commit is contained in:
Leijurv 2018-11-05 20:01:46 -08:00
parent 6ca7f47bf9
commit 604ef2bb64
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
8 changed files with 22 additions and 22 deletions

View File

@ -67,7 +67,7 @@ public enum Baritone implements IBaritone {
private GameEventHandler gameEventHandler;
private Settings settings;
private File dir;
private ThreadPoolExecutor threadPool;
private List<Behavior> 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
}
}

View File

@ -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);
}

View File

@ -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) {

View File

@ -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();
});

View File

@ -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"))) {

View File

@ -37,8 +37,14 @@ import java.util.ArrayList;
*/
public final class GameEventHandler implements IGameEventListener, Helper {
private final Baritone baritone;
private final ArrayList<IGameEventListener> 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()) {

View File

@ -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);

View File

@ -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())) {