misc cleanup
This commit is contained in:
parent
6ca7f47bf9
commit
604ef2bb64
@ -67,7 +67,7 @@ public enum Baritone implements IBaritone {
|
|||||||
private GameEventHandler gameEventHandler;
|
private GameEventHandler gameEventHandler;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
private File dir;
|
private File dir;
|
||||||
private ThreadPoolExecutor threadPool;
|
|
||||||
|
|
||||||
private List<Behavior> behaviors;
|
private List<Behavior> behaviors;
|
||||||
private PathingBehavior pathingBehavior;
|
private PathingBehavior pathingBehavior;
|
||||||
@ -82,16 +82,16 @@ public enum Baritone implements IBaritone {
|
|||||||
|
|
||||||
private PathingControlManager pathingControlManager;
|
private PathingControlManager pathingControlManager;
|
||||||
|
|
||||||
|
private static ThreadPoolExecutor threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());
|
||||||
|
|
||||||
Baritone() {
|
Baritone() {
|
||||||
this.gameEventHandler = new GameEventHandler();
|
this.gameEventHandler = new GameEventHandler(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void init() {
|
public synchronized void init() {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
return;
|
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
|
// Acquire the "singleton" instance of the settings directly from the API
|
||||||
// We might want to change this...
|
// We might want to change this...
|
||||||
@ -148,7 +148,7 @@ public enum Baritone implements IBaritone {
|
|||||||
return this.behaviors;
|
return this.behaviors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Executor getExecutor() {
|
public static Executor getExecutor() {
|
||||||
return threadPool;
|
return threadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ public enum Baritone implements IBaritone {
|
|||||||
return Baritone.INSTANCE.settings; // yolo
|
return Baritone.INSTANCE.settings; // yolo
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getDir() {
|
public static File getDir() {
|
||||||
return this.dir;
|
return Baritone.INSTANCE.dir; // should be static I guess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
toDispatch.drainTo(curr);
|
toDispatch.drainTo(curr);
|
||||||
calcFailedLastTick = curr.contains(PathEvent.CALC_FAILED);
|
calcFailedLastTick = curr.contains(PathEvent.CALC_FAILED);
|
||||||
for (PathEvent event : curr) {
|
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;
|
isPathCalcInProgress = true;
|
||||||
}
|
}
|
||||||
CalculationContext context = new CalculationContext(); // not safe to create on the other thread, it looks up a lot of stuff in minecraft
|
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) {
|
if (talkAboutIt) {
|
||||||
logDebug("Starting to search for path from " + start + " to " + goal);
|
logDebug("Starting to search for path from " + start + " to " + goal);
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
|||||||
System.out.println("Cached world directory: " + directory);
|
System.out.println("Cached world directory: " + directory);
|
||||||
// Insert an invalid region element
|
// Insert an invalid region element
|
||||||
cachedRegions.put(0, null);
|
cachedRegions.put(0, null);
|
||||||
Baritone.INSTANCE.getExecutor().execute(new PackerThread());
|
Baritone.getExecutor().execute(new PackerThread());
|
||||||
Baritone.INSTANCE.getExecutor().execute(() -> {
|
Baritone.getExecutor().execute(() -> {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(30000);
|
Thread.sleep(30000);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
2
src/main/java/baritone/cache/WorldData.java
vendored
2
src/main/java/baritone/cache/WorldData.java
vendored
@ -43,7 +43,7 @@ public class WorldData implements IWorldData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
Baritone.INSTANCE.getExecutor().execute(() -> {
|
Baritone.getExecutor().execute(() -> {
|
||||||
System.out.println("Started saving the world in a new thread");
|
System.out.println("Started saving the world in a new thread");
|
||||||
cache.save();
|
cache.save();
|
||||||
});
|
});
|
||||||
|
@ -74,8 +74,8 @@ public enum WorldProvider implements IWorldProvider, Helper {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
//remote
|
//remote
|
||||||
directory = new File(Baritone.INSTANCE.getDir(), mc.getCurrentServerData().serverIP);
|
directory = new File(Baritone.getDir(), mc.getCurrentServerData().serverIP);
|
||||||
readme = Baritone.INSTANCE.getDir();
|
readme = Baritone.getDir();
|
||||||
}
|
}
|
||||||
// lol wtf is this baritone folder in my minecraft save?
|
// lol wtf is this baritone folder in my minecraft save?
|
||||||
try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) {
|
try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) {
|
||||||
|
@ -37,8 +37,14 @@ import java.util.ArrayList;
|
|||||||
*/
|
*/
|
||||||
public final class GameEventHandler implements IGameEventListener, Helper {
|
public final class GameEventHandler implements IGameEventListener, Helper {
|
||||||
|
|
||||||
|
private final Baritone baritone;
|
||||||
|
|
||||||
private final ArrayList<IGameEventListener> listeners = new ArrayList<>();
|
private final ArrayList<IGameEventListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
|
public GameEventHandler(Baritone baritone) {
|
||||||
|
this.baritone = baritone;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onTick(TickEvent event) {
|
public final void onTick(TickEvent event) {
|
||||||
listeners.forEach(l -> l.onTick(event));
|
listeners.forEach(l -> l.onTick(event));
|
||||||
@ -51,7 +57,7 @@ public final class GameEventHandler implements IGameEventListener, Helper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void onProcessKeyBinds() {
|
public final void onProcessKeyBinds() {
|
||||||
InputOverrideHandler inputHandler = Baritone.INSTANCE.getInputOverrideHandler();
|
InputOverrideHandler inputHandler = baritone.getInputOverrideHandler();
|
||||||
|
|
||||||
// Simulate the key being held down this tick
|
// Simulate the key being held down this tick
|
||||||
for (InputOverrideHandler.Input input : InputOverrideHandler.Input.values()) {
|
for (InputOverrideHandler.Input input : InputOverrideHandler.Input.values()) {
|
||||||
|
@ -226,12 +226,6 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
|||||||
state.getInputStates().forEach((input, forced) -> Baritone.INSTANCE.getInputOverrideHandler().setInputForceState(input, forced));
|
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
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
currentState = new MovementState().setStatus(MovementStatus.PREPPING);
|
||||||
|
@ -73,7 +73,7 @@ public class GetToBlockProcess extends BaritoneProcessHelper implements IGetToBl
|
|||||||
}
|
}
|
||||||
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.get();
|
||||||
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
|
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));
|
Goal goal = new GoalComposite(knownLocations.stream().map(GoalGetToBlock::new).toArray(Goal[]::new));
|
||||||
if (goal.isInGoal(playerFeet())) {
|
if (goal.isInGoal(playerFeet())) {
|
||||||
|
Loading…
Reference in New Issue
Block a user