only one singleton
This commit is contained in:
parent
c4b0e0a810
commit
1b1233d26a
@ -22,9 +22,7 @@ import baritone.api.event.events.BlockInteractEvent;
|
|||||||
import baritone.api.event.events.TickEvent;
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.api.event.events.WorldEvent;
|
import baritone.api.event.events.WorldEvent;
|
||||||
import baritone.api.event.events.type.EventState;
|
import baritone.api.event.events.type.EventState;
|
||||||
import baritone.behavior.PathingBehavior;
|
|
||||||
import baritone.utils.BaritoneAutoTest;
|
import baritone.utils.BaritoneAutoTest;
|
||||||
import baritone.utils.ExampleBaritoneControl;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
@ -60,7 +58,6 @@ public class MixinMinecraft {
|
|||||||
)
|
)
|
||||||
private void postInit(CallbackInfo ci) {
|
private void postInit(CallbackInfo ci) {
|
||||||
Baritone.INSTANCE.init();
|
Baritone.INSTANCE.init();
|
||||||
ExampleBaritoneControl.INSTANCE.initAndRegister();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
@ -145,7 +142,7 @@ public class MixinMinecraft {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
private boolean isAllowUserInput(GuiScreen screen) {
|
private boolean isAllowUserInput(GuiScreen screen) {
|
||||||
return (PathingBehavior.INSTANCE.getCurrent() != null && PathingBehavior.INSTANCE.isEnabled() && player != null) || screen.allowUserInput;
|
return (Baritone.INSTANCE.getPathingBehavior().getCurrent() != null && Baritone.INSTANCE.getPathingBehavior().isEnabled() && player != null) || screen.allowUserInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(
|
@Inject(
|
||||||
|
@ -18,11 +18,18 @@
|
|||||||
package baritone;
|
package baritone;
|
||||||
|
|
||||||
import baritone.api.BaritoneAPI;
|
import baritone.api.BaritoneAPI;
|
||||||
|
import baritone.api.IBaritoneProvider;
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
|
import baritone.api.behavior.*;
|
||||||
|
import baritone.api.cache.IWorldProvider;
|
||||||
|
import baritone.api.cache.IWorldScanner;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
import baritone.behavior.*;
|
import baritone.behavior.*;
|
||||||
|
import baritone.cache.WorldProvider;
|
||||||
|
import baritone.cache.WorldScanner;
|
||||||
import baritone.event.GameEventHandler;
|
import baritone.event.GameEventHandler;
|
||||||
import baritone.utils.BaritoneAutoTest;
|
import baritone.utils.BaritoneAutoTest;
|
||||||
|
import baritone.utils.ExampleBaritoneControl;
|
||||||
import baritone.utils.InputOverrideHandler;
|
import baritone.utils.InputOverrideHandler;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
|
||||||
@ -40,7 +47,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 7/31/2018 10:50 PM
|
* @since 7/31/2018 10:50 PM
|
||||||
*/
|
*/
|
||||||
public enum Baritone {
|
public enum Baritone implements IBaritoneProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Singleton instance of this class
|
* Singleton instance of this class
|
||||||
@ -55,10 +62,17 @@ public enum Baritone {
|
|||||||
private GameEventHandler gameEventHandler;
|
private GameEventHandler gameEventHandler;
|
||||||
private InputOverrideHandler inputOverrideHandler;
|
private InputOverrideHandler inputOverrideHandler;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
private List<Behavior> behaviors;
|
|
||||||
private File dir;
|
private File dir;
|
||||||
private ThreadPoolExecutor threadPool;
|
private ThreadPoolExecutor threadPool;
|
||||||
|
|
||||||
|
private List<Behavior> behaviors;
|
||||||
|
private PathingBehavior pathingBehavior;
|
||||||
|
private LookBehavior lookBehavior;
|
||||||
|
private MemoryBehavior memoryBehavior;
|
||||||
|
private LocationTrackingBehavior locationTrackingBehavior;
|
||||||
|
private FollowBehavior followBehavior;
|
||||||
|
private MineBehavior mineBehavior;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not Baritone is active
|
* Whether or not Baritone is active
|
||||||
*/
|
*/
|
||||||
@ -81,12 +95,14 @@ public enum Baritone {
|
|||||||
|
|
||||||
this.behaviors = new ArrayList<>();
|
this.behaviors = new ArrayList<>();
|
||||||
{
|
{
|
||||||
registerBehavior(PathingBehavior.INSTANCE);
|
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||||
registerBehavior(LookBehavior.INSTANCE);
|
pathingBehavior = new PathingBehavior(this);
|
||||||
registerBehavior(MemoryBehavior.INSTANCE);
|
lookBehavior = new LookBehavior(this);
|
||||||
registerBehavior(LocationTrackingBehavior.INSTANCE);
|
memoryBehavior = new MemoryBehavior(this);
|
||||||
registerBehavior(FollowBehavior.INSTANCE);
|
locationTrackingBehavior = new LocationTrackingBehavior(this);
|
||||||
registerBehavior(MineBehavior.INSTANCE);
|
followBehavior = new FollowBehavior(this);
|
||||||
|
mineBehavior = new MineBehavior(this);
|
||||||
|
new ExampleBaritoneControl(this);
|
||||||
}
|
}
|
||||||
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
|
if (BaritoneAutoTest.ENABLE_AUTO_TEST) {
|
||||||
registerEventListener(BaritoneAutoTest.INSTANCE);
|
registerEventListener(BaritoneAutoTest.INSTANCE);
|
||||||
@ -127,6 +143,42 @@ public enum Baritone {
|
|||||||
this.registerEventListener(behavior);
|
this.registerEventListener(behavior);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IFollowBehavior getFollowBehavior() {
|
||||||
|
return followBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ILookBehavior getLookBehavior() {
|
||||||
|
return lookBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMemoryBehavior getMemoryBehavior() {
|
||||||
|
return memoryBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMineBehavior getMineBehavior() {
|
||||||
|
return mineBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPathingBehavior getPathingBehavior() {
|
||||||
|
return pathingBehavior;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWorldProvider getWorldProvider() {
|
||||||
|
return WorldProvider.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IWorldScanner getWorldScanner() {
|
||||||
|
return WorldScanner.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void registerEventListener(IGameEventListener listener) {
|
public void registerEventListener(IGameEventListener listener) {
|
||||||
this.gameEventHandler.registerEventListener(listener);
|
this.gameEventHandler.registerEventListener(listener);
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,12 @@ import baritone.api.behavior.*;
|
|||||||
import baritone.api.cache.IWorldProvider;
|
import baritone.api.cache.IWorldProvider;
|
||||||
import baritone.api.cache.IWorldScanner;
|
import baritone.api.cache.IWorldScanner;
|
||||||
import baritone.api.event.listener.IGameEventListener;
|
import baritone.api.event.listener.IGameEventListener;
|
||||||
import baritone.behavior.*;
|
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
import baritone.cache.WorldScanner;
|
import baritone.cache.WorldScanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* todo fix this cancer
|
||||||
|
*
|
||||||
* @author Brady
|
* @author Brady
|
||||||
* @since 9/29/2018
|
* @since 9/29/2018
|
||||||
*/
|
*/
|
||||||
@ -34,27 +35,27 @@ public final class BaritoneProvider implements IBaritoneProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IFollowBehavior getFollowBehavior() {
|
public IFollowBehavior getFollowBehavior() {
|
||||||
return FollowBehavior.INSTANCE;
|
return Baritone.INSTANCE.getFollowBehavior();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ILookBehavior getLookBehavior() {
|
public ILookBehavior getLookBehavior() {
|
||||||
return LookBehavior.INSTANCE;
|
return Baritone.INSTANCE.getLookBehavior();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMemoryBehavior getMemoryBehavior() {
|
public IMemoryBehavior getMemoryBehavior() {
|
||||||
return MemoryBehavior.INSTANCE;
|
return Baritone.INSTANCE.getMemoryBehavior();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IMineBehavior getMineBehavior() {
|
public IMineBehavior getMineBehavior() {
|
||||||
return MineBehavior.INSTANCE;
|
return Baritone.INSTANCE.getMineBehavior();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPathingBehavior getPathingBehavior() {
|
public IPathingBehavior getPathingBehavior() {
|
||||||
return PathingBehavior.INSTANCE;
|
return Baritone.INSTANCE.getPathingBehavior();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.behavior;
|
package baritone.behavior;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.behavior.IBehavior;
|
import baritone.api.behavior.IBehavior;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,6 +28,13 @@ import baritone.api.behavior.IBehavior;
|
|||||||
*/
|
*/
|
||||||
public class Behavior implements IBehavior {
|
public class Behavior implements IBehavior {
|
||||||
|
|
||||||
|
public final Baritone baritone;
|
||||||
|
|
||||||
|
protected Behavior(Baritone baritone) {
|
||||||
|
this.baritone = baritone;
|
||||||
|
baritone.registerBehavior(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not this behavior is enabled
|
* Whether or not this behavior is enabled
|
||||||
*/
|
*/
|
||||||
|
@ -33,11 +33,11 @@ import net.minecraft.util.math.BlockPos;
|
|||||||
*/
|
*/
|
||||||
public final class FollowBehavior extends Behavior implements IFollowBehavior, Helper {
|
public final class FollowBehavior extends Behavior implements IFollowBehavior, Helper {
|
||||||
|
|
||||||
public static final FollowBehavior INSTANCE = new FollowBehavior();
|
|
||||||
|
|
||||||
private Entity following;
|
private Entity following;
|
||||||
|
|
||||||
private FollowBehavior() {}
|
public FollowBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
@ -56,9 +56,9 @@ public final class FollowBehavior extends Behavior implements IFollowBehavior, H
|
|||||||
GoalXZ g = GoalXZ.fromDirection(following.getPositionVector(), Baritone.settings().followOffsetDirection.get(), Baritone.settings().followOffsetDistance.get());
|
GoalXZ g = GoalXZ.fromDirection(following.getPositionVector(), Baritone.settings().followOffsetDirection.get(), Baritone.settings().followOffsetDistance.get());
|
||||||
pos = new BlockPos(g.getX(), following.posY, g.getZ());
|
pos = new BlockPos(g.getX(), following.posY, g.getZ());
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(new GoalNear(pos, Baritone.settings().followRadius.get()));
|
baritone.getPathingBehavior().setGoal(new GoalNear(pos, Baritone.settings().followRadius.get()));
|
||||||
PathingBehavior.INSTANCE.revalidateGoal();
|
((PathingBehavior) baritone.getPathingBehavior()).revalidateGoal();
|
||||||
PathingBehavior.INSTANCE.path();
|
baritone.getPathingBehavior().path();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -73,7 +73,7 @@ public final class FollowBehavior extends Behavior implements IFollowBehavior, H
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
PathingBehavior.INSTANCE.cancel();
|
baritone.getPathingBehavior().cancel();
|
||||||
follow(null);
|
follow(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.behavior;
|
package baritone.behavior;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.event.events.BlockInteractEvent;
|
import baritone.api.event.events.BlockInteractEvent;
|
||||||
import baritone.cache.Waypoint;
|
import baritone.cache.Waypoint;
|
||||||
import baritone.cache.WorldProvider;
|
import baritone.cache.WorldProvider;
|
||||||
@ -28,16 +29,15 @@ import net.minecraft.block.BlockBed;
|
|||||||
* A collection of event methods that are used to interact with Baritone's
|
* A collection of event methods that are used to interact with Baritone's
|
||||||
* waypoint system. This class probably needs a better name.
|
* waypoint system. This class probably needs a better name.
|
||||||
*
|
*
|
||||||
* @see Waypoint
|
|
||||||
*
|
|
||||||
* @author Brady
|
* @author Brady
|
||||||
|
* @see Waypoint
|
||||||
* @since 8/22/2018
|
* @since 8/22/2018
|
||||||
*/
|
*/
|
||||||
public final class LocationTrackingBehavior extends Behavior implements Helper {
|
public final class LocationTrackingBehavior extends Behavior implements Helper {
|
||||||
|
|
||||||
public static final LocationTrackingBehavior INSTANCE = new LocationTrackingBehavior();
|
public LocationTrackingBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
private LocationTrackingBehavior() {}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBlockInteract(BlockInteractEvent event) {
|
public void onBlockInteract(BlockInteractEvent event) {
|
||||||
|
@ -26,9 +26,6 @@ import baritone.api.utils.Rotation;
|
|||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
|
|
||||||
public final class LookBehavior extends Behavior implements ILookBehavior, Helper {
|
public final class LookBehavior extends Behavior implements ILookBehavior, Helper {
|
||||||
|
|
||||||
public static final LookBehavior INSTANCE = new LookBehavior();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Target's values are as follows:
|
* Target's values are as follows:
|
||||||
* <p>
|
* <p>
|
||||||
@ -49,7 +46,9 @@ public final class LookBehavior extends Behavior implements ILookBehavior, Helpe
|
|||||||
*/
|
*/
|
||||||
private float lastYaw;
|
private float lastYaw;
|
||||||
|
|
||||||
private LookBehavior() {}
|
public LookBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTarget(Rotation target, boolean force) {
|
public void updateTarget(Rotation target, boolean force) {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.behavior;
|
package baritone.behavior;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.behavior.IMemoryBehavior;
|
import baritone.api.behavior.IMemoryBehavior;
|
||||||
import baritone.api.behavior.memory.IRememberedInventory;
|
import baritone.api.behavior.memory.IRememberedInventory;
|
||||||
import baritone.api.cache.IWorldData;
|
import baritone.api.cache.IWorldData;
|
||||||
@ -43,11 +44,11 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public final class MemoryBehavior extends Behavior implements IMemoryBehavior, Helper {
|
public final class MemoryBehavior extends Behavior implements IMemoryBehavior, Helper {
|
||||||
|
|
||||||
public static MemoryBehavior INSTANCE = new MemoryBehavior();
|
|
||||||
|
|
||||||
private final Map<IWorldData, WorldDataContainer> worldDataContainers = new HashMap<>();
|
private final Map<IWorldData, WorldDataContainer> worldDataContainers = new HashMap<>();
|
||||||
|
|
||||||
private MemoryBehavior() {}
|
public MemoryBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void onPlayerUpdate(PlayerUpdateEvent event) {
|
public synchronized void onPlayerUpdate(PlayerUpdateEvent event) {
|
||||||
|
@ -46,14 +46,14 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public final class MineBehavior extends Behavior implements IMineBehavior, Helper {
|
public final class MineBehavior extends Behavior implements IMineBehavior, Helper {
|
||||||
|
|
||||||
public static final MineBehavior INSTANCE = new MineBehavior();
|
|
||||||
|
|
||||||
private List<Block> mining;
|
private List<Block> mining;
|
||||||
private List<BlockPos> knownOreLocations;
|
private List<BlockPos> knownOreLocations;
|
||||||
private BlockPos branchPoint;
|
private BlockPos branchPoint;
|
||||||
private int desiredQuantity;
|
private int desiredQuantity;
|
||||||
|
|
||||||
private MineBehavior() {}
|
public MineBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick(TickEvent event) {
|
public void onTick(TickEvent event) {
|
||||||
@ -82,7 +82,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
addNearby();
|
addNearby();
|
||||||
}
|
}
|
||||||
updateGoal();
|
updateGoal();
|
||||||
PathingBehavior.INSTANCE.revalidateGoal();
|
((PathingBehavior) baritone.getPathingBehavior()).revalidateGoal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGoal() {
|
private void updateGoal() {
|
||||||
@ -93,7 +93,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
if (!locs.isEmpty()) {
|
if (!locs.isEmpty()) {
|
||||||
List<BlockPos> locs2 = prune(new ArrayList<>(locs), mining, 64);
|
List<BlockPos> locs2 = prune(new ArrayList<>(locs), mining, 64);
|
||||||
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
|
// can't reassign locs, gotta make a new var locs2, because we use it in a lambda right here, and variables you use in a lambda must be effectively final
|
||||||
PathingBehavior.INSTANCE.setGoalAndPath(new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)));
|
((PathingBehavior) baritone.getPathingBehavior()).setGoalAndPath(new GoalComposite(locs2.stream().map(loc -> coalesce(loc, locs2)).toArray(Goal[]::new)));
|
||||||
knownOreLocations = locs;
|
knownOreLocations = locs;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -104,11 +104,11 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
// only in non-Xray mode (aka legit mode) do we do this
|
// only in non-Xray mode (aka legit mode) do we do this
|
||||||
if (branchPoint == null) {
|
if (branchPoint == null) {
|
||||||
int y = Baritone.settings().legitMineYLevel.get();
|
int y = Baritone.settings().legitMineYLevel.get();
|
||||||
if (!PathingBehavior.INSTANCE.isPathing() && playerFeet().y == y) {
|
if (!baritone.getPathingBehavior().isPathing() && playerFeet().y == y) {
|
||||||
// cool, path is over and we are at desired y
|
// cool, path is over and we are at desired y
|
||||||
branchPoint = playerFeet();
|
branchPoint = playerFeet();
|
||||||
} else {
|
} else {
|
||||||
PathingBehavior.INSTANCE.setGoalAndPath(new GoalYLevel(y));
|
((PathingBehavior) baritone.getPathingBehavior()).setGoalAndPath(new GoalYLevel(y));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
// TODO mine 1x1 shafts to either side
|
// TODO mine 1x1 shafts to either side
|
||||||
branchPoint = branchPoint.north(10);
|
branchPoint = branchPoint.north(10);
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoalAndPath(new GoalBlock(branchPoint));
|
((PathingBehavior) baritone.getPathingBehavior()).setGoalAndPath(new GoalBlock(branchPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void rescan() {
|
private void rescan() {
|
||||||
@ -197,12 +197,12 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
knownOreLocations = prune(knownOreLocations, mining, 64);
|
knownOreLocations = prune(knownOreLocations, mining, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<BlockPos> prune(List<BlockPos> locs2, List<Block> mining, int max) {
|
public List<BlockPos> prune(List<BlockPos> locs2, List<Block> mining, int max) {
|
||||||
List<BlockPos> locs = locs2
|
List<BlockPos> locs = locs2
|
||||||
.stream()
|
.stream()
|
||||||
|
|
||||||
// remove any that are within loaded chunks that aren't actually what we want
|
// remove any that are within loaded chunks that aren't actually what we want
|
||||||
.filter(pos -> MineBehavior.INSTANCE.world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock()))
|
.filter(pos -> world().getChunk(pos) instanceof EmptyChunk || mining.contains(BlockStateInterface.get(pos).getBlock()))
|
||||||
|
|
||||||
// remove any that are implausible to mine (encased in bedrock, or touching lava)
|
// remove any that are implausible to mine (encased in bedrock, or touching lava)
|
||||||
.filter(MineBehavior::plausibleToBreak)
|
.filter(MineBehavior::plausibleToBreak)
|
||||||
@ -247,6 +247,6 @@ public final class MineBehavior extends Behavior implements IMineBehavior, Helpe
|
|||||||
@Override
|
@Override
|
||||||
public void cancel() {
|
public void cancel() {
|
||||||
mine(0, (String[]) null);
|
mine(0, (String[]) null);
|
||||||
PathingBehavior.INSTANCE.cancel();
|
baritone.getPathingBehavior().cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,6 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
|
public final class PathingBehavior extends Behavior implements IPathingBehavior, Helper {
|
||||||
|
|
||||||
public static final PathingBehavior INSTANCE = new PathingBehavior();
|
|
||||||
|
|
||||||
private PathExecutor current;
|
private PathExecutor current;
|
||||||
private PathExecutor next;
|
private PathExecutor next;
|
||||||
|
|
||||||
@ -62,7 +60,9 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
|||||||
|
|
||||||
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
|
private final LinkedBlockingQueue<PathEvent> toDispatch = new LinkedBlockingQueue<>();
|
||||||
|
|
||||||
private PathingBehavior() {}
|
public PathingBehavior(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
|
}
|
||||||
|
|
||||||
private void queuePathEvent(PathEvent event) {
|
private void queuePathEvent(PathEvent event) {
|
||||||
toDispatch.add(event);
|
toDispatch.add(event);
|
||||||
|
@ -24,7 +24,6 @@ import baritone.api.utils.BetterBlockPos;
|
|||||||
import baritone.api.utils.Rotation;
|
import baritone.api.utils.Rotation;
|
||||||
import baritone.api.utils.RotationUtils;
|
import baritone.api.utils.RotationUtils;
|
||||||
import baritone.api.utils.VecUtils;
|
import baritone.api.utils.VecUtils;
|
||||||
import baritone.behavior.LookBehavior;
|
|
||||||
import baritone.utils.BlockBreakHelper;
|
import baritone.utils.BlockBreakHelper;
|
||||||
import baritone.utils.BlockStateInterface;
|
import baritone.utils.BlockStateInterface;
|
||||||
import baritone.utils.Helper;
|
import baritone.utils.Helper;
|
||||||
@ -126,7 +125,7 @@ public abstract class Movement implements IMovement, Helper, MovementHelper {
|
|||||||
|
|
||||||
// If the movement target has to force the new rotations, or we aren't using silent move, then force the rotations
|
// If the movement target has to force the new rotations, or we aren't using silent move, then force the rotations
|
||||||
latestState.getTarget().getRotation().ifPresent(rotation ->
|
latestState.getTarget().getRotation().ifPresent(rotation ->
|
||||||
LookBehavior.INSTANCE.updateTarget(
|
Baritone.INSTANCE.getLookBehavior().updateTarget(
|
||||||
rotation,
|
rotation,
|
||||||
latestState.getTarget().hasToForceRotations()));
|
latestState.getTarget().hasToForceRotations()));
|
||||||
|
|
||||||
|
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
package baritone.utils;
|
package baritone.utils;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.event.events.TickEvent;
|
import baritone.api.event.events.TickEvent;
|
||||||
import baritone.api.event.listener.AbstractGameEventListener;
|
import baritone.api.event.listener.AbstractGameEventListener;
|
||||||
import baritone.api.pathing.goals.Goal;
|
import baritone.api.pathing.goals.Goal;
|
||||||
import baritone.api.pathing.goals.GoalBlock;
|
import baritone.api.pathing.goals.GoalBlock;
|
||||||
import baritone.behavior.PathingBehavior;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiMainMenu;
|
import net.minecraft.client.gui.GuiMainMenu;
|
||||||
import net.minecraft.client.settings.GameSettings;
|
import net.minecraft.client.settings.GameSettings;
|
||||||
@ -105,8 +105,8 @@ public class BaritoneAutoTest implements AbstractGameEventListener, Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup Baritone's pathing goal and (if needed) begin pathing
|
// Setup Baritone's pathing goal and (if needed) begin pathing
|
||||||
PathingBehavior.INSTANCE.setGoal(GOAL);
|
Baritone.INSTANCE.getPathingBehavior().setGoal(GOAL);
|
||||||
PathingBehavior.INSTANCE.path();
|
Baritone.INSTANCE.getPathingBehavior().path();
|
||||||
|
|
||||||
// If we have reached our goal, print a message and safely close the game
|
// If we have reached our goal, print a message and safely close the game
|
||||||
if (GOAL.isInGoal(playerFeet())) {
|
if (GOAL.isInGoal(playerFeet())) {
|
||||||
|
@ -26,7 +26,6 @@ import baritone.api.pathing.movement.ActionCosts;
|
|||||||
import baritone.api.utils.RayTraceUtils;
|
import baritone.api.utils.RayTraceUtils;
|
||||||
import baritone.api.utils.SettingsUtil;
|
import baritone.api.utils.SettingsUtil;
|
||||||
import baritone.behavior.Behavior;
|
import baritone.behavior.Behavior;
|
||||||
import baritone.behavior.FollowBehavior;
|
|
||||||
import baritone.behavior.MineBehavior;
|
import baritone.behavior.MineBehavior;
|
||||||
import baritone.behavior.PathingBehavior;
|
import baritone.behavior.PathingBehavior;
|
||||||
import baritone.cache.ChunkPacker;
|
import baritone.cache.ChunkPacker;
|
||||||
@ -48,14 +47,8 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class ExampleBaritoneControl extends Behavior implements Helper {
|
public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||||
|
|
||||||
public static ExampleBaritoneControl INSTANCE = new ExampleBaritoneControl();
|
public ExampleBaritoneControl(Baritone baritone) {
|
||||||
|
super(baritone);
|
||||||
private ExampleBaritoneControl() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initAndRegister() {
|
|
||||||
Baritone.INSTANCE.registerBehavior(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -77,6 +70,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
|
|
||||||
public boolean runCommand(String msg0) {
|
public boolean runCommand(String msg0) {
|
||||||
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
String msg = msg0.toLowerCase(Locale.US).trim(); // don't reassign the argument LOL
|
||||||
|
PathingBehavior pathingBehavior = (PathingBehavior) baritone.getPathingBehavior();
|
||||||
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
List<Settings.Setting<Boolean>> toggleable = Baritone.settings().getAllValuesByType(Boolean.class);
|
||||||
for (Settings.Setting<Boolean> setting : toggleable) {
|
for (Settings.Setting<Boolean> setting : toggleable) {
|
||||||
if (msg.equalsIgnoreCase(setting.getName())) {
|
if (msg.equalsIgnoreCase(setting.getName())) {
|
||||||
@ -158,16 +152,16 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("unable to parse integer " + ex);
|
logDirect("unable to parse integer " + ex);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
pathingBehavior.setGoal(goal);
|
||||||
logDirect("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("path")) {
|
if (msg.equals("path")) {
|
||||||
if (!PathingBehavior.INSTANCE.path()) {
|
if (!pathingBehavior.path()) {
|
||||||
if (PathingBehavior.INSTANCE.getGoal() == null) {
|
if (pathingBehavior.getGoal() == null) {
|
||||||
logDirect("No goal.");
|
logDirect("No goal.");
|
||||||
} else {
|
} else {
|
||||||
if (PathingBehavior.INSTANCE.getGoal().isInGoal(playerFeet())) {
|
if (pathingBehavior.getGoal().isInGoal(playerFeet())) {
|
||||||
logDirect("Already in goal");
|
logDirect("Already in goal");
|
||||||
} else {
|
} else {
|
||||||
logDirect("Currently executing a path. Please cancel it first.");
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
@ -194,23 +188,23 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("axis")) {
|
if (msg.equals("axis")) {
|
||||||
PathingBehavior.INSTANCE.setGoal(new GoalAxis());
|
pathingBehavior.setGoal(new GoalAxis());
|
||||||
PathingBehavior.INSTANCE.path();
|
pathingBehavior.path();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("cancel") || msg.equals("stop")) {
|
if (msg.equals("cancel") || msg.equals("stop")) {
|
||||||
MineBehavior.INSTANCE.cancel();
|
baritone.getMineBehavior().cancel();
|
||||||
FollowBehavior.INSTANCE.cancel();
|
baritone.getFollowBehavior().cancel();
|
||||||
PathingBehavior.INSTANCE.cancel();
|
pathingBehavior.cancel();
|
||||||
logDirect("ok canceled");
|
logDirect("ok canceled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("forcecancel")) {
|
if (msg.equals("forcecancel")) {
|
||||||
MineBehavior.INSTANCE.cancel();
|
baritone.getMineBehavior().cancel();
|
||||||
FollowBehavior.INSTANCE.cancel();
|
baritone.getFollowBehavior().cancel();
|
||||||
PathingBehavior.INSTANCE.cancel();
|
pathingBehavior.cancel();
|
||||||
AbstractNodeCostSearch.forceCancel();
|
AbstractNodeCostSearch.forceCancel();
|
||||||
PathingBehavior.INSTANCE.forceCancel();
|
pathingBehavior.forceCancel();
|
||||||
logDirect("ok force canceled");
|
logDirect("ok force canceled");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -220,7 +214,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("invert")) {
|
if (msg.equals("invert")) {
|
||||||
Goal goal = PathingBehavior.INSTANCE.getGoal();
|
Goal goal = pathingBehavior.getGoal();
|
||||||
BlockPos runAwayFrom;
|
BlockPos runAwayFrom;
|
||||||
if (goal instanceof GoalXZ) {
|
if (goal instanceof GoalXZ) {
|
||||||
runAwayFrom = new BlockPos(((GoalXZ) goal).getX(), 0, ((GoalXZ) goal).getZ());
|
runAwayFrom = new BlockPos(((GoalXZ) goal).getX(), 0, ((GoalXZ) goal).getZ());
|
||||||
@ -231,13 +225,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Inverting goal of player feet");
|
logDirect("Inverting goal of player feet");
|
||||||
runAwayFrom = playerFeet();
|
runAwayFrom = playerFeet();
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) {
|
pathingBehavior.setGoal(new GoalRunAway(1, runAwayFrom) {
|
||||||
@Override
|
@Override
|
||||||
public boolean isInGoal(BlockPos pos) {
|
public boolean isInGoal(BlockPos pos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!PathingBehavior.INSTANCE.path()) {
|
if (!pathingBehavior.path()) {
|
||||||
logDirect("Currently executing a path. Please cancel it first.");
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -259,7 +253,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("Not found");
|
logDirect("Not found");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
FollowBehavior.INSTANCE.follow(toFollow.get());
|
baritone.getFollowBehavior().follow(toFollow.get());
|
||||||
logDirect("Following " + toFollow.get());
|
logDirect("Following " + toFollow.get());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -291,7 +285,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
int quantity = Integer.parseInt(blockTypes[1]);
|
int quantity = Integer.parseInt(blockTypes[1]);
|
||||||
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
|
Block block = ChunkPacker.stringToBlock(blockTypes[0]);
|
||||||
Objects.requireNonNull(block);
|
Objects.requireNonNull(block);
|
||||||
MineBehavior.INSTANCE.mine(quantity, block);
|
baritone.getMineBehavior().mine(quantity, block);
|
||||||
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
logDirect("Will mine " + quantity + " " + blockTypes[0]);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
} catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException ex) {}
|
||||||
@ -302,14 +296,14 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
MineBehavior.INSTANCE.mine(0, blockTypes);
|
baritone.getMineBehavior().mine(0, blockTypes);
|
||||||
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
logDirect("Started mining blocks of type " + Arrays.toString(blockTypes));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.startsWith("thisway")) {
|
if (msg.startsWith("thisway")) {
|
||||||
try {
|
try {
|
||||||
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim()));
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
pathingBehavior.setGoal(goal);
|
||||||
logDirect("Goal: " + goal);
|
logDirect("Goal: " + goal);
|
||||||
} catch (NumberFormatException ex) {
|
} catch (NumberFormatException ex) {
|
||||||
logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double.");
|
logDirect("Error unable to parse '" + msg.substring(7).trim() + "' to a double.");
|
||||||
@ -378,13 +372,13 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<BlockPos> locs = MineBehavior.INSTANCE.searchWorld(Collections.singletonList(block), 64);
|
List<BlockPos> locs = ((MineBehavior) baritone.getMineBehavior()).searchWorld(Collections.singletonList(block), 64);
|
||||||
if (locs.isEmpty()) {
|
if (locs.isEmpty()) {
|
||||||
logDirect("No locations for " + mining + " known, cancelling");
|
logDirect("No locations for " + mining + " known, cancelling");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
pathingBehavior.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new)));
|
||||||
PathingBehavior.INSTANCE.path();
|
pathingBehavior.path();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -395,8 +389,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
pathingBehavior.setGoal(goal);
|
||||||
if (!PathingBehavior.INSTANCE.path() && !goal.isInGoal(playerFeet())) {
|
if (!pathingBehavior.path() && !goal.isInGoal(playerFeet())) {
|
||||||
logDirect("Currently executing a path. Please cancel it first.");
|
logDirect("Currently executing a path. Please cancel it first.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -408,10 +402,10 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
// for some reason the default spawnpoint is underground sometimes
|
// for some reason the default spawnpoint is underground sometimes
|
||||||
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ());
|
||||||
logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal);
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
pathingBehavior.setGoal(goal);
|
||||||
} else {
|
} else {
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
pathingBehavior.setGoal(goal);
|
||||||
logDirect("Set goal to most recent bed " + goal);
|
logDirect("Set goal to most recent bed " + goal);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -427,8 +421,8 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
logDirect("home not saved");
|
logDirect("home not saved");
|
||||||
} else {
|
} else {
|
||||||
Goal goal = new GoalBlock(waypoint.getLocation());
|
Goal goal = new GoalBlock(waypoint.getLocation());
|
||||||
PathingBehavior.INSTANCE.setGoal(goal);
|
pathingBehavior.setGoal(goal);
|
||||||
PathingBehavior.INSTANCE.path();
|
pathingBehavior.path();
|
||||||
logDirect("Going to saved home " + goal);
|
logDirect("Going to saved home " + goal);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -451,7 +445,7 @@ public class ExampleBaritoneControl extends Behavior implements Helper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (msg.equals("pause")) {
|
if (msg.equals("pause")) {
|
||||||
boolean enabled = PathingBehavior.INSTANCE.toggle();
|
boolean enabled = pathingBehavior.toggle();
|
||||||
logDirect("Pathing Behavior has " + (enabled ? "resumed" : "paused") + ".");
|
logDirect("Pathing Behavior has " + (enabled ? "resumed" : "paused") + ".");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user