Merge branch '1.15.2' into 1.16.5
This commit is contained in:
@@ -20,8 +20,9 @@ package baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.behavior.IBehavior;
|
||||
import baritone.api.event.listener.IEventBus;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.process.IBaritoneProcess;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.behavior.*;
|
||||
import baritone.cache.WorldProvider;
|
||||
@@ -33,16 +34,17 @@ import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.GuiClick;
|
||||
import baritone.utils.InputOverrideHandler;
|
||||
import baritone.utils.PathingControlManager;
|
||||
import baritone.utils.player.PrimaryPlayerContext;
|
||||
import baritone.utils.player.BaritonePlayerContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@@ -50,87 +52,101 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
public class Baritone implements IBaritone {
|
||||
|
||||
private static ThreadPoolExecutor threadPool;
|
||||
private static File dir;
|
||||
private static final ThreadPoolExecutor threadPool;
|
||||
|
||||
static {
|
||||
threadPool = new ThreadPoolExecutor(4, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>());
|
||||
|
||||
dir = new File(Minecraft.getInstance().gameDir, "baritone");
|
||||
if (!Files.exists(dir.toPath())) {
|
||||
try {
|
||||
Files.createDirectories(dir.toPath());
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
private GameEventHandler gameEventHandler;
|
||||
private final Minecraft mc;
|
||||
private final Path directory;
|
||||
|
||||
private PathingBehavior pathingBehavior;
|
||||
private LookBehavior lookBehavior;
|
||||
private InventoryBehavior inventoryBehavior;
|
||||
private WaypointBehavior waypointBehavior;
|
||||
private InputOverrideHandler inputOverrideHandler;
|
||||
private final GameEventHandler gameEventHandler;
|
||||
|
||||
private FollowProcess followProcess;
|
||||
private MineProcess mineProcess;
|
||||
private GetToBlockProcess getToBlockProcess;
|
||||
private CustomGoalProcess customGoalProcess;
|
||||
private BuilderProcess builderProcess;
|
||||
private ExploreProcess exploreProcess;
|
||||
private BackfillProcess backfillProcess;
|
||||
private FarmProcess farmProcess;
|
||||
private final PathingBehavior pathingBehavior;
|
||||
private final LookBehavior lookBehavior;
|
||||
private final InventoryBehavior inventoryBehavior;
|
||||
private final InputOverrideHandler inputOverrideHandler;
|
||||
|
||||
private PathingControlManager pathingControlManager;
|
||||
private SelectionManager selectionManager;
|
||||
private CommandManager commandManager;
|
||||
private final FollowProcess followProcess;
|
||||
private final MineProcess mineProcess;
|
||||
private final GetToBlockProcess getToBlockProcess;
|
||||
private final CustomGoalProcess customGoalProcess;
|
||||
private final BuilderProcess builderProcess;
|
||||
private final ExploreProcess exploreProcess;
|
||||
private final FarmProcess farmProcess;
|
||||
private final InventoryPauserProcess inventoryPauserProcess;
|
||||
|
||||
private IPlayerContext playerContext;
|
||||
private WorldProvider worldProvider;
|
||||
private final PathingControlManager pathingControlManager;
|
||||
private final SelectionManager selectionManager;
|
||||
private final CommandManager commandManager;
|
||||
|
||||
private final IPlayerContext playerContext;
|
||||
private final WorldProvider worldProvider;
|
||||
|
||||
public BlockStateInterface bsi;
|
||||
|
||||
Baritone() {
|
||||
Baritone(Minecraft mc) {
|
||||
this.mc = mc;
|
||||
this.gameEventHandler = new GameEventHandler(this);
|
||||
|
||||
this.directory = mc.gameDir.toPath().resolve("baritone");
|
||||
if (!Files.exists(this.directory)) {
|
||||
try {
|
||||
Files.createDirectories(this.directory);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
// Define this before behaviors try and get it, or else it will be null and the builds will fail!
|
||||
this.playerContext = PrimaryPlayerContext.INSTANCE;
|
||||
this.playerContext = new BaritonePlayerContext(this, mc);
|
||||
|
||||
{
|
||||
// the Behavior constructor calls baritone.registerBehavior(this) so this populates the behaviors arraylist
|
||||
pathingBehavior = new PathingBehavior(this);
|
||||
lookBehavior = new LookBehavior(this);
|
||||
inventoryBehavior = new InventoryBehavior(this);
|
||||
inputOverrideHandler = new InputOverrideHandler(this);
|
||||
waypointBehavior = new WaypointBehavior(this);
|
||||
this.lookBehavior = this.registerBehavior(LookBehavior::new);
|
||||
this.pathingBehavior = this.registerBehavior(PathingBehavior::new);
|
||||
this.inventoryBehavior = this.registerBehavior(InventoryBehavior::new);
|
||||
this.inputOverrideHandler = this.registerBehavior(InputOverrideHandler::new);
|
||||
this.registerBehavior(WaypointBehavior::new);
|
||||
}
|
||||
|
||||
this.pathingControlManager = new PathingControlManager(this);
|
||||
{
|
||||
this.pathingControlManager.registerProcess(followProcess = new FollowProcess(this));
|
||||
this.pathingControlManager.registerProcess(mineProcess = new MineProcess(this));
|
||||
this.pathingControlManager.registerProcess(customGoalProcess = new CustomGoalProcess(this)); // very high iq
|
||||
this.pathingControlManager.registerProcess(getToBlockProcess = new GetToBlockProcess(this));
|
||||
this.pathingControlManager.registerProcess(builderProcess = new BuilderProcess(this));
|
||||
this.pathingControlManager.registerProcess(exploreProcess = new ExploreProcess(this));
|
||||
this.pathingControlManager.registerProcess(backfillProcess = new BackfillProcess(this));
|
||||
this.pathingControlManager.registerProcess(farmProcess = new FarmProcess(this));
|
||||
this.followProcess = this.registerProcess(FollowProcess::new);
|
||||
this.mineProcess = this.registerProcess(MineProcess::new);
|
||||
this.customGoalProcess = this.registerProcess(CustomGoalProcess::new); // very high iq
|
||||
this.getToBlockProcess = this.registerProcess(GetToBlockProcess::new);
|
||||
this.builderProcess = this.registerProcess(BuilderProcess::new);
|
||||
this.exploreProcess = this.registerProcess(ExploreProcess::new);
|
||||
this.farmProcess = this.registerProcess(FarmProcess::new);
|
||||
this.inventoryPauserProcess = this.registerProcess(InventoryPauserProcess::new);
|
||||
this.registerProcess(BackfillProcess::new);
|
||||
}
|
||||
|
||||
this.worldProvider = new WorldProvider();
|
||||
this.worldProvider = new WorldProvider(this);
|
||||
this.selectionManager = new SelectionManager(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
}
|
||||
|
||||
public void registerBehavior(IBehavior behavior) {
|
||||
this.gameEventHandler.registerEventListener(behavior);
|
||||
}
|
||||
|
||||
public <T extends IBehavior> T registerBehavior(Function<Baritone, T> constructor) {
|
||||
final T behavior = constructor.apply(this);
|
||||
this.registerBehavior(behavior);
|
||||
return behavior;
|
||||
}
|
||||
|
||||
public <T extends IBaritoneProcess> T registerProcess(Function<Baritone, T> constructor) {
|
||||
final T behavior = constructor.apply(this);
|
||||
this.pathingControlManager.registerProcess(behavior);
|
||||
return behavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingControlManager getPathingControlManager() {
|
||||
return this.pathingControlManager;
|
||||
}
|
||||
|
||||
public void registerBehavior(Behavior behavior) {
|
||||
this.gameEventHandler.registerEventListener(behavior);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputOverrideHandler getInputOverrideHandler() {
|
||||
return this.inputOverrideHandler;
|
||||
@@ -170,6 +186,7 @@ public class Baritone implements IBaritone {
|
||||
return this.lookBehavior;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExploreProcess getExploreProcess() {
|
||||
return this.exploreProcess;
|
||||
}
|
||||
@@ -179,10 +196,15 @@ public class Baritone implements IBaritone {
|
||||
return this.mineProcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FarmProcess getFarmProcess() {
|
||||
return this.farmProcess;
|
||||
}
|
||||
|
||||
public InventoryPauserProcess getInventoryPauserProcess() {
|
||||
return this.inventoryPauserProcess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingBehavior getPathingBehavior() {
|
||||
return this.pathingBehavior;
|
||||
@@ -213,19 +235,19 @@ public class Baritone implements IBaritone {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
Helper.mc.execute(() -> Helper.mc.displayGuiScreen(new GuiClick()));
|
||||
mc.execute(() -> mc.displayGuiScreen(new GuiClick()));
|
||||
} catch (Exception ignored) {}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public Path getDirectory() {
|
||||
return this.directory;
|
||||
}
|
||||
|
||||
public static Settings settings() {
|
||||
return BaritoneAPI.getSettings();
|
||||
}
|
||||
|
||||
public static File getDir() {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static Executor getExecutor() {
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,15 @@ import baritone.api.IBaritoneProvider;
|
||||
import baritone.api.cache.IWorldScanner;
|
||||
import baritone.api.command.ICommandSystem;
|
||||
import baritone.api.schematic.ISchematicSystem;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.cache.FasterWorldScanner;
|
||||
import baritone.command.CommandSystem;
|
||||
import baritone.command.ExampleBaritoneControl;
|
||||
import baritone.utils.schematic.SchematicSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
@@ -36,30 +38,45 @@ import java.util.List;
|
||||
*/
|
||||
public final class BaritoneProvider implements IBaritoneProvider {
|
||||
|
||||
private final Baritone primary;
|
||||
private final List<IBaritone> all;
|
||||
private final List<IBaritone> allView;
|
||||
|
||||
{
|
||||
this.primary = new Baritone();
|
||||
this.all = Collections.singletonList(this.primary);
|
||||
public BaritoneProvider() {
|
||||
this.all = new CopyOnWriteArrayList<>();
|
||||
this.allView = Collections.unmodifiableList(this.all);
|
||||
|
||||
// Setup chat control, just for the primary instance
|
||||
new ExampleBaritoneControl(this.primary);
|
||||
final Baritone primary = (Baritone) this.createBaritone(Minecraft.getInstance());
|
||||
primary.registerBehavior(ExampleBaritoneControl::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBaritone getPrimaryBaritone() {
|
||||
return primary;
|
||||
return this.all.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IBaritone> getAllBaritones() {
|
||||
return all;
|
||||
return this.allView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized IBaritone createBaritone(Minecraft minecraft) {
|
||||
IBaritone baritone = this.getBaritoneForMinecraft(minecraft);
|
||||
if (baritone == null) {
|
||||
this.all.add(baritone = new Baritone(minecraft));
|
||||
}
|
||||
return baritone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean destroyBaritone(IBaritone baritone) {
|
||||
return baritone != this.getPrimaryBaritone() && this.all.remove(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldScanner getWorldScanner() {
|
||||
return WorldScanner.INSTANCE;
|
||||
return FasterWorldScanner.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,6 +35,5 @@ public class Behavior implements IBehavior {
|
||||
protected Behavior(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
this.ctx = baritone.getPlayerContext();
|
||||
baritone.registerBehavior(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package baritone.behavior;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.utils.ToolSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
@@ -37,7 +38,10 @@ import java.util.OptionalInt;
|
||||
import java.util.Random;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public final class InventoryBehavior extends Behavior {
|
||||
public final class InventoryBehavior extends Behavior implements Helper {
|
||||
|
||||
int ticksSinceLastInventoryMove;
|
||||
int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt
|
||||
|
||||
public InventoryBehavior(Baritone baritone) {
|
||||
super(baritone);
|
||||
@@ -55,20 +59,28 @@ public final class InventoryBehavior extends Behavior {
|
||||
// we have a crafting table or a chest or something open
|
||||
return;
|
||||
}
|
||||
ticksSinceLastInventoryMove++;
|
||||
if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory
|
||||
swapWithHotBar(firstValidThrowaway(), 8);
|
||||
requestSwapWithHotBar(firstValidThrowaway(), 8);
|
||||
}
|
||||
int pick = bestToolAgainst(Blocks.STONE, PickaxeItem.class);
|
||||
if (pick >= 9) {
|
||||
swapWithHotBar(pick, 0);
|
||||
requestSwapWithHotBar(pick, 0);
|
||||
}
|
||||
if (lastTickRequestedMove != null) {
|
||||
logDebug("Remembering to move " + lastTickRequestedMove[0] + " " + lastTickRequestedMove[1] + " from a previous tick");
|
||||
requestSwapWithHotBar(lastTickRequestedMove[0], lastTickRequestedMove[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public void attemptToPutOnHotbar(int inMainInvy, Predicate<Integer> disallowedHotbar) {
|
||||
public boolean attemptToPutOnHotbar(int inMainInvy, Predicate<Integer> disallowedHotbar) {
|
||||
OptionalInt destination = getTempHotbarSlot(disallowedHotbar);
|
||||
if (destination.isPresent()) {
|
||||
swapWithHotBar(inMainInvy, destination.getAsInt());
|
||||
if (!requestSwapWithHotBar(inMainInvy, destination.getAsInt())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public OptionalInt getTempHotbarSlot(Predicate<Integer> disallowedHotbar) {
|
||||
@@ -92,8 +104,20 @@ public final class InventoryBehavior extends Behavior {
|
||||
return OptionalInt.of(candidates.get(new Random().nextInt(candidates.size())));
|
||||
}
|
||||
|
||||
private void swapWithHotBar(int inInventory, int inHotbar) {
|
||||
private boolean requestSwapWithHotBar(int inInventory, int inHotbar) {
|
||||
lastTickRequestedMove = new int[]{inInventory, inHotbar};
|
||||
if (ticksSinceLastInventoryMove < Baritone.settings().ticksBetweenInventoryMoves.value) {
|
||||
logDebug("Inventory move requested but delaying " + ticksSinceLastInventoryMove + " " + Baritone.settings().ticksBetweenInventoryMoves.value);
|
||||
return false;
|
||||
}
|
||||
if (Baritone.settings().inventoryMoveOnlyIfStationary.value && !baritone.getInventoryPauserProcess().stationaryForInventoryMove()) {
|
||||
logDebug("Inventory move requested but delaying until stationary");
|
||||
return false;
|
||||
}
|
||||
ctx.playerController().windowClick(ctx.player().container.windowId, inInventory < 9 ? inInventory + 36 : inInventory, inHotbar, ClickType.SWAP, ctx.player());
|
||||
ticksSinceLastInventoryMove = 0;
|
||||
lastTickRequestedMove = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
private int firstValidThrowaway() { // TODO offhand idk
|
||||
@@ -195,8 +219,8 @@ public final class InventoryBehavior extends Behavior {
|
||||
if (allowInventory) {
|
||||
for (int i = 9; i < 36; i++) {
|
||||
if (desired.test(inv.get(i))) {
|
||||
swapWithHotBar(i, 7);
|
||||
if (select) {
|
||||
requestSwapWithHotBar(i, 7);
|
||||
p.inventory.currentItem = 7;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -20,44 +20,57 @@ package baritone.behavior;
|
||||
import baritone.Baritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.behavior.ILookBehavior;
|
||||
import baritone.api.event.events.PlayerUpdateEvent;
|
||||
import baritone.api.event.events.RotationMoveEvent;
|
||||
import baritone.api.behavior.look.IAimProcessor;
|
||||
import baritone.api.behavior.look.ITickableAimProcessor;
|
||||
import baritone.api.event.events.*;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.behavior.look.ForkableRandom;
|
||||
import net.minecraft.network.play.client.CPlayerPacket;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class LookBehavior extends Behavior implements ILookBehavior {
|
||||
|
||||
/**
|
||||
* Target's values are as follows:
|
||||
* The current look target, may be {@code null}.
|
||||
*/
|
||||
private Rotation target;
|
||||
private Target target;
|
||||
|
||||
/**
|
||||
* Whether or not rotations are currently being forced
|
||||
* The rotation known to the server. Returned by {@link #getEffectiveRotation()} for use in {@link IPlayerContext}.
|
||||
*/
|
||||
private boolean force;
|
||||
private Rotation serverRotation;
|
||||
|
||||
/**
|
||||
* The last player yaw angle. Used when free looking
|
||||
* The last player rotation. Used to restore the player's angle when using free look.
|
||||
*
|
||||
* @see Settings#freeLook
|
||||
*/
|
||||
private float lastYaw;
|
||||
private Rotation prevRotation;
|
||||
|
||||
private final AimProcessor processor;
|
||||
|
||||
public LookBehavior(Baritone baritone) {
|
||||
super(baritone);
|
||||
this.processor = new AimProcessor(baritone.getPlayerContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTarget(Rotation target, boolean force) {
|
||||
this.target = target;
|
||||
if (!force) {
|
||||
double rand = Math.random() - 0.5;
|
||||
if (Math.abs(rand) < 0.1) {
|
||||
rand *= 4;
|
||||
}
|
||||
this.target = new Rotation(this.target.getYaw() + (float) (rand * Baritone.settings().randomLooking113.value), this.target.getPitch());
|
||||
public void updateTarget(Rotation rotation, boolean blockInteract) {
|
||||
this.target = new Target(rotation, blockInteract);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAimProcessor getAimProcessor() {
|
||||
return this.processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(TickEvent event) {
|
||||
if (event.getType() == TickEvent.Type.IN) {
|
||||
this.processor.tick();
|
||||
}
|
||||
this.force = force || !Baritone.settings().freeLook.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,35 +78,30 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
||||
if (this.target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Whether or not we're going to silently set our angles
|
||||
boolean silent = Baritone.settings().antiCheatCompatibility.value && !this.force;
|
||||
|
||||
switch (event.getState()) {
|
||||
case PRE: {
|
||||
if (this.force) {
|
||||
ctx.player().rotationYaw = this.target.getYaw();
|
||||
float oldPitch = ctx.player().rotationPitch;
|
||||
float desiredPitch = this.target.getPitch();
|
||||
ctx.player().rotationPitch = desiredPitch;
|
||||
ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value;
|
||||
ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value;
|
||||
if (desiredPitch == oldPitch && !Baritone.settings().freeLook.value) {
|
||||
nudgeToLevel();
|
||||
}
|
||||
this.target = null;
|
||||
if (this.target.mode == Target.Mode.NONE) {
|
||||
// Just return for PRE, we still want to set target to null on POST
|
||||
return;
|
||||
}
|
||||
if (silent) {
|
||||
this.lastYaw = ctx.player().rotationYaw;
|
||||
ctx.player().rotationYaw = this.target.getYaw();
|
||||
if (this.target.mode == Target.Mode.SERVER) {
|
||||
this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch);
|
||||
}
|
||||
|
||||
final Rotation actual = this.processor.peekRotation(this.target.rotation);
|
||||
ctx.player().rotationYaw = actual.getYaw();
|
||||
ctx.player().rotationPitch = actual.getPitch();
|
||||
break;
|
||||
}
|
||||
case POST: {
|
||||
if (silent) {
|
||||
ctx.player().rotationYaw = this.lastYaw;
|
||||
this.target = null;
|
||||
// Reset the player's rotations back to their original values
|
||||
if (this.prevRotation != null) {
|
||||
ctx.player().rotationYaw = this.prevRotation.getYaw();
|
||||
ctx.player().rotationPitch = this.prevRotation.getPitch();
|
||||
this.prevRotation = null;
|
||||
}
|
||||
// The target is done being used for this game tick, so it can be invalidated
|
||||
this.target = null;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -101,34 +109,224 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSendPacket(PacketEvent event) {
|
||||
if (!(event.getPacket() instanceof CPlayerPacket)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CPlayerPacket packet = (CPlayerPacket) event.getPacket();
|
||||
if (packet instanceof CPlayerPacket.RotationPacket || packet instanceof CPlayerPacket.PositionRotationPacket) {
|
||||
this.serverRotation = new Rotation(packet.getYaw(0.0f), packet.getPitch(0.0f));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWorldEvent(WorldEvent event) {
|
||||
this.serverRotation = null;
|
||||
this.target = null;
|
||||
}
|
||||
|
||||
public void pig() {
|
||||
if (this.target != null) {
|
||||
ctx.player().rotationYaw = this.target.getYaw();
|
||||
final Rotation actual = this.processor.peekRotation(this.target.rotation);
|
||||
ctx.player().rotationYaw = actual.getYaw();
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Rotation> getEffectiveRotation() {
|
||||
if (Baritone.settings().freeLook.value) {
|
||||
return Optional.ofNullable(this.serverRotation);
|
||||
}
|
||||
// If freeLook isn't on, just defer to the player's actual rotations
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRotationMove(RotationMoveEvent event) {
|
||||
if (this.target != null) {
|
||||
final Rotation actual = this.processor.peekRotation(this.target.rotation);
|
||||
event.setYaw(actual.getYaw());
|
||||
event.setPitch(actual.getPitch());
|
||||
}
|
||||
}
|
||||
|
||||
event.setYaw(this.target.getYaw());
|
||||
private static final class AimProcessor extends AbstractAimProcessor {
|
||||
|
||||
// If we have antiCheatCompatibility on, we're going to use the target value later in onPlayerUpdate()
|
||||
// Also the type has to be MOTION_UPDATE because that is called after JUMP
|
||||
if (!Baritone.settings().antiCheatCompatibility.value && event.getType() == RotationMoveEvent.Type.MOTION_UPDATE && !this.force) {
|
||||
this.target = null;
|
||||
public AimProcessor(final IPlayerContext ctx) {
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rotation getPrevRotation() {
|
||||
// Implementation will use LookBehavior.serverRotation
|
||||
return ctx.playerRotations();
|
||||
}
|
||||
}
|
||||
|
||||
private static abstract class AbstractAimProcessor implements ITickableAimProcessor {
|
||||
|
||||
protected final IPlayerContext ctx;
|
||||
private final ForkableRandom rand;
|
||||
private double randomYawOffset;
|
||||
private double randomPitchOffset;
|
||||
|
||||
public AbstractAimProcessor(IPlayerContext ctx) {
|
||||
this.ctx = ctx;
|
||||
this.rand = new ForkableRandom();
|
||||
}
|
||||
|
||||
private AbstractAimProcessor(final AbstractAimProcessor source) {
|
||||
this.ctx = source.ctx;
|
||||
this.rand = source.rand.fork();
|
||||
this.randomYawOffset = source.randomYawOffset;
|
||||
this.randomPitchOffset = source.randomPitchOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Rotation peekRotation(final Rotation rotation) {
|
||||
final Rotation prev = this.getPrevRotation();
|
||||
|
||||
float desiredYaw = rotation.getYaw();
|
||||
float desiredPitch = rotation.getPitch();
|
||||
|
||||
// In other words, the target doesn't care about the pitch, so it used playerRotations().getPitch()
|
||||
// and it's safe to adjust it to a normal level
|
||||
if (desiredPitch == prev.getPitch()) {
|
||||
desiredPitch = nudgeToLevel(desiredPitch);
|
||||
}
|
||||
|
||||
desiredYaw += this.randomYawOffset;
|
||||
desiredPitch += this.randomPitchOffset;
|
||||
|
||||
return new Rotation(
|
||||
this.calculateMouseMove(prev.getYaw(), desiredYaw),
|
||||
this.calculateMouseMove(prev.getPitch(), desiredPitch)
|
||||
).clamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void tick() {
|
||||
// randomLooking
|
||||
this.randomYawOffset = (this.rand.nextDouble() - 0.5) * Baritone.settings().randomLooking.value;
|
||||
this.randomPitchOffset = (this.rand.nextDouble() - 0.5) * Baritone.settings().randomLooking.value;
|
||||
|
||||
// randomLooking113
|
||||
double random = this.rand.nextDouble() - 0.5;
|
||||
if (Math.abs(random) < 0.1) {
|
||||
random *= 4;
|
||||
}
|
||||
this.randomYawOffset += random * Baritone.settings().randomLooking113.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void advance(int ticks) {
|
||||
for (int i = 0; i < ticks; i++) {
|
||||
this.tick();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rotation nextRotation(final Rotation rotation) {
|
||||
final Rotation actual = this.peekRotation(rotation);
|
||||
this.tick();
|
||||
return actual;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ITickableAimProcessor fork() {
|
||||
return new AbstractAimProcessor(this) {
|
||||
|
||||
private Rotation prev = AbstractAimProcessor.this.getPrevRotation();
|
||||
|
||||
@Override
|
||||
public Rotation nextRotation(final Rotation rotation) {
|
||||
return (this.prev = super.nextRotation(rotation));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rotation getPrevRotation() {
|
||||
return this.prev;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected abstract Rotation getPrevRotation();
|
||||
|
||||
/**
|
||||
* Nudges the player's pitch to a regular level. (Between {@code -20} and {@code 10}, increments are by {@code 1})
|
||||
*/
|
||||
private float nudgeToLevel(float pitch) {
|
||||
if (pitch < -20) {
|
||||
return pitch + 1;
|
||||
} else if (pitch > 10) {
|
||||
return pitch - 1;
|
||||
}
|
||||
return pitch;
|
||||
}
|
||||
|
||||
// The game uses rotation = (float) ((double) rotation + delta) so we'll do that as well
|
||||
private float calculateMouseMove(float current, float target) {
|
||||
final double delta = target - current;
|
||||
final double deltaPx = angleToMouse(delta); // yes, even the mouse movements use double
|
||||
return (float) ((double) current + mouseToAngle(deltaPx));
|
||||
}
|
||||
|
||||
private double angleToMouse(double angleDelta) {
|
||||
final double minAngleChange = mouseToAngle(1);
|
||||
return Math.round(angleDelta / minAngleChange);
|
||||
}
|
||||
|
||||
private double mouseToAngle(double mouseDelta) {
|
||||
// casting float literals to double gets us the precise values used by mc
|
||||
final double f = ctx.minecraft().gameSettings.mouseSensitivity * (double) 0.6f + (double) 0.2f;
|
||||
return mouseDelta * f * f * f * 8.0d * 0.15d;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Target {
|
||||
|
||||
public final Rotation rotation;
|
||||
public final Mode mode;
|
||||
|
||||
public Target(Rotation rotation, boolean blockInteract) {
|
||||
this.rotation = rotation;
|
||||
this.mode = Mode.resolve(blockInteract);
|
||||
}
|
||||
|
||||
enum Mode {
|
||||
/**
|
||||
* Rotation will be set client-side and is visual to the player
|
||||
*/
|
||||
CLIENT,
|
||||
|
||||
/**
|
||||
* Rotation will be set server-side and is silent to the player
|
||||
*/
|
||||
SERVER,
|
||||
|
||||
/**
|
||||
* Rotation will remain unaffected on both the client and server
|
||||
*/
|
||||
NONE;
|
||||
|
||||
static Mode resolve(boolean blockInteract) {
|
||||
final Settings settings = Baritone.settings();
|
||||
final boolean antiCheat = settings.antiCheatCompatibility.value;
|
||||
final boolean blockFreeLook = settings.blockFreeLook.value;
|
||||
final boolean freeLook = settings.freeLook.value;
|
||||
|
||||
if (!freeLook) return CLIENT;
|
||||
if (!blockFreeLook && blockInteract) return CLIENT;
|
||||
|
||||
// Regardless of if antiCheatCompatibility is enabled, if a blockInteract is requested then the player
|
||||
// rotation needs to be set somehow, otherwise Baritone will halt since objectMouseOver() will just be
|
||||
// whatever the player is mousing over visually. Let's just settle for setting it silently.
|
||||
if (antiCheat || blockInteract) return SERVER;
|
||||
|
||||
// Pathing regularly without antiCheatCompatibility, don't set the player rotation
|
||||
return NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nudges the player's pitch to a regular level. (Between {@code -20} and {@code 10}, increments are by {@code 1})
|
||||
*/
|
||||
private void nudgeToLevel() {
|
||||
if (ctx.player().rotationPitch < -20) {
|
||||
ctx.player().rotationPitch++;
|
||||
} else if (ctx.player().rotationPitch > 10) {
|
||||
ctx.player().rotationPitch--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,11 +239,11 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior,
|
||||
if (current != null) {
|
||||
switch (event.getState()) {
|
||||
case PRE:
|
||||
lastAutoJump = mc.gameSettings.autoJump;
|
||||
mc.gameSettings.autoJump = false;
|
||||
lastAutoJump = ctx.minecraft().gameSettings.autoJump;
|
||||
ctx.minecraft().gameSettings.autoJump = false;
|
||||
break;
|
||||
case POST:
|
||||
mc.gameSettings.autoJump = lastAutoJump;
|
||||
ctx.minecraft().gameSettings.autoJump = lastAutoJump;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
85
src/main/java/baritone/behavior/look/ForkableRandom.java
Normal file
85
src/main/java/baritone/behavior/look/ForkableRandom.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.behavior.look;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.LongSupplier;
|
||||
|
||||
/**
|
||||
* Implementation of Xoroshiro256++
|
||||
* <p>
|
||||
* Extended to produce random double-precision floating point numbers, and allow copies to be spawned via {@link #fork},
|
||||
* which share the same internal state as the source object.
|
||||
*
|
||||
* @author Brady
|
||||
*/
|
||||
public final class ForkableRandom {
|
||||
|
||||
private static final double DOUBLE_UNIT = 0x1.0p-53;
|
||||
|
||||
private final long[] s;
|
||||
|
||||
public ForkableRandom() {
|
||||
this(System.nanoTime() ^ System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public ForkableRandom(long seedIn) {
|
||||
final AtomicLong seed = new AtomicLong(seedIn);
|
||||
final LongSupplier splitmix64 = () -> {
|
||||
long z = seed.addAndGet(0x9e3779b97f4a7c15L);
|
||||
z = (z ^ (z >>> 30)) * 0xbf58476d1ce4e5b9L;
|
||||
z = (z ^ (z >>> 27)) * 0x94d049bb133111ebL;
|
||||
return z ^ (z >>> 31);
|
||||
};
|
||||
this.s = new long[] {
|
||||
splitmix64.getAsLong(),
|
||||
splitmix64.getAsLong(),
|
||||
splitmix64.getAsLong(),
|
||||
splitmix64.getAsLong()
|
||||
};
|
||||
}
|
||||
|
||||
private ForkableRandom(long[] s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public double nextDouble() {
|
||||
return (this.next() >>> 11) * DOUBLE_UNIT;
|
||||
}
|
||||
|
||||
public long next() {
|
||||
final long result = rotl(this.s[0] + this.s[3], 23) + this.s[0];
|
||||
final long t = this.s[1] << 17;
|
||||
this.s[2] ^= this.s[0];
|
||||
this.s[3] ^= this.s[1];
|
||||
this.s[1] ^= this.s[2];
|
||||
this.s[0] ^= this.s[3];
|
||||
this.s[2] ^= t;
|
||||
this.s[3] = rotl(this.s[3], 45);
|
||||
return result;
|
||||
}
|
||||
|
||||
public ForkableRandom fork() {
|
||||
return new ForkableRandom(Arrays.copyOf(this.s, 4));
|
||||
}
|
||||
|
||||
private static long rotl(long x, int k) {
|
||||
return (x << k) | (x >>> (64 - k));
|
||||
}
|
||||
}
|
||||
@@ -309,6 +309,9 @@ public final class CachedWorld implements ICachedWorld, Helper {
|
||||
try {
|
||||
ChunkPos pos = toPackQueue.take();
|
||||
Chunk chunk = toPackMap.remove(pos);
|
||||
if (toPackQueue.size() > Baritone.settings().chunkPackerQueueMaxSize.value) {
|
||||
continue;
|
||||
}
|
||||
CachedChunk cached = ChunkPacker.pack(chunk);
|
||||
CachedWorld.this.updateCachedChunk(cached);
|
||||
//System.out.println("Processed chunk at " + chunk.x + "," + chunk.z);
|
||||
|
||||
261
src/main/java/baritone/cache/FasterWorldScanner.java
vendored
Normal file
261
src/main/java/baritone/cache/FasterWorldScanner.java
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.cache;
|
||||
|
||||
import baritone.api.cache.ICachedWorld;
|
||||
import baritone.api.cache.IWorldScanner;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.BlockOptionalMetaLookup;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.utils.accessor.IBitArray;
|
||||
import baritone.utils.accessor.IPalettedContainer;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.BitArray;
|
||||
import net.minecraft.util.ObjectIntIdentityMap;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.palette.IPalette;
|
||||
import net.minecraft.util.palette.PalettedContainer;
|
||||
import net.minecraft.util.palette.IdentityPalette;
|
||||
import net.minecraft.world.chunk.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum FasterWorldScanner implements IWorldScanner {
|
||||
INSTANCE;
|
||||
@Override
|
||||
public List<BlockPos> scanChunkRadius(IPlayerContext ctx, BlockOptionalMetaLookup filter, int max, int yLevelThreshold, int maxSearchRadius) {
|
||||
assert ctx.world() != null;
|
||||
if (maxSearchRadius < 0) {
|
||||
throw new IllegalArgumentException("chunkRange must be >= 0");
|
||||
}
|
||||
return scanChunksInternal(ctx, filter, getChunkRange(ctx.playerFeet().x >> 4, ctx.playerFeet().z >> 4, maxSearchRadius), max);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BlockPos> scanChunk(IPlayerContext ctx, BlockOptionalMetaLookup filter, ChunkPos pos, int max, int yLevelThreshold) {
|
||||
Stream<BlockPos> stream = scanChunkInternal(ctx, filter, pos);
|
||||
if (max >= 0) {
|
||||
stream = stream.limit(max);
|
||||
}
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repack(IPlayerContext ctx) {
|
||||
return this.repack(ctx, 40);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repack(IPlayerContext ctx, int range) {
|
||||
AbstractChunkProvider chunkProvider = ctx.world().getChunkProvider();
|
||||
ICachedWorld cachedWorld = ctx.worldData().getCachedWorld();
|
||||
|
||||
BetterBlockPos playerPos = ctx.playerFeet();
|
||||
|
||||
int playerChunkX = playerPos.getX() >> 4;
|
||||
int playerChunkZ = playerPos.getZ() >> 4;
|
||||
|
||||
int minX = playerChunkX - range;
|
||||
int minZ = playerChunkZ - range;
|
||||
int maxX = playerChunkX + range;
|
||||
int maxZ = playerChunkZ + range;
|
||||
|
||||
int queued = 0;
|
||||
for (int x = minX; x <= maxX; x++) {
|
||||
for (int z = minZ; z <= maxZ; z++) {
|
||||
Chunk chunk = chunkProvider.getChunk(x, z, false);
|
||||
|
||||
if (chunk != null && !chunk.isEmpty()) {
|
||||
queued++;
|
||||
cachedWorld.queueForPacking(chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queued;
|
||||
}
|
||||
|
||||
// ordered in a way that the closest blocks are generally first
|
||||
public static List<ChunkPos> getChunkRange(int centerX, int centerZ, int chunkRadius) {
|
||||
List<ChunkPos> chunks = new ArrayList<>();
|
||||
// spiral out
|
||||
chunks.add(new ChunkPos(centerX, centerZ));
|
||||
for (int i = 1; i < chunkRadius; i++) {
|
||||
for (int j = 0; j <= i; j++) {
|
||||
chunks.add(new ChunkPos(centerX - j, centerZ - i));
|
||||
if (j != 0) {
|
||||
chunks.add(new ChunkPos(centerX + j, centerZ - i));
|
||||
chunks.add(new ChunkPos(centerX - j, centerZ + i));
|
||||
}
|
||||
chunks.add(new ChunkPos(centerX + j, centerZ + i));
|
||||
if (j != i) {
|
||||
chunks.add(new ChunkPos(centerX - i, centerZ - j));
|
||||
chunks.add(new ChunkPos(centerX + i, centerZ - j));
|
||||
if (j != 0) {
|
||||
chunks.add(new ChunkPos(centerX - i, centerZ + j));
|
||||
chunks.add(new ChunkPos(centerX + i, centerZ + j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
private List<BlockPos> scanChunksInternal(IPlayerContext ctx, BlockOptionalMetaLookup lookup, List<ChunkPos> chunkPositions, int maxBlocks) {
|
||||
assert ctx.world() != null;
|
||||
try {
|
||||
// p -> scanChunkInternal(ctx, lookup, p)
|
||||
Stream<BlockPos> posStream = chunkPositions.parallelStream().flatMap(p -> scanChunkInternal(ctx, lookup, p));
|
||||
if (maxBlocks >= 0) {
|
||||
// WARNING: this can be expensive if maxBlocks is large...
|
||||
// see limit's javadoc
|
||||
posStream = posStream.limit(maxBlocks);
|
||||
}
|
||||
return posStream.collect(Collectors.toList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private Stream<BlockPos> scanChunkInternal(IPlayerContext ctx, BlockOptionalMetaLookup lookup, ChunkPos pos) {
|
||||
AbstractChunkProvider chunkProvider = ctx.world().getChunkProvider();
|
||||
// if chunk is not loaded, return empty stream
|
||||
if (!chunkProvider.chunkExists(pos.x, pos.z)) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
long chunkX = (long) pos.x << 4;
|
||||
long chunkZ = (long) pos.z << 4;
|
||||
|
||||
int playerSectionY = ctx.playerFeet().y >> 4;
|
||||
|
||||
return collectChunkSections(lookup, chunkProvider.getChunk(pos.x, pos.z, false), chunkX, chunkZ, playerSectionY).stream();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<BlockPos> collectChunkSections(BlockOptionalMetaLookup lookup, Chunk chunk, long chunkX, long chunkZ, int playerSection) {
|
||||
// iterate over sections relative to player
|
||||
List<BlockPos> blocks = new ArrayList<>();
|
||||
ChunkSection[] sections = chunk.getSections();
|
||||
int l = sections.length;
|
||||
int i = playerSection - 1;
|
||||
int j = playerSection;
|
||||
for (; i >= 0 || j < l; ++j, --i) {
|
||||
if (j < l) {
|
||||
visitSection(lookup, sections[j], blocks, chunkX, chunkZ);
|
||||
}
|
||||
if (i >= 0) {
|
||||
visitSection(lookup, sections[i], blocks, chunkX, chunkZ);
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
private void visitSection(BlockOptionalMetaLookup lookup, ChunkSection section, List<BlockPos> blocks, long chunkX, long chunkZ) {
|
||||
if (section == null || section.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PalettedContainer<BlockState> sectionContainer = section.getData();
|
||||
//this won't work if the PaletteStorage is of the type EmptyPaletteStorage
|
||||
if (((IPalettedContainer<BlockState>) sectionContainer).getStorage() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean[] isInFilter = getIncludedFilterIndices(lookup, ((IPalettedContainer<BlockState>) sectionContainer).getPalette());
|
||||
if (isInFilter.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
BitArray array = ((IPalettedContainer<BlockState>) section.getData()).getStorage();
|
||||
long[] longArray = array.getBackingLongArray();
|
||||
int arraySize = array.size();
|
||||
int bitsPerEntry = ((IBitArray) array).getBitsPerEntry();
|
||||
long maxEntryValue = ((IBitArray) array).getMaxEntryValue();
|
||||
|
||||
|
||||
int yOffset = section.getYLocation();
|
||||
|
||||
for (int i = 0, idx = 0; i < longArray.length && idx < arraySize; ++i) {
|
||||
long l = longArray[i];
|
||||
for (int offset = 0; offset <= (64 - bitsPerEntry) && idx < arraySize; offset += bitsPerEntry, ++idx) {
|
||||
int value = (int) ((l >> offset) & maxEntryValue);
|
||||
if (isInFilter[value]) {
|
||||
//noinspection DuplicateExpressions
|
||||
blocks.add(new BlockPos(
|
||||
chunkX + ((idx & 255) & 15),
|
||||
yOffset + (idx >> 8),
|
||||
chunkZ + ((idx & 255) >> 4)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean[] getIncludedFilterIndices(BlockOptionalMetaLookup lookup, IPalette<BlockState> palette) {
|
||||
boolean commonBlockFound = false;
|
||||
ObjectIntIdentityMap<BlockState> paletteMap = getPalette(palette);
|
||||
int size = paletteMap.size();
|
||||
|
||||
boolean[] isInFilter = new boolean[size];
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
BlockState state = paletteMap.getByValue(i);
|
||||
if (lookup.has(state)) {
|
||||
isInFilter[i] = true;
|
||||
commonBlockFound = true;
|
||||
} else {
|
||||
isInFilter[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!commonBlockFound) {
|
||||
return new boolean[0];
|
||||
}
|
||||
return isInFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* cheats to get the actual map of id -> blockstate from the various palette implementations
|
||||
*/
|
||||
private static ObjectIntIdentityMap<BlockState> getPalette(IPalette<BlockState> palette) {
|
||||
if (palette instanceof IdentityPalette) {
|
||||
return Block.BLOCK_STATE_IDS;
|
||||
} else {
|
||||
PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
|
||||
palette.write(buf);
|
||||
int size = buf.readVarInt();
|
||||
ObjectIntIdentityMap<BlockState> states = new ObjectIntIdentityMap<>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
BlockState state = Block.BLOCK_STATE_IDS.getByValue(buf.readVarInt());
|
||||
assert state != null;
|
||||
states.put(state, i);
|
||||
}
|
||||
return states;
|
||||
}
|
||||
}
|
||||
}
|
||||
174
src/main/java/baritone/cache/WorldProvider.java
vendored
174
src/main/java/baritone/cache/WorldProvider.java
vendored
@@ -19,100 +19,83 @@ package baritone.cache;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.IWorldProvider;
|
||||
import baritone.api.utils.Helper;
|
||||
import net.minecraft.server.integrated.IntegratedServer;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.FolderName;
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Brady
|
||||
* @since 8/4/2018
|
||||
*/
|
||||
public class WorldProvider implements IWorldProvider, Helper {
|
||||
public class WorldProvider implements IWorldProvider {
|
||||
|
||||
private static final Map<Path, WorldData> worldCache = new HashMap<>(); // this is how the bots have the same cached world
|
||||
private static final Map<Path, WorldData> worldCache = new HashMap<>();
|
||||
|
||||
private final Baritone baritone;
|
||||
private final IPlayerContext ctx;
|
||||
private WorldData currentWorld;
|
||||
private World mcWorld; // this let's us detect a broken load/unload hook
|
||||
|
||||
/**
|
||||
* This lets us detect a broken load/unload hook.
|
||||
* @see #detectAndHandleBrokenLoading()
|
||||
*/
|
||||
private World mcWorld;
|
||||
|
||||
public WorldProvider(Baritone baritone) {
|
||||
this.baritone = baritone;
|
||||
this.ctx = baritone.getPlayerContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final WorldData getCurrentWorld() {
|
||||
detectAndHandleBrokenLoading();
|
||||
this.detectAndHandleBrokenLoading();
|
||||
return this.currentWorld;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new world is initialized to discover the
|
||||
*
|
||||
* @param world The world's Registry Data
|
||||
* @param world The new world
|
||||
*/
|
||||
public final void initWorld(RegistryKey<World> world) {
|
||||
File directory;
|
||||
File readme;
|
||||
public final void initWorld(World world) {
|
||||
this.getSaveDirectories(world).ifPresent(dirs -> {
|
||||
final Path worldDir = dirs.getA();
|
||||
final Path readmeDir = dirs.getB();
|
||||
|
||||
IntegratedServer integratedServer = mc.getIntegratedServer();
|
||||
|
||||
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
|
||||
if (mc.isSingleplayer()) {
|
||||
directory = DimensionType.getDimensionFolder(world, integratedServer.func_240776_a_(FolderName.DOT).toFile());
|
||||
|
||||
// Gets the "depth" of this directory relative the the game's run directory, 2 is the location of the world
|
||||
if (directory.toPath().relativize(mc.gameDir.toPath()).getNameCount() != 2) {
|
||||
// subdirectory of the main save directory for this world
|
||||
directory = directory.getParentFile();
|
||||
}
|
||||
|
||||
directory = new File(directory, "baritone");
|
||||
readme = directory;
|
||||
} else { // Otherwise, the server must be remote...
|
||||
String folderName;
|
||||
if (mc.getCurrentServerData() != null) {
|
||||
folderName = mc.isConnectedToRealms() ? "realms" : mc.getCurrentServerData().serverIP;
|
||||
} else {
|
||||
//replaymod causes null currentServerData and false singleplayer.
|
||||
System.out.println("World seems to be a replay. Not loading Baritone cache.");
|
||||
currentWorld = null;
|
||||
mcWorld = mc.world;
|
||||
return;
|
||||
}
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
folderName = folderName.replace(":", "_");
|
||||
}
|
||||
directory = new File(Baritone.getDir(), folderName);
|
||||
readme = Baritone.getDir();
|
||||
}
|
||||
|
||||
// lol wtf is this baritone folder in my minecraft save?
|
||||
try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) {
|
||||
// good thing we have a readme
|
||||
out.write("https://github.com/cabaletta/baritone\n".getBytes());
|
||||
} catch (IOException ignored) {}
|
||||
|
||||
// We will actually store the world data in a subfolder: "DIM<id>"
|
||||
Path dir = DimensionType.getDimensionFolder(world, directory).toPath();
|
||||
if (!Files.exists(dir)) {
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
// lol wtf is this baritone folder in my minecraft save?
|
||||
// good thing we have a readme
|
||||
Files.createDirectories(readmeDir);
|
||||
Files.write(
|
||||
readmeDir.resolve("readme.txt"),
|
||||
"https://github.com/cabaletta/baritone\n".getBytes(StandardCharsets.US_ASCII)
|
||||
);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
System.out.println("Baritone world data dir: " + dir);
|
||||
synchronized (worldCache) {
|
||||
this.currentWorld = worldCache.computeIfAbsent(dir, d -> new WorldData(d, world));
|
||||
}
|
||||
this.mcWorld = mc.world;
|
||||
// We will actually store the world data in a subfolder: "DIM<id>"
|
||||
final Path worldDataDir = this.getWorldDataDirectory(worldDir, world);
|
||||
try {
|
||||
Files.createDirectories(worldDataDir);
|
||||
} catch (IOException ignored) {}
|
||||
|
||||
System.out.println("Baritone world data dir: " + worldDataDir);
|
||||
synchronized (worldCache) {
|
||||
this.currentWorld = worldCache.computeIfAbsent(worldDataDir, d -> new WorldData(d, world.getDimensionKey()));
|
||||
}
|
||||
this.mcWorld = ctx.world();
|
||||
});
|
||||
}
|
||||
|
||||
public final void closeWorld() {
|
||||
@@ -125,26 +108,71 @@ public class WorldProvider implements IWorldProvider, Helper {
|
||||
world.onClose();
|
||||
}
|
||||
|
||||
public final void ifWorldLoaded(Consumer<WorldData> currentWorldConsumer) {
|
||||
detectAndHandleBrokenLoading();
|
||||
if (this.currentWorld != null) {
|
||||
currentWorldConsumer.accept(this.currentWorld);
|
||||
}
|
||||
private Path getWorldDataDirectory(Path parent, World world) {
|
||||
return DimensionType.getDimensionFolder(world.getDimensionKey(), parent.toFile()).toPath();
|
||||
}
|
||||
|
||||
private final void detectAndHandleBrokenLoading() {
|
||||
if (this.mcWorld != mc.world) {
|
||||
/**
|
||||
* @param world The world
|
||||
* @return An {@link Optional} containing the world's baritone dir and readme dir, or {@link Optional#empty()} if
|
||||
* the world isn't valid for caching.
|
||||
*/
|
||||
private Optional<Tuple<Path, Path>> getSaveDirectories(World world) {
|
||||
Path worldDir;
|
||||
Path readmeDir;
|
||||
|
||||
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
|
||||
if (ctx.minecraft().isSingleplayer()) {
|
||||
worldDir = ctx.minecraft().getIntegratedServer().func_240776_a_(FolderName.DOT);
|
||||
|
||||
// Gets the "depth" of this directory relative to the game's run directory, 2 is the location of the world
|
||||
if (worldDir.relativize(ctx.minecraft().gameDir.toPath()).getNameCount() != 2) {
|
||||
// subdirectory of the main save directory for this world
|
||||
worldDir = worldDir.getParent();
|
||||
}
|
||||
|
||||
worldDir = worldDir.resolve("baritone");
|
||||
readmeDir = worldDir;
|
||||
} else { // Otherwise, the server must be remote...
|
||||
String folderName;
|
||||
final ServerData serverData = ctx.minecraft().getCurrentServerData();
|
||||
if (serverData != null) {
|
||||
folderName = ctx.minecraft().isConnectedToRealms() ? "realms" : serverData.serverIP;
|
||||
} else {
|
||||
//replaymod causes null currentServerData and false singleplayer.
|
||||
System.out.println("World seems to be a replay. Not loading Baritone cache.");
|
||||
currentWorld = null;
|
||||
mcWorld = ctx.world();
|
||||
return Optional.empty();
|
||||
}
|
||||
if (SystemUtils.IS_OS_WINDOWS) {
|
||||
folderName = folderName.replace(":", "_");
|
||||
}
|
||||
// TODO: This should probably be in "baritone/servers"
|
||||
worldDir = baritone.getDirectory().resolve(folderName);
|
||||
// Just write the readme to the baritone directory instead of each server save in it
|
||||
readmeDir = baritone.getDirectory();
|
||||
}
|
||||
|
||||
return Optional.of(new Tuple<>(worldDir, readmeDir));
|
||||
}
|
||||
|
||||
/**
|
||||
* Why does this exist instead of fixing the event? Some mods break the event. Lol.
|
||||
*/
|
||||
private void detectAndHandleBrokenLoading() {
|
||||
if (this.mcWorld != ctx.world()) {
|
||||
if (this.currentWorld != null) {
|
||||
System.out.println("mc.world unloaded unnoticed! Unloading Baritone cache now.");
|
||||
closeWorld();
|
||||
}
|
||||
if (mc.world != null) {
|
||||
if (ctx.world() != null) {
|
||||
System.out.println("mc.world loaded unnoticed! Loading Baritone cache now.");
|
||||
initWorld(mc.world.getDimensionKey());
|
||||
initWorld(ctx.world());
|
||||
}
|
||||
} else if (currentWorld == null && mc.world != null && (mc.isSingleplayer() || mc.getCurrentServerData() != null)) {
|
||||
} else if (this.currentWorld == null && ctx.world() != null && (ctx.minecraft().isSingleplayer() || ctx.minecraft().getCurrentServerData() != null)) {
|
||||
System.out.println("Retrying to load Baritone cache");
|
||||
initWorld(mc.world.getDimensionKey());
|
||||
initWorld(ctx.world());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
|
||||
package baritone.command;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.command.argument.ICommandArgument;
|
||||
import baritone.api.command.exception.CommandNotEnoughArgumentsException;
|
||||
@@ -27,9 +27,9 @@ import baritone.api.command.helpers.TabCompleteHelper;
|
||||
import baritone.api.command.manager.ICommandManager;
|
||||
import baritone.api.event.events.ChatEvent;
|
||||
import baritone.api.event.events.TabCompleteEvent;
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import baritone.behavior.Behavior;
|
||||
import baritone.command.argument.ArgConsumer;
|
||||
import baritone.command.argument.CommandArguments;
|
||||
import baritone.command.manager.CommandManager;
|
||||
@@ -49,14 +49,14 @@ import java.util.stream.Stream;
|
||||
|
||||
import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX;
|
||||
|
||||
public class ExampleBaritoneControl implements Helper, AbstractGameEventListener {
|
||||
public class ExampleBaritoneControl extends Behavior implements Helper {
|
||||
|
||||
private static final Settings settings = BaritoneAPI.getSettings();
|
||||
private final ICommandManager manager;
|
||||
|
||||
public ExampleBaritoneControl(IBaritone baritone) {
|
||||
public ExampleBaritoneControl(Baritone baritone) {
|
||||
super(baritone);
|
||||
this.manager = baritone.getCommandManager();
|
||||
baritone.getGameEventHandler().registerEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,7 +100,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
|
||||
return false;
|
||||
} else if (msg.trim().equalsIgnoreCase("orderpizza")) {
|
||||
try {
|
||||
((IGuiScreen) mc.currentScreen).openLinkInvoker(new URI("https://www.dominos.com/en/pages/order/"));
|
||||
((IGuiScreen) ctx.minecraft().currentScreen).openLinkInvoker(new URI("https://www.dominos.com/en/pages/order/"));
|
||||
} catch (NullPointerException | URISyntaxException ignored) {}
|
||||
return false;
|
||||
}
|
||||
@@ -124,7 +124,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
|
||||
}
|
||||
} else if (argc.hasExactlyOne()) {
|
||||
for (Settings.Setting setting : settings.allSettings) {
|
||||
if (SettingsUtil.javaOnlySetting(setting)) {
|
||||
if (setting.isJavaOnly()) {
|
||||
continue;
|
||||
}
|
||||
if (setting.getName().equalsIgnoreCase(pair.getA())) {
|
||||
@@ -177,7 +177,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
|
||||
.stream();
|
||||
}
|
||||
Settings.Setting setting = settings.byLowerName.get(argc.getString().toLowerCase(Locale.US));
|
||||
if (setting != null && !SettingsUtil.javaOnlySetting(setting)) {
|
||||
if (setting != null && !setting.isJavaOnly()) {
|
||||
if (setting.getValueClass() == Boolean.class) {
|
||||
TabCompleteHelper helper = new TabCompleteHelper();
|
||||
if ((Boolean) setting.value) {
|
||||
|
||||
@@ -380,6 +380,8 @@ public class ArgConsumer implements IArgConsumer {
|
||||
public <T extends IDatatype> Stream<String> tabCompleteDatatype(T datatype) {
|
||||
try {
|
||||
return datatype.tabComplete(this.context);
|
||||
} catch (CommandException ignored) {
|
||||
// NOP
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -35,10 +35,11 @@ import java.util.stream.Stream;
|
||||
|
||||
public class BuildCommand extends Command {
|
||||
|
||||
private static final File schematicsDir = new File(mc.gameDir, "schematics");
|
||||
private final File schematicsDir;
|
||||
|
||||
public BuildCommand(IBaritone baritone) {
|
||||
super(baritone, "build");
|
||||
this.schematicsDir = new File(baritone.getPlayerContext().minecraft().gameDir, "schematics");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,9 +21,7 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.api.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.pathing.goals.GoalBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -38,11 +36,7 @@ public class ComeCommand extends Command {
|
||||
@Override
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
args.requireMax(0);
|
||||
Entity entity = mc.getRenderViewEntity();
|
||||
if (entity == null) {
|
||||
throw new CommandInvalidStateException("render view entity is null");
|
||||
}
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(entity.getPosition()));
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(ctx.viewerPos()));
|
||||
logDirect("Coming");
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class ExploreFilterCommand extends Command {
|
||||
@Override
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
args.requireMax(2);
|
||||
File file = args.getDatatypePost(RelativeFile.INSTANCE, mc.gameDir.getAbsoluteFile().getParentFile());
|
||||
File file = args.getDatatypePost(RelativeFile.INSTANCE, ctx.minecraft().gameDir.getAbsoluteFile().getParentFile());
|
||||
boolean invert = false;
|
||||
if (args.hasAny()) {
|
||||
if (args.getString().equalsIgnoreCase("invert")) {
|
||||
@@ -65,7 +65,7 @@ public class ExploreFilterCommand extends Command {
|
||||
@Override
|
||||
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
|
||||
if (args.hasExactlyOne()) {
|
||||
return RelativeFile.tabComplete(args, RelativeFile.gameDir());
|
||||
return RelativeFile.tabComplete(args, RelativeFile.gameDir(ctx.minecraft()));
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class GoalCommand extends Command {
|
||||
}
|
||||
} else {
|
||||
args.requireMax(3);
|
||||
BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
|
||||
goalProcess.setGoal(goal);
|
||||
logDirect(String.format("Goal: %s", goal.toString()));
|
||||
|
||||
@@ -20,7 +20,6 @@ package baritone.command.defaults;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.datatypes.BlockById;
|
||||
import baritone.api.command.datatypes.ForBlockOptionalMeta;
|
||||
import baritone.api.command.datatypes.RelativeCoordinate;
|
||||
import baritone.api.command.datatypes.RelativeGoal;
|
||||
@@ -46,7 +45,7 @@ public class GotoCommand extends Command {
|
||||
// is no need to handle the case of empty arguments.
|
||||
if (args.peekDatatypeOrNull(RelativeCoordinate.INSTANCE) != null) {
|
||||
args.requireMax(3);
|
||||
BetterBlockPos origin = baritone.getPlayerContext().playerFeet();
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
Goal goal = args.getDatatypePost(RelativeGoal.INSTANCE, origin);
|
||||
logDirect(String.format("Going to: %s", goal.toString()));
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(goal);
|
||||
@@ -61,7 +60,8 @@ public class GotoCommand extends Command {
|
||||
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
|
||||
// since it's either a goal or a block, I don't think we can tab complete properly?
|
||||
// so just tab complete for the block variant
|
||||
return args.tabCompleteDatatype(BlockById.INSTANCE);
|
||||
args.requireMax(1);
|
||||
return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
|
||||
package baritone.command.defaults;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.datatypes.BlockById;
|
||||
import baritone.api.command.datatypes.ForBlockOptionalMeta;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.api.utils.BlockOptionalMeta;
|
||||
import baritone.cache.WorldScanner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -45,14 +44,18 @@ public class MineCommand extends Command {
|
||||
while (args.hasAny()) {
|
||||
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE));
|
||||
}
|
||||
WorldScanner.INSTANCE.repack(ctx);
|
||||
BaritoneAPI.getProvider().getWorldScanner().repack(ctx);
|
||||
logDirect(String.format("Mining %s", boms.toString()));
|
||||
baritone.getMineProcess().mine(quantity, boms.toArray(new BlockOptionalMeta[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
||||
return args.tabCompleteDatatype(BlockById.INSTANCE);
|
||||
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
|
||||
args.getAsOrDefault(Integer.class, 0);
|
||||
while (args.has(2)) {
|
||||
args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
|
||||
}
|
||||
return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
|
||||
package baritone.command.defaults;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.api.process.ICustomGoalProcess;
|
||||
import baritone.cache.WorldScanner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -38,7 +38,7 @@ public class PathCommand extends Command {
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
|
||||
args.requireMax(0);
|
||||
WorldScanner.INSTANCE.repack(ctx);
|
||||
BaritoneAPI.getProvider().getWorldScanner().repack(ctx);
|
||||
customGoalProcess.path();
|
||||
logDirect("Now pathing");
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ public class RenderCommand extends Command {
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
args.requireMax(0);
|
||||
BetterBlockPos origin = ctx.playerFeet();
|
||||
int renderDistance = (mc.gameSettings.renderDistanceChunks + 1) * 16;
|
||||
mc.worldRenderer.markBlockRangeForRenderUpdate(
|
||||
int renderDistance = (ctx.minecraft().gameSettings.renderDistanceChunks + 1) * 16;
|
||||
ctx.minecraft().worldRenderer.markBlockRangeForRenderUpdate(
|
||||
origin.x - renderDistance,
|
||||
0,
|
||||
origin.z - renderDistance,
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
package baritone.command.defaults;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.cache.WorldScanner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -36,7 +36,7 @@ public class RepackCommand extends Command {
|
||||
@Override
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
args.requireMax(0);
|
||||
logDirect(String.format("Queued %d chunks for repacking", WorldScanner.INSTANCE.repack(ctx)));
|
||||
logDirect(String.format("Queued %d chunks for repacking", BaritoneAPI.getProvider().getWorldScanner().repack(ctx)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.datatypes.ForAxis;
|
||||
import baritone.api.command.datatypes.ForBlockOptionalMeta;
|
||||
import baritone.api.command.datatypes.ForDirection;
|
||||
import baritone.api.command.datatypes.RelativeBlockPos;
|
||||
@@ -31,6 +32,8 @@ import baritone.api.command.helpers.TabCompleteHelper;
|
||||
import baritone.api.event.events.RenderEvent;
|
||||
import baritone.api.event.listener.AbstractGameEventListener;
|
||||
import baritone.api.schematic.*;
|
||||
import baritone.api.schematic.mask.shape.CylinderMask;
|
||||
import baritone.api.schematic.mask.shape.SphereMask;
|
||||
import baritone.api.selection.ISelection;
|
||||
import baritone.api.selection.ISelectionManager;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
@@ -49,6 +52,7 @@ import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SelCommand extends Command {
|
||||
@@ -71,7 +75,7 @@ public class SelCommand extends Command {
|
||||
float lineWidth = Baritone.settings().selectionLineWidth.value;
|
||||
boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value;
|
||||
IRenderer.startLines(color, opacity, lineWidth, ignoreDepth);
|
||||
IRenderer.drawAABB(event.getModelViewStack(), new AxisAlignedBB(pos1, pos1.add(1, 1, 1)));
|
||||
IRenderer.emitAABB(event.getModelViewStack(), new AxisAlignedBB(pos1, pos1.add(1, 1, 1)));
|
||||
IRenderer.endLines(ignoreDepth);
|
||||
}
|
||||
});
|
||||
@@ -87,7 +91,7 @@ public class SelCommand extends Command {
|
||||
if (action == Action.POS2 && pos1 == null) {
|
||||
throw new CommandInvalidStateException("Set pos1 first before using pos2");
|
||||
}
|
||||
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(mc.getRenderViewEntity().getPosition()) : ctx.playerFeet();
|
||||
BetterBlockPos playerPos = ctx.viewerPos();
|
||||
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
|
||||
args.requireMax(0);
|
||||
if (action == Action.POS1) {
|
||||
@@ -116,11 +120,13 @@ public class SelCommand extends Command {
|
||||
logDirect("Undid pos2");
|
||||
}
|
||||
}
|
||||
} else if (action == Action.SET || action == Action.WALLS || action == Action.SHELL || action == Action.CLEARAREA || action == Action.REPLACE) {
|
||||
} else if (action.isFillAction()) {
|
||||
BlockOptionalMeta type = action == Action.CLEARAREA
|
||||
? new BlockOptionalMeta(Blocks.AIR)
|
||||
: args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
|
||||
BlockOptionalMetaLookup replaces = null;
|
||||
|
||||
final BlockOptionalMetaLookup replaces; // Action.REPLACE
|
||||
final Direction.Axis alignment; // Action.(H)CYLINDER
|
||||
if (action == Action.REPLACE) {
|
||||
args.requireMin(1);
|
||||
List<BlockOptionalMeta> replacesList = new ArrayList<>();
|
||||
@@ -130,8 +136,15 @@ public class SelCommand extends Command {
|
||||
}
|
||||
type = args.getDatatypeFor(ForBlockOptionalMeta.INSTANCE);
|
||||
replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
|
||||
alignment = null;
|
||||
} else if (action == Action.CYLINDER || action == Action.HCYLINDER) {
|
||||
args.requireMax(1);
|
||||
alignment = args.hasAny() ? args.getDatatypeFor(ForAxis.INSTANCE) : Direction.Axis.Y;
|
||||
replaces = null;
|
||||
} else {
|
||||
args.requireMax(0);
|
||||
replaces = null;
|
||||
alignment = null;
|
||||
}
|
||||
ISelection[] selections = manager.getSelections();
|
||||
if (selections.length == 0) {
|
||||
@@ -150,20 +163,41 @@ public class SelCommand extends Command {
|
||||
for (ISelection selection : selections) {
|
||||
Vector3i size = selection.size();
|
||||
BetterBlockPos min = selection.min();
|
||||
ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
|
||||
if (action == Action.WALLS) {
|
||||
schematic = new WallsSchematic(schematic);
|
||||
} else if (action == Action.SHELL) {
|
||||
schematic = new ShellSchematic(schematic);
|
||||
} else if (action == Action.REPLACE) {
|
||||
schematic = new ReplaceSchematic(schematic, replaces);
|
||||
}
|
||||
|
||||
// Java 8 so no switch expressions 😿
|
||||
UnaryOperator<ISchematic> create = fill -> {
|
||||
final int w = fill.widthX();
|
||||
final int h = fill.heightY();
|
||||
final int l = fill.lengthZ();
|
||||
|
||||
switch (action) {
|
||||
case WALLS:
|
||||
return new WallsSchematic(fill);
|
||||
case SHELL:
|
||||
return new ShellSchematic(fill);
|
||||
case REPLACE:
|
||||
return new ReplaceSchematic(fill, replaces);
|
||||
case SPHERE:
|
||||
return MaskSchematic.create(fill, new SphereMask(w, h, l, true).compute());
|
||||
case HSPHERE:
|
||||
return MaskSchematic.create(fill, new SphereMask(w, h, l, false).compute());
|
||||
case CYLINDER:
|
||||
return MaskSchematic.create(fill, new CylinderMask(w, h, l, true, alignment).compute());
|
||||
case HCYLINDER:
|
||||
return MaskSchematic.create(fill, new CylinderMask(w, h, l, false, alignment).compute());
|
||||
default:
|
||||
// Silent fail
|
||||
return fill;
|
||||
}
|
||||
};
|
||||
|
||||
ISchematic schematic = create.apply(new FillSchematic(size.getX(), size.getY(), size.getZ(), type));
|
||||
composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
|
||||
}
|
||||
baritone.getBuilderProcess().build("Fill", composite, origin);
|
||||
logDirect("Filling now");
|
||||
} else if (action == Action.COPY) {
|
||||
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(mc.getRenderViewEntity().getPosition()) : ctx.playerFeet();
|
||||
BetterBlockPos playerPos = ctx.viewerPos();
|
||||
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
|
||||
args.requireMax(0);
|
||||
ISelection[] selections = manager.getSelections();
|
||||
@@ -204,7 +238,7 @@ public class SelCommand extends Command {
|
||||
clipboardOffset = origin.subtract(pos);
|
||||
logDirect("Selection copied");
|
||||
} else if (action == Action.PASTE) {
|
||||
BetterBlockPos playerPos = mc.getRenderViewEntity() != null ? BetterBlockPos.from(mc.getRenderViewEntity().getPosition()) : ctx.playerFeet();
|
||||
BetterBlockPos playerPos = ctx.viewerPos();
|
||||
BetterBlockPos pos = args.hasAny() ? args.getDatatypePost(RelativeBlockPos.INSTANCE, playerPos) : playerPos;
|
||||
args.requireMax(0);
|
||||
if (clipboard == null) {
|
||||
@@ -253,12 +287,15 @@ public class SelCommand extends Command {
|
||||
if (args.hasAtMost(3)) {
|
||||
return args.tabCompleteDatatype(RelativeBlockPos.INSTANCE);
|
||||
}
|
||||
} else if (action == Action.SET || action == Action.WALLS || action == Action.CLEARAREA || action == Action.REPLACE) {
|
||||
} else if (action.isFillAction()) {
|
||||
if (args.hasExactlyOne() || action == Action.REPLACE) {
|
||||
while (args.has(2)) {
|
||||
args.get();
|
||||
}
|
||||
return args.tabCompleteDatatype(ForBlockOptionalMeta.INSTANCE);
|
||||
} else if (args.hasExactly(2) && (action == Action.CYLINDER || action == Action.HCYLINDER)) {
|
||||
args.get();
|
||||
return args.tabCompleteDatatype(ForAxis.INSTANCE);
|
||||
}
|
||||
} else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
|
||||
if (args.hasExactlyOne()) {
|
||||
@@ -304,6 +341,10 @@ public class SelCommand extends Command {
|
||||
"> sel set/fill/s/f [block] - Completely fill all selections with a block.",
|
||||
"> sel walls/w [block] - Fill in the walls of the selection with a specified block.",
|
||||
"> sel shell/shl [block] - The same as walls, but fills in a ceiling and floor too.",
|
||||
"> sel sphere/sph [block] - Fills the selection with a sphere bounded by the sides.",
|
||||
"> sel hsphere/hsph [block] - The same as sphere, but hollow.",
|
||||
"> sel cylinder/cyl [block] <axis> - Fills the selection with a cylinder bounded by the sides, oriented about the given axis. (default=y)",
|
||||
"> sel hcylinder/hcyl [block] <axis> - The same as cylinder, but hollow.",
|
||||
"> sel cleararea/ca - Basically 'set air'.",
|
||||
"> sel replace/r <blocks...> <with> - Replaces blocks with another block.",
|
||||
"> sel copy/cp <x> <y> <z> - Copy the selected area relative to the specified or your position.",
|
||||
@@ -323,6 +364,10 @@ public class SelCommand extends Command {
|
||||
SET("set", "fill", "s", "f"),
|
||||
WALLS("walls", "w"),
|
||||
SHELL("shell", "shl"),
|
||||
SPHERE("sphere", "sph"),
|
||||
HSPHERE("hsphere", "hsph"),
|
||||
CYLINDER("cylinder", "cyl"),
|
||||
HCYLINDER("hcylinder", "hcyl"),
|
||||
CLEARAREA("cleararea", "ca"),
|
||||
REPLACE("replace", "r"),
|
||||
EXPAND("expand", "ex"),
|
||||
@@ -354,6 +399,18 @@ public class SelCommand extends Command {
|
||||
}
|
||||
return names.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public final boolean isFillAction() {
|
||||
return this == SET
|
||||
|| this == WALLS
|
||||
|| this == SHELL
|
||||
|| this == SPHERE
|
||||
|| this == HSPHERE
|
||||
|| this == CYLINDER
|
||||
|| this == HCYLINDER
|
||||
|| this == CLEARAREA
|
||||
|| this == REPLACE;
|
||||
}
|
||||
}
|
||||
|
||||
enum TransformTarget {
|
||||
|
||||
@@ -22,12 +22,14 @@ import baritone.api.IBaritone;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.command.Command;
|
||||
import baritone.api.command.argument.IArgConsumer;
|
||||
import baritone.api.command.datatypes.RelativeFile;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.api.command.exception.CommandInvalidStateException;
|
||||
import baritone.api.command.exception.CommandInvalidTypeException;
|
||||
import baritone.api.command.helpers.Paginator;
|
||||
import baritone.api.command.helpers.TabCompleteHelper;
|
||||
import baritone.api.utils.SettingsUtil;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
@@ -57,6 +59,18 @@ public class SetCommand extends Command {
|
||||
logDirect("Settings saved");
|
||||
return;
|
||||
}
|
||||
if (Arrays.asList("load", "ld").contains(arg)) {
|
||||
String file = SETTINGS_DEFAULT_NAME;
|
||||
if (args.hasAny()) {
|
||||
file = args.getString();
|
||||
}
|
||||
// reset to defaults
|
||||
SettingsUtil.modifiedSettings(Baritone.settings()).forEach(Settings.Setting::reset);
|
||||
// then load from disk
|
||||
SettingsUtil.readAndApply(Baritone.settings(), file);
|
||||
logDirect("Settings reloaded from " + file);
|
||||
return;
|
||||
}
|
||||
boolean viewModified = Arrays.asList("m", "mod", "modified").contains(arg);
|
||||
boolean viewAll = Arrays.asList("all", "l", "list").contains(arg);
|
||||
boolean paginate = viewModified || viewAll;
|
||||
@@ -65,7 +79,7 @@ public class SetCommand extends Command {
|
||||
args.requireMax(1);
|
||||
List<? extends Settings.Setting> toPaginate =
|
||||
(viewModified ? SettingsUtil.modifiedSettings(Baritone.settings()) : Baritone.settings().allSettings).stream()
|
||||
.filter(s -> !javaOnlySetting(s))
|
||||
.filter(s -> !s.isJavaOnly())
|
||||
.filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US)))
|
||||
.sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName()))
|
||||
.collect(Collectors.toList());
|
||||
@@ -129,7 +143,7 @@ public class SetCommand extends Command {
|
||||
if (setting == null) {
|
||||
throw new CommandInvalidTypeException(args.consumed(), "a valid setting");
|
||||
}
|
||||
if (javaOnlySetting(setting)) {
|
||||
if (setting.isJavaOnly()) {
|
||||
// ideally it would act as if the setting didn't exist
|
||||
// but users will see it in Settings.java or its javadoc
|
||||
// so at some point we have to tell them or they will see it as a bug
|
||||
@@ -209,6 +223,9 @@ public class SetCommand extends Command {
|
||||
.addToggleableSettings()
|
||||
.filterPrefix(args.getString())
|
||||
.stream();
|
||||
} else if (Arrays.asList("ld", "load").contains(arg.toLowerCase(Locale.US))) {
|
||||
// settings always use the directory of the main Minecraft instance
|
||||
return RelativeFile.tabComplete(args, Minecraft.getInstance().gameDir.toPath().resolve("baritone").toFile());
|
||||
}
|
||||
Settings.Setting setting = Baritone.settings().byLowerName.get(arg.toLowerCase(Locale.US));
|
||||
if (setting != null) {
|
||||
@@ -228,7 +245,7 @@ public class SetCommand extends Command {
|
||||
return new TabCompleteHelper()
|
||||
.addSettings()
|
||||
.sortAlphabetically()
|
||||
.prepend("list", "modified", "reset", "toggle", "save")
|
||||
.prepend("list", "modified", "reset", "toggle", "save", "load")
|
||||
.filterPrefix(arg)
|
||||
.stream();
|
||||
}
|
||||
@@ -255,7 +272,9 @@ public class SetCommand extends Command {
|
||||
"> set reset all - Reset ALL SETTINGS to their defaults",
|
||||
"> set reset <setting> - Reset a setting to its default",
|
||||
"> set toggle <setting> - Toggle a boolean setting",
|
||||
"> set save - Save all settings (this is automatic tho)"
|
||||
"> set save - Save all settings (this is automatic tho)",
|
||||
"> set load - Load settings from settings.txt",
|
||||
"> set load [filename] - Load settings from another file in your minecraft/baritone"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,13 +38,13 @@ public class SurfaceCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||
final BetterBlockPos playerPos = baritone.getPlayerContext().playerFeet();
|
||||
final int surfaceLevel = baritone.getPlayerContext().world().getSeaLevel();
|
||||
final int worldHeight = baritone.getPlayerContext().world().getHeight();
|
||||
final BetterBlockPos playerPos = ctx.playerFeet();
|
||||
final int surfaceLevel = ctx.world().getSeaLevel();
|
||||
final int worldHeight = ctx.world().getHeight();
|
||||
|
||||
// Ensure this command will not run if you are above the surface level and the block above you is air
|
||||
// As this would imply that your are already on the open surface
|
||||
if (playerPos.getY() > surfaceLevel && mc.world.getBlockState(playerPos.up()).getBlock() instanceof AirBlock) {
|
||||
if (playerPos.getY() > surfaceLevel && ctx.world().getBlockState(playerPos.up()).getBlock() instanceof AirBlock) {
|
||||
logDirect("Already at surface");
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class SurfaceCommand extends Command {
|
||||
for (int currentIteratedY = startingYPos; currentIteratedY < worldHeight; currentIteratedY++) {
|
||||
final BetterBlockPos newPos = new BetterBlockPos(playerPos.getX(), currentIteratedY, playerPos.getZ());
|
||||
|
||||
if (!(mc.world.getBlockState(newPos).getBlock() instanceof AirBlock) && newPos.getY() > playerPos.getY()) {
|
||||
if (!(ctx.world().getBlockState(newPos).getBlock() instanceof AirBlock) && newPos.getY() > playerPos.getY()) {
|
||||
Goal goal = new GoalBlock(newPos.up());
|
||||
logDirect(String.format("Going to: %s", goal.toString()));
|
||||
baritone.getCustomGoalProcess().setGoalAndPath(goal);
|
||||
|
||||
@@ -150,7 +150,11 @@ public class WaypointsCommand extends Command {
|
||||
logDirect(component);
|
||||
} else if (action == Action.CLEAR) {
|
||||
args.requireMax(1);
|
||||
IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
|
||||
String name = args.getString();
|
||||
IWaypoint.Tag tag = IWaypoint.Tag.getByName(name);
|
||||
if (tag == null) {
|
||||
throw new CommandInvalidStateException("Invalid tag, \"" + name + "\"");
|
||||
}
|
||||
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(this.baritone, tag);
|
||||
for (IWaypoint waypoint : waypoints) {
|
||||
ForWaypoints.waypoints(this.baritone).removeWaypoint(waypoint);
|
||||
|
||||
@@ -21,6 +21,7 @@ import baritone.Baritone;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.command.ICommand;
|
||||
import baritone.api.command.argument.ICommandArgument;
|
||||
import baritone.api.command.exception.CommandException;
|
||||
import baritone.api.command.exception.CommandUnhandledException;
|
||||
import baritone.api.command.exception.ICommandException;
|
||||
import baritone.api.command.helpers.TabCompleteHelper;
|
||||
@@ -153,9 +154,12 @@ public class CommandManager implements ICommandManager {
|
||||
private Stream<String> tabComplete() {
|
||||
try {
|
||||
return this.command.tabComplete(this.label, this.args);
|
||||
} catch (CommandException ignored) {
|
||||
// NOP
|
||||
} catch (Throwable t) {
|
||||
return Stream.empty();
|
||||
t.printStackTrace();
|
||||
}
|
||||
return Stream.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public final class GameEventHandler implements IEventBus, Helper {
|
||||
if (event.getState() == EventState.POST) {
|
||||
cache.closeWorld();
|
||||
if (event.getWorld() != null) {
|
||||
cache.initWorld(event.getWorld().getDimensionKey());
|
||||
cache.initWorld(event.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,8 @@ public class CalculationContext {
|
||||
this.baritone = baritone;
|
||||
ClientPlayerEntity player = baritone.getPlayerContext().player();
|
||||
this.world = baritone.getPlayerContext().world();
|
||||
this.worldData = (WorldData) baritone.getWorldProvider().getCurrentWorld();
|
||||
this.bsi = new BlockStateInterface(world, worldData, forUseOnAnotherThread);
|
||||
this.worldData = (WorldData) baritone.getPlayerContext().worldData();
|
||||
this.bsi = new BlockStateInterface(baritone.getPlayerContext(), forUseOnAnotherThread);
|
||||
this.toolSet = new ToolSet(player);
|
||||
this.hasThrowaway = Baritone.settings().allowPlace.value && ((Baritone) baritone).getInventoryBehavior().hasGenericThrowaway();
|
||||
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.value && PlayerInventory.isHotbar(player.inventory.getSlotFor(STACK_BUCKET_WATER)) && world.getDimensionKey() != World.THE_NETHER;
|
||||
|
||||
@@ -163,7 +163,7 @@ public abstract class Movement implements IMovement, MovementHelper {
|
||||
if (!MovementHelper.canWalkThrough(ctx, blockPos)) { // can't break air, so don't try
|
||||
somethingInTheWay = true;
|
||||
MovementHelper.switchToBestToolFor(ctx, BlockStateInterface.get(ctx, blockPos));
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), blockPos, ctx.playerController().getBlockReachDistance());
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx, blockPos, ctx.playerController().getBlockReachDistance());
|
||||
if (reachable.isPresent()) {
|
||||
Rotation rotTowardsBlock = reachable.get();
|
||||
state.setTarget(new MovementState.MovementTarget(rotTowardsBlock, true));
|
||||
|
||||
@@ -637,9 +637,9 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
|
||||
static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
|
||||
state.setTarget(new MovementTarget(
|
||||
new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||
RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||
VecUtils.getBlockPosCenter(pos),
|
||||
ctx.playerRotations()).getYaw(), ctx.player().rotationPitch),
|
||||
ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()),
|
||||
false
|
||||
)).setInput(Input.MOVE_FORWARD, true);
|
||||
}
|
||||
@@ -744,7 +744,8 @@ public interface MovementHelper extends ActionCosts, Helper {
|
||||
double faceY = (placeAt.getY() + against1.getY() + 0.5D) * 0.5D;
|
||||
double faceZ = (placeAt.getZ() + against1.getZ() + 1.0D) * 0.5D;
|
||||
Rotation place = RotationUtils.calcRotationFromVec3d(wouldSneak ? RayTraceUtils.inferSneakingEyePosition(ctx.player()) : ctx.playerHead(), new Vector3d(faceX, faceY, faceZ), ctx.playerRotations());
|
||||
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), place, ctx.playerController().getBlockReachDistance(), wouldSneak);
|
||||
Rotation actual = baritone.getLookBehavior().getAimProcessor().peekRotation(place);
|
||||
RayTraceResult res = RayTraceUtils.rayTraceTowards(ctx.player(), actual, ctx.playerController().getBlockReachDistance(), wouldSneak);
|
||||
if (res != null && res.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) res).getPos().equals(against1) && ((BlockRayTraceResult) res).getPos().offset(((BlockRayTraceResult) res).getFace()).equals(placeAt)) {
|
||||
state.setTarget(new MovementState.MovementTarget(place, true));
|
||||
found = true;
|
||||
|
||||
@@ -20,7 +20,6 @@ package baritone.pathing.movement.movements;
|
||||
import baritone.api.IBaritone;
|
||||
import baritone.api.pathing.movement.MovementStatus;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
@@ -31,10 +30,9 @@ import baritone.utils.BlockStateInterface;
|
||||
import baritone.utils.pathing.MutableMoveResult;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.FallingBlock;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.vector.Vector3d;
|
||||
|
||||
@@ -234,11 +232,10 @@ public class MovementDescend extends Movement {
|
||||
if (safeMode()) {
|
||||
double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83;
|
||||
double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83;
|
||||
ClientPlayerEntity player = ctx.player();
|
||||
state.setTarget(new MovementState.MovementTarget(
|
||||
new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||
RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||
new Vector3d(destX, dest.getY(), destZ),
|
||||
new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch),
|
||||
ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()),
|
||||
false
|
||||
)).setInput(Input.MOVE_FORWARD, true);
|
||||
return state;
|
||||
|
||||
@@ -188,9 +188,9 @@ public class MovementPillar extends Movement {
|
||||
boolean vine = fromDown.getBlock() == Blocks.VINE;
|
||||
Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
|
||||
VecUtils.getBlockPosCenter(positionToPlace),
|
||||
new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch));
|
||||
ctx.playerRotations());
|
||||
if (!ladder) {
|
||||
state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true));
|
||||
state.setTarget(new MovementState.MovementTarget(ctx.playerRotations().withPitch(rotation.getPitch()), true));
|
||||
}
|
||||
|
||||
boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;
|
||||
@@ -249,7 +249,7 @@ public class MovementPillar extends Movement {
|
||||
Block fr = frState.getBlock();
|
||||
// TODO: Evaluate usage of getMaterial().isReplaceable()
|
||||
if (!(fr instanceof AirBlock || frState.getMaterial().isReplaceable())) {
|
||||
RotationUtils.reachable(ctx.player(), src, ctx.playerController().getBlockReachDistance())
|
||||
RotationUtils.reachable(ctx, src, ctx.playerController().getBlockReachDistance())
|
||||
.map(rot -> new MovementState.MovementTarget(rot, true))
|
||||
.ifPresent(state::setTarget);
|
||||
state.setInput(Input.JUMP, false); // breaking is like 5x slower when you're jumping
|
||||
|
||||
@@ -30,10 +30,7 @@ import baritone.api.schematic.ISchematic;
|
||||
import baritone.api.schematic.IStaticSchematic;
|
||||
import baritone.api.schematic.SubstituteSchematic;
|
||||
import baritone.api.schematic.format.ISchematicFormat;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.Movement;
|
||||
@@ -163,7 +160,6 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
if (!format.isPresent()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ISchematic parsed;
|
||||
try {
|
||||
parsed = format.get().parse(new FileInputStream(schematic));
|
||||
@@ -171,20 +167,22 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Baritone.settings().mapArtMode.value) {
|
||||
parsed = new MapArtSchematic((IStaticSchematic) parsed);
|
||||
}
|
||||
|
||||
if (Baritone.settings().buildOnlySelection.value) {
|
||||
parsed = new SelectionSchematic(parsed, origin, baritone.getSelectionManager().getSelections());
|
||||
}
|
||||
|
||||
|
||||
parsed = applyMapArtAndSelection(origin, (IStaticSchematic) parsed);
|
||||
build(name, parsed, origin);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ISchematic applyMapArtAndSelection(Vector3i origin, IStaticSchematic parsed) {
|
||||
ISchematic schematic = parsed;
|
||||
if (Baritone.settings().mapArtMode.value) {
|
||||
schematic = new MapArtSchematic(parsed);
|
||||
}
|
||||
if (Baritone.settings().buildOnlySelection.value) {
|
||||
schematic = new SelectionSchematic(schematic, origin, baritone.getSelectionManager().getSelections());
|
||||
}
|
||||
return schematic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildOpenSchematic() {
|
||||
if (SchematicaHelper.isSchematicaPresent()) {
|
||||
@@ -218,7 +216,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
try {
|
||||
LitematicaSchematic schematic1 = new LitematicaSchematic(CompressedStreamTools.readCompressed(Files.newInputStream(LitematicaHelper.getSchematicFile(i).toPath())), false);
|
||||
Vector3i correctedOrigin = LitematicaHelper.getCorrectedOrigin(schematic1, i);
|
||||
LitematicaSchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i);
|
||||
ISchematic schematic2 = LitematicaHelper.blackMagicFuckery(schematic1, i);
|
||||
schematic2 = applyMapArtAndSelection(origin, (IStaticSchematic) schematic2);
|
||||
build(name, schematic2, correctedOrigin);
|
||||
} catch (Exception e) {
|
||||
logDirect("Schematic File could not be loaded.");
|
||||
@@ -282,7 +281,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
BlockState curr = bcc.bsi.get0(x, y, z);
|
||||
if (!(curr.getBlock() instanceof AirBlock) && !(curr.getBlock() == Blocks.WATER || curr.getBlock() == Blocks.LAVA) && !valid(curr, desired, false)) {
|
||||
BetterBlockPos pos = new BetterBlockPos(x, y, z);
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance());
|
||||
if (rot.isPresent()) {
|
||||
return Optional.of(new Tuple<>(pos, rot.get()));
|
||||
}
|
||||
@@ -361,9 +360,10 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
double placeY = placeAgainstPos.y + aabb.minY * placementMultiplier.y + aabb.maxY * (1 - placementMultiplier.y);
|
||||
double placeZ = placeAgainstPos.z + aabb.minZ * placementMultiplier.z + aabb.maxZ * (1 - placementMultiplier.z);
|
||||
Rotation rot = RotationUtils.calcRotationFromVec3d(RayTraceUtils.inferSneakingEyePosition(ctx.player()), new Vector3d(placeX, placeY, placeZ), ctx.playerRotations());
|
||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot, ctx.playerController().getBlockReachDistance(), true);
|
||||
Rotation actualRot = baritone.getLookBehavior().getAimProcessor().peekRotation(rot);
|
||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), actualRot, ctx.playerController().getBlockReachDistance(), true);
|
||||
if (result != null && result.getType() == RayTraceResult.Type.BLOCK && ((BlockRayTraceResult) result).getPos().equals(placeAgainstPos) && ((BlockRayTraceResult) result).getFace() == against.getOpposite()) {
|
||||
OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, rot);
|
||||
OptionalInt hotbar = hasAnyItemThatWouldPlace(toPlace, result, actualRot);
|
||||
if (hotbar.isPresent()) {
|
||||
return Optional.of(new Placement(hotbar.getAsInt(), placeAgainstPos, against.getOpposite(), rot));
|
||||
}
|
||||
@@ -573,7 +573,10 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
for (int i = 9; i < 36; i++) {
|
||||
for (BlockState desired : noValidHotbarOption) {
|
||||
if (valid(approxPlaceable.get(i), desired, true)) {
|
||||
baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains);
|
||||
if (!baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains)) {
|
||||
// awaiting inventory move, so pause
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
@@ -699,7 +702,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
incorrectPositions.forEach(pos -> {
|
||||
BlockState state = bcc.bsi.get0(pos);
|
||||
if (state.getBlock() instanceof AirBlock) {
|
||||
if (approxPlaceable.contains(bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
|
||||
if (containsBlockState(approxPlaceable, bcc.getSchematic(pos.x, pos.y, pos.z, state))) {
|
||||
placeable.add(pos);
|
||||
} else {
|
||||
BlockState desired = bcc.getSchematic(pos.x, pos.y, pos.z, state);
|
||||
@@ -772,6 +775,28 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
return primary.heuristic(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
JankyGoalComposite goal = (JankyGoalComposite) o;
|
||||
return Objects.equals(primary, goal.primary)
|
||||
&& Objects.equals(fallback, goal.fallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = -1701079641;
|
||||
hash = hash * 1196141026 + primary.hashCode();
|
||||
hash = hash * -80327868 + fallback.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JankyComposite Primary: " + primary + " Fallback: " + fallback;
|
||||
@@ -793,6 +818,21 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
// but any other adjacent works for breaking, including inside or below
|
||||
return super.isInGoal(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"GoalBreak{x=%s,y=%s,z=%s}",
|
||||
SettingsUtil.maybeCensor(x),
|
||||
SettingsUtil.maybeCensor(y),
|
||||
SettingsUtil.maybeCensor(z)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() * 1636324008;
|
||||
}
|
||||
}
|
||||
|
||||
private Goal placementGoal(BlockPos pos, BuilderCalculationContext bcc) {
|
||||
@@ -836,6 +876,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
this.allowSameLevel = allowSameLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInGoal(int x, int y, int z) {
|
||||
if (x == this.x && y == this.y && z == this.z) {
|
||||
return false;
|
||||
@@ -852,10 +893,41 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
return super.isInGoal(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(int x, int y, int z) {
|
||||
// prioritize lower y coordinates
|
||||
return this.y * 100 + super.heuristic(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GoalAdjacent goal = (GoalAdjacent) o;
|
||||
return allowSameLevel == goal.allowSameLevel
|
||||
&& Objects.equals(no, goal.no);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 806368046;
|
||||
hash = hash * 1412661222 + super.hashCode();
|
||||
hash = hash * 1730799370 + (int) BetterBlockPos.longHash(no.getX(), no.getY(), no.getZ());
|
||||
hash = hash * 260592149 + (allowSameLevel ? -1314802005 : 1565710265);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"GoalAdjacent{x=%s,y=%s,z=%s}",
|
||||
SettingsUtil.maybeCensor(x),
|
||||
SettingsUtil.maybeCensor(y),
|
||||
SettingsUtil.maybeCensor(z)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GoalPlace extends GoalBlock {
|
||||
@@ -864,10 +936,26 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
super(placeAt.up());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double heuristic(int x, int y, int z) {
|
||||
// prioritize lower y coordinates
|
||||
return this.y * 100 + super.heuristic(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() * 1910811835;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"GoalPlace{x=%s,y=%s,z=%s}",
|
||||
SettingsUtil.maybeCensor(x),
|
||||
SettingsUtil.maybeCensor(y),
|
||||
SettingsUtil.maybeCensor(z)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -941,6 +1029,15 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean containsBlockState(Collection<BlockState> states, BlockState state) {
|
||||
for (BlockState testee : states) {
|
||||
if (sameBlockstate(testee, state)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean valid(BlockState current, BlockState desired, boolean itemVerify) {
|
||||
if (desired == null) {
|
||||
return true;
|
||||
|
||||
@@ -18,8 +18,10 @@
|
||||
package baritone.process;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.pathing.goals.Goal;
|
||||
import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.pathing.goals.GoalGetToBlock;
|
||||
import baritone.api.pathing.goals.GoalComposite;
|
||||
import baritone.api.process.IFarmProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
@@ -28,7 +30,6 @@ import baritone.api.utils.RayTraceUtils;
|
||||
import baritone.api.utils.Rotation;
|
||||
import baritone.api.utils.RotationUtils;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
import net.minecraft.block.*;
|
||||
@@ -82,6 +83,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
Items.POTATO,
|
||||
Items.CARROT,
|
||||
Items.NETHER_WART,
|
||||
Items.COCOA_BEANS,
|
||||
Blocks.SUGAR_CANE.asItem(),
|
||||
Blocks.CACTUS.asItem()
|
||||
);
|
||||
@@ -115,6 +117,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
PUMPKIN(Blocks.PUMPKIN, state -> true),
|
||||
MELON(Blocks.MELON, state -> true),
|
||||
NETHERWART(Blocks.NETHER_WART, state -> state.get(NetherWartBlock.AGE) >= 3),
|
||||
COCOA(Blocks.COCOA, state -> state.get(CocoaBlock.AGE) >= 2),
|
||||
SUGARCANE(Blocks.SUGAR_CANE, null) {
|
||||
@Override
|
||||
public boolean readyToHarvest(World world, BlockPos pos, BlockState state) {
|
||||
@@ -172,6 +175,10 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
return !stack.isEmpty() && stack.getItem().equals(Items.NETHER_WART);
|
||||
}
|
||||
|
||||
private boolean isCocoa(ItemStack stack) {
|
||||
return !stack.isEmpty() && stack.getItem().equals(Items.COCOA_BEANS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
ArrayList<Block> scan = new ArrayList<>();
|
||||
@@ -180,13 +187,14 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
if (Baritone.settings().replantCrops.value) {
|
||||
scan.add(Blocks.FARMLAND);
|
||||
scan.add(Blocks.JUNGLE_LOG);
|
||||
if (Baritone.settings().replantNetherWart.value) {
|
||||
scan.add(Blocks.SOUL_SAND);
|
||||
}
|
||||
}
|
||||
|
||||
if (Baritone.settings().mineGoalUpdateInterval.value != 0 && tickCount++ % Baritone.settings().mineGoalUpdateInterval.value == 0) {
|
||||
Baritone.getExecutor().execute(() -> locations = WorldScanner.INSTANCE.scanChunkRadius(ctx, scan, 256, 10, 10));
|
||||
Baritone.getExecutor().execute(() -> locations = BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(ctx, scan, 256, 10, 10));
|
||||
}
|
||||
if (locations == null) {
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
@@ -195,6 +203,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
List<BlockPos> openFarmland = new ArrayList<>();
|
||||
List<BlockPos> bonemealable = new ArrayList<>();
|
||||
List<BlockPos> openSoulsand = new ArrayList<>();
|
||||
List<BlockPos> openLog = new ArrayList<>();
|
||||
for (BlockPos pos : locations) {
|
||||
//check if the target block is out of range.
|
||||
if (range != 0 && pos.distanceSq(center) > range * range) {
|
||||
@@ -215,6 +224,15 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (state.getBlock() == Blocks.JUNGLE_LOG) {
|
||||
for (Direction direction : Direction.Plane.HORIZONTAL) {
|
||||
if (ctx.world().getBlockState(pos.offset(direction)).getBlock() instanceof AirBlock) {
|
||||
openLog.add(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (readyForHarvest(ctx.world(), pos, state)) {
|
||||
toBreak.add(pos);
|
||||
continue;
|
||||
@@ -243,7 +261,7 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
both.addAll(openSoulsand);
|
||||
for (BlockPos pos : both) {
|
||||
boolean soulsand = openSoulsand.contains(pos);
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx.player(), pos, new Vector3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, new Vector3d(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5), ctx.playerController().getBlockReachDistance(), false);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, soulsand ? this::isNetherWart : this::isPlantable)) {
|
||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
|
||||
if (result instanceof BlockRayTraceResult && ((BlockRayTraceResult) result).getFace() == Direction.UP) {
|
||||
@@ -255,6 +273,25 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
}
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : openLog) {
|
||||
for (Direction dir : Direction.Plane.HORIZONTAL) {
|
||||
if (!(ctx.world().getBlockState(pos.offset(dir)).getBlock() instanceof AirBlock)) {
|
||||
continue;
|
||||
}
|
||||
Vector3d faceCenter = Vector3d.copyCentered(pos).add(Vector3d.copy(dir.getDirectionVec()).scale(0.5));
|
||||
Optional<Rotation> rot = RotationUtils.reachableOffset(ctx, pos, faceCenter, ctx.playerController().getBlockReachDistance(), false);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isCocoa)) {
|
||||
RayTraceResult result = RayTraceUtils.rayTraceTowards(ctx.player(), rot.get(), ctx.playerController().getBlockReachDistance());
|
||||
if (result instanceof BlockRayTraceResult && ((BlockRayTraceResult) result).getFace() == dir) {
|
||||
baritone.getLookBehavior().updateTarget(rot.get(), true);
|
||||
if (ctx.isLookingAt(pos)) {
|
||||
baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_RIGHT, true);
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (BlockPos pos : bonemealable) {
|
||||
Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
|
||||
if (rot.isPresent() && isSafeToCancel && baritone.getInventoryBehavior().throwaway(true, this::isBoneMeal)) {
|
||||
@@ -289,6 +326,15 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
|
||||
goalz.add(new GoalBlock(pos.up()));
|
||||
}
|
||||
}
|
||||
if (baritone.getInventoryBehavior().throwaway(false, this::isCocoa)) {
|
||||
for (BlockPos pos : openLog) {
|
||||
for (Direction direction : Direction.Plane.HORIZONTAL) {
|
||||
if (ctx.world().getBlockState(pos.offset(direction)).getBlock() instanceof AirBlock) {
|
||||
goalz.add(new GoalGetToBlock(pos.offset(direction)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (baritone.getInventoryBehavior().throwaway(false, this::isBoneMeal)) {
|
||||
for (BlockPos pos : bonemealable) {
|
||||
goalz.add(new GoalBlock(pos));
|
||||
|
||||
@@ -211,7 +211,7 @@ public final class GetToBlockProcess extends BaritoneProcessHelper implements IG
|
||||
|
||||
private boolean rightClick() {
|
||||
for (BlockPos pos : knownLocations) {
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance());
|
||||
Optional<Rotation> reachable = RotationUtils.reachable(ctx, pos, ctx.playerController().getBlockReachDistance());
|
||||
if (reachable.isPresent()) {
|
||||
baritone.getLookBehavior().updateTarget(reachable.get(), true);
|
||||
if (knownLocations.contains(ctx.getSelectedBlock().orElse(null))) {
|
||||
|
||||
90
src/main/java/baritone/process/InventoryPauserProcess.java
Normal file
90
src/main/java/baritone/process/InventoryPauserProcess.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.process;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.process.PathingCommand;
|
||||
import baritone.api.process.PathingCommandType;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
|
||||
public class InventoryPauserProcess extends BaritoneProcessHelper {
|
||||
|
||||
boolean pauseRequestedLastTick;
|
||||
boolean safeToCancelLastTick;
|
||||
int ticksOfStationary;
|
||||
|
||||
public InventoryPauserProcess(Baritone baritone) {
|
||||
super(baritone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
if (ctx.player() == null || ctx.world() == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private double motion() {
|
||||
return ctx.player().getMotion().mul(1, 0, 1).length();
|
||||
}
|
||||
|
||||
private boolean stationaryNow() {
|
||||
return motion() < 0.00001;
|
||||
}
|
||||
|
||||
public boolean stationaryForInventoryMove() {
|
||||
pauseRequestedLastTick = true;
|
||||
return safeToCancelLastTick && ticksOfStationary > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
|
||||
//logDebug(pauseRequestedLastTick + " " + safeToCancelLastTick + " " + ticksOfStationary);
|
||||
safeToCancelLastTick = isSafeToCancel;
|
||||
if (pauseRequestedLastTick) {
|
||||
pauseRequestedLastTick = false;
|
||||
if (stationaryNow()) {
|
||||
ticksOfStationary++;
|
||||
}
|
||||
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);
|
||||
}
|
||||
ticksOfStationary = 0;
|
||||
return new PathingCommand(null, PathingCommandType.DEFER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLostControl() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String displayName0() {
|
||||
return "inventory pauser";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double priority() {
|
||||
return 5.1; // slightly higher than backfill
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
package baritone.process;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.pathing.goals.*;
|
||||
import baritone.api.process.IMineProcess;
|
||||
import baritone.api.process.PathingCommand;
|
||||
@@ -25,7 +26,6 @@ import baritone.api.process.PathingCommandType;
|
||||
import baritone.api.utils.*;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.cache.CachedChunk;
|
||||
import baritone.cache.WorldScanner;
|
||||
import baritone.pathing.movement.CalculationContext;
|
||||
import baritone.pathing.movement.MovementHelper;
|
||||
import baritone.utils.BaritoneProcessHelper;
|
||||
@@ -320,6 +320,26 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
int zDiff = z - this.z;
|
||||
return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() * 393857768;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"GoalThreeBlocks{x=%s,y=%s,z=%s}",
|
||||
SettingsUtil.maybeCensor(x),
|
||||
SettingsUtil.maybeCensor(y),
|
||||
SettingsUtil.maybeCensor(z)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public List<BlockPos> droppedItemsScan() {
|
||||
@@ -363,7 +383,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
locs = prune(ctx, locs, filter, max, blacklist, dropped);
|
||||
|
||||
if (!untracked.isEmpty() || (Baritone.settings().extendCacheOnThreshold.value && locs.size() < max)) {
|
||||
locs.addAll(WorldScanner.INSTANCE.scanChunkRadius(
|
||||
locs.addAll(BaritoneAPI.getProvider().getWorldScanner().scanChunkRadius(
|
||||
ctx.getBaritone().getPlayerContext(),
|
||||
filter,
|
||||
max,
|
||||
@@ -398,7 +418,7 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
// is an x-ray and it'll get caught
|
||||
if (filter.has(bsi.get0(x, y, z))) {
|
||||
BlockPos pos = new BlockPos(x, y, z);
|
||||
if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx.player(), pos, fakedBlockReachDistance).isPresent()) {
|
||||
if ((Baritone.settings().legitMineIncludeDiagonals.value && knownOreLocations.stream().anyMatch(ore -> ore.distanceSq(pos) <= 2 /* sq means this is pytha dist <= sqrt(2) */)) || RotationUtils.reachable(ctx, pos, fakedBlockReachDistance).isPresent()) {
|
||||
knownOreLocations.add(pos);
|
||||
}
|
||||
}
|
||||
@@ -438,6 +458,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
|
||||
|
||||
.filter(pos -> pos.getY() >= Baritone.settings().minYLevelWhileMining.value)
|
||||
|
||||
.filter(pos -> pos.getY() <= Baritone.settings().maxYLevelWhileMining.value)
|
||||
|
||||
.filter(pos -> !blacklist.contains(pos))
|
||||
|
||||
.sorted(Comparator.comparingDouble(ctx.getBaritone().getPlayerContext().player().getPosition()::distanceSq))
|
||||
|
||||
@@ -24,27 +24,27 @@ public class SelectionRenderer implements IRenderer, AbstractGameEventListener {
|
||||
boolean ignoreDepth = settings.renderSelectionIgnoreDepth.value;
|
||||
float lineWidth = settings.selectionLineWidth.value;
|
||||
|
||||
if (!settings.renderSelection.value) {
|
||||
if (!settings.renderSelection.value || selections.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
IRenderer.startLines(settings.colorSelection.value, opacity, lineWidth, ignoreDepth);
|
||||
|
||||
for (ISelection selection : selections) {
|
||||
IRenderer.drawAABB(stack, selection.aabb(), SELECTION_BOX_EXPANSION);
|
||||
IRenderer.emitAABB(stack, selection.aabb(), SELECTION_BOX_EXPANSION);
|
||||
}
|
||||
|
||||
if (settings.renderSelectionCorners.value) {
|
||||
IRenderer.glColor(settings.colorSelectionPos1.value, opacity);
|
||||
|
||||
for (ISelection selection : selections) {
|
||||
IRenderer.drawAABB(stack, new AxisAlignedBB(selection.pos1(), selection.pos1().add(1, 1, 1)));
|
||||
IRenderer.emitAABB(stack, new AxisAlignedBB(selection.pos1(), selection.pos1().add(1, 1, 1)));
|
||||
}
|
||||
|
||||
IRenderer.glColor(settings.colorSelectionPos2.value, opacity);
|
||||
|
||||
for (ISelection selection : selections) {
|
||||
IRenderer.drawAABB(stack, new AxisAlignedBB(selection.pos2(), selection.pos2().add(1, 1, 1)));
|
||||
IRenderer.emitAABB(stack, new AxisAlignedBB(selection.pos2(), selection.pos2().add(1, 1, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
@@ -27,7 +26,7 @@ import net.minecraft.util.math.RayTraceResult;
|
||||
* @author Brady
|
||||
* @since 8/25/2018
|
||||
*/
|
||||
public final class BlockBreakHelper implements Helper {
|
||||
public final class BlockBreakHelper {
|
||||
|
||||
private final IPlayerContext ctx;
|
||||
private boolean didBreakLastTick;
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
package baritone.utils;
|
||||
|
||||
import baritone.Baritone;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import net.minecraft.util.ActionResultType;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockRayTraceResult;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
|
||||
public class BlockPlaceHelper implements Helper {
|
||||
public class BlockPlaceHelper {
|
||||
|
||||
private final IPlayerContext ctx;
|
||||
private int rightClickTimer;
|
||||
|
||||
@@ -28,7 +28,6 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientChunkProvider;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockReader;
|
||||
@@ -46,7 +45,6 @@ public class BlockStateInterface {
|
||||
|
||||
private final ClientChunkProvider provider;
|
||||
private final WorldData worldData;
|
||||
protected final IBlockReader world;
|
||||
public final BlockPos.Mutable isPassableBlockPos;
|
||||
public final IBlockReader access;
|
||||
public final BetterWorldBorder worldBorder;
|
||||
@@ -63,20 +61,16 @@ public class BlockStateInterface {
|
||||
}
|
||||
|
||||
public BlockStateInterface(IPlayerContext ctx, boolean copyLoadedChunks) {
|
||||
this(ctx.world(), (WorldData) ctx.worldData(), copyLoadedChunks);
|
||||
}
|
||||
|
||||
public BlockStateInterface(World world, WorldData worldData, boolean copyLoadedChunks) {
|
||||
this.world = world;
|
||||
final World world = ctx.world();
|
||||
this.worldBorder = new BetterWorldBorder(world.getWorldBorder());
|
||||
this.worldData = worldData;
|
||||
this.worldData = (WorldData) ctx.worldData();
|
||||
if (copyLoadedChunks) {
|
||||
this.provider = ((IClientChunkProvider) world.getChunkProvider()).createThreadSafeCopy();
|
||||
} else {
|
||||
this.provider = (ClientChunkProvider) world.getChunkProvider();
|
||||
}
|
||||
this.useTheRealWorld = !Baritone.settings().pathThroughCachedOnly.value;
|
||||
if (!Minecraft.getInstance().isOnExecutionThread()) {
|
||||
if (!ctx.minecraft().isOnExecutionThread()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
this.isPassableBlockPos = new BlockPos.Mutable();
|
||||
|
||||
@@ -23,7 +23,6 @@ import baritone.api.pathing.goals.GoalBlock;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -123,21 +122,11 @@ public class GuiClick extends Screen implements Helper {
|
||||
// drawSingleSelectionBox WHEN?
|
||||
PathRenderer.drawManySelectionBoxes(modelViewStack, e, Collections.singletonList(currentMouseOver), Color.CYAN);
|
||||
if (clickStart != null && !clickStart.equals(currentMouseOver)) {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
RenderSystem.color4f(Color.RED.getColorComponents(null)[0], Color.RED.getColorComponents(null)[1], Color.RED.getColorComponents(null)[2], 0.4F);
|
||||
RenderSystem.lineWidth(Baritone.settings().pathRenderLineWidthPixels.value);
|
||||
RenderSystem.disableTexture();
|
||||
RenderSystem.depthMask(false);
|
||||
RenderSystem.disableDepthTest();
|
||||
IRenderer.startLines(Color.RED, Baritone.settings().pathRenderLineWidthPixels.value, true);
|
||||
BetterBlockPos a = new BetterBlockPos(currentMouseOver);
|
||||
BetterBlockPos b = new BetterBlockPos(clickStart);
|
||||
IRenderer.drawAABB(modelViewStack, new AxisAlignedBB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1));
|
||||
RenderSystem.enableDepthTest();
|
||||
|
||||
RenderSystem.depthMask(true);
|
||||
RenderSystem.enableTexture();
|
||||
RenderSystem.disableBlend();
|
||||
IRenderer.emitAABB(modelViewStack, new AxisAlignedBB(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z), Math.max(a.x, b.x) + 1, Math.max(a.y, b.y) + 1, Math.max(a.z, b.z) + 1));
|
||||
IRenderer.endLines(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,12 +19,13 @@ package baritone.utils;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.api.Settings;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.utils.accessor.IEntityRenderManager;
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.vector.Matrix4f;
|
||||
@@ -37,12 +38,18 @@ public interface IRenderer {
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
IEntityRenderManager renderManager = (IEntityRenderManager) Helper.mc.getRenderManager();
|
||||
IEntityRenderManager renderManager = (IEntityRenderManager) Minecraft.getInstance().getRenderManager();
|
||||
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
|
||||
Settings settings = BaritoneAPI.getSettings();
|
||||
|
||||
float[] color = new float[] {1.0F, 1.0F, 1.0F, 255.0F};
|
||||
|
||||
static void glColor(Color color, float alpha) {
|
||||
float[] colorComponents = color.getColorComponents(null);
|
||||
RenderSystem.color4f(colorComponents[0], colorComponents[1], colorComponents[2], alpha);
|
||||
IRenderer.color[0] = colorComponents[0];
|
||||
IRenderer.color[1] = colorComponents[1];
|
||||
IRenderer.color[2] = colorComponents[2];
|
||||
IRenderer.color[3] = alpha;
|
||||
}
|
||||
|
||||
static void startLines(Color color, float alpha, float lineWidth, boolean ignoreDepth) {
|
||||
@@ -56,6 +63,7 @@ public interface IRenderer {
|
||||
if (ignoreDepth) {
|
||||
RenderSystem.disableDepthTest();
|
||||
}
|
||||
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||
}
|
||||
|
||||
static void startLines(Color color, float lineWidth, boolean ignoreDepth) {
|
||||
@@ -63,6 +71,7 @@ public interface IRenderer {
|
||||
}
|
||||
|
||||
static void endLines(boolean ignoredDepth) {
|
||||
tessellator.draw();
|
||||
if (ignoredDepth) {
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
@@ -72,42 +81,46 @@ public interface IRenderer {
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
static void drawAABB(MatrixStack stack, AxisAlignedBB aabb) {
|
||||
static void emitAABB(MatrixStack stack, AxisAlignedBB aabb) {
|
||||
AxisAlignedBB toDraw = aabb.offset(-renderManager.renderPosX(), -renderManager.renderPosY(), -renderManager.renderPosZ());
|
||||
|
||||
Matrix4f matrix4f = stack.getLast().getMatrix();
|
||||
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION);
|
||||
// bottom
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
// top
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
// corners
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.maxX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.minY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) toDraw.minX, (float) toDraw.maxY, (float) toDraw.maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
}
|
||||
|
||||
static void drawAABB(MatrixStack stack, AxisAlignedBB aabb, double expand) {
|
||||
drawAABB(stack, aabb.grow(expand, expand, expand));
|
||||
static void emitAABB(MatrixStack stack, AxisAlignedBB aabb, double expand) {
|
||||
emitAABB(stack, aabb.grow(expand, expand, expand));
|
||||
}
|
||||
|
||||
static void drawAABB(MatrixStack stack, AxisAlignedBB aabb) {
|
||||
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION_COLOR);
|
||||
emitAABB(stack, aabb);
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import baritone.api.event.events.TickEvent;
|
||||
import baritone.api.utils.IInputOverrideHandler;
|
||||
import baritone.api.utils.input.Input;
|
||||
import baritone.behavior.Behavior;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.MovementInputFromOptions;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -100,7 +99,7 @@ public final class InputOverrideHandler extends Behavior implements IInputOverri
|
||||
}
|
||||
} else {
|
||||
if (ctx.player().movementInput.getClass() == PlayerMovementInput.class) { // allow other movement inputs that aren't this one, e.g. for a freecam
|
||||
ctx.player().movementInput = new MovementInputFromOptions(Minecraft.getInstance().gameSettings);
|
||||
ctx.player().movementInput = new MovementInputFromOptions(ctx.minecraft().gameSettings);
|
||||
}
|
||||
}
|
||||
// only set it if it was previously incorrect
|
||||
|
||||
@@ -22,7 +22,7 @@ import baritone.api.event.events.RenderEvent;
|
||||
import baritone.api.pathing.calc.IPath;
|
||||
import baritone.api.pathing.goals.*;
|
||||
import baritone.api.utils.BetterBlockPos;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.interfaces.IGoalRenderPos;
|
||||
import baritone.behavior.PathingBehavior;
|
||||
import baritone.pathing.path.PathExecutor;
|
||||
@@ -30,7 +30,6 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.client.renderer.tileentity.BeaconTileEntityRenderer;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
@@ -42,6 +41,7 @@ import net.minecraft.util.math.vector.Matrix4f;
|
||||
import net.minecraft.world.DimensionType;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -52,7 +52,7 @@ import static org.lwjgl.opengl.GL11.*;
|
||||
* @author Brady
|
||||
* @since 8/9/2018
|
||||
*/
|
||||
public final class PathRenderer implements IRenderer, Helper {
|
||||
public final class PathRenderer implements IRenderer {
|
||||
|
||||
private static final ResourceLocation TEXTURE_BEACON_BEAM = new ResourceLocation("textures/entity/beacon_beam.png");
|
||||
|
||||
@@ -72,31 +72,27 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
}
|
||||
|
||||
public static void render(RenderEvent event, PathingBehavior behavior) {
|
||||
float partialTicks = event.getPartialTicks();
|
||||
Goal goal = behavior.getGoal();
|
||||
if (Helper.mc.currentScreen instanceof GuiClick) {
|
||||
((GuiClick) Helper.mc.currentScreen).onRender(event.getModelViewStack(), event.getProjectionMatrix());
|
||||
final IPlayerContext ctx = behavior.ctx;
|
||||
if (ctx.world() == null) {
|
||||
return;
|
||||
}
|
||||
if (ctx.minecraft().currentScreen instanceof GuiClick) {
|
||||
((GuiClick) ctx.minecraft().currentScreen).onRender(event.getModelViewStack(), event.getProjectionMatrix());
|
||||
}
|
||||
|
||||
DimensionType thisPlayerDimension = behavior.baritone.getPlayerContext().world().getDimensionType();
|
||||
DimensionType currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().getDimensionType();
|
||||
final float partialTicks = event.getPartialTicks();
|
||||
final Goal goal = behavior.getGoal();
|
||||
|
||||
final DimensionType thisPlayerDimension = ctx.world().getDimensionType();
|
||||
final DimensionType currentRenderViewDimension = BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world().getDimensionType();
|
||||
|
||||
if (thisPlayerDimension != currentRenderViewDimension) {
|
||||
// this is a path for a bot in a different dimension, don't render it
|
||||
return;
|
||||
}
|
||||
|
||||
Entity renderView = Helper.mc.getRenderViewEntity();
|
||||
|
||||
if (renderView.world != BaritoneAPI.getProvider().getPrimaryBaritone().getPlayerContext().world()) {
|
||||
System.out.println("I have no idea what's going on");
|
||||
System.out.println("The primary baritone is in a different world than the render view entity");
|
||||
System.out.println("Not rendering the path");
|
||||
return;
|
||||
}
|
||||
|
||||
if (goal != null && settings.renderGoal.value) {
|
||||
drawDankLitGoalBox(event.getModelViewStack(), renderView, goal, partialTicks, settings.colorGoalBox.value);
|
||||
drawGoal(event.getModelViewStack(), ctx, goal, partialTicks, settings.colorGoalBox.value);
|
||||
}
|
||||
|
||||
if (!settings.renderPath.value) {
|
||||
@@ -106,9 +102,9 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
PathExecutor current = behavior.getCurrent(); // this should prevent most race conditions?
|
||||
PathExecutor next = behavior.getNext(); // like, now it's not possible for current!=null to be true, then suddenly false because of another thread
|
||||
if (current != null && settings.renderSelectionBoxes.value) {
|
||||
drawManySelectionBoxes(event.getModelViewStack(), renderView, current.toBreak(), settings.colorBlocksToBreak.value);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), renderView, current.toPlace(), settings.colorBlocksToPlace.value);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), renderView, current.toWalkInto(), settings.colorBlocksToWalkInto.value);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), current.toBreak(), settings.colorBlocksToBreak.value);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), current.toPlace(), settings.colorBlocksToPlace.value);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), current.toWalkInto(), settings.colorBlocksToWalkInto.value);
|
||||
}
|
||||
|
||||
//drawManySelectionBoxes(player, Collections.singletonList(behavior.pathStart()), partialTicks, Color.WHITE);
|
||||
@@ -131,12 +127,12 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
|
||||
currentlyRunning.pathToMostRecentNodeConsidered().ifPresent(mr -> {
|
||||
drawPath(event.getModelViewStack(), mr, 0, settings.colorMostRecentConsidered.value, settings.fadePath.value, 10, 20);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), renderView, Collections.singletonList(mr.getDest()), settings.colorMostRecentConsidered.value);
|
||||
drawManySelectionBoxes(event.getModelViewStack(), ctx.player(), Collections.singletonList(mr.getDest()), settings.colorMostRecentConsidered.value);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static void drawPath(MatrixStack stack, IPath path, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) {
|
||||
private static void drawPath(MatrixStack stack, IPath path, int startIndex, Color color, boolean fadeOut, int fadeStart0, int fadeEnd0) {
|
||||
IRenderer.startLines(color, settings.pathRenderLineWidthPixels.value, settings.renderPathIgnoreDepth.value);
|
||||
|
||||
int fadeStart = fadeStart0 + startIndex;
|
||||
@@ -172,31 +168,31 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
IRenderer.glColor(color, alpha);
|
||||
}
|
||||
|
||||
drawLine(stack, start.x, start.y, start.z, end.x, end.y, end.z);
|
||||
|
||||
tessellator.draw();
|
||||
emitLine(stack, start.x, start.y, start.z, end.x, end.y, end.z);
|
||||
}
|
||||
|
||||
IRenderer.endLines(settings.renderPathIgnoreDepth.value);
|
||||
}
|
||||
|
||||
|
||||
public static void drawLine(MatrixStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
private static void emitLine(MatrixStack stack, double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||
Matrix4f matrix4f = stack.getLast().getMatrix();
|
||||
|
||||
double vpX = posX();
|
||||
double vpY = posY();
|
||||
double vpZ = posZ();
|
||||
boolean renderPathAsFrickinThingy = !settings.renderPathAsLine.value;
|
||||
|
||||
buffer.begin(renderPathAsFrickinThingy ? GL_LINE_STRIP : GL_LINES, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.5D - vpY), (float) (z2 + 0.5D - vpZ)).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.5D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
if (renderPathAsFrickinThingy) {
|
||||
buffer.pos(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.53D - vpY), (float) (z2 + 0.5D - vpZ)).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.53D - vpY), (float) (z1 + 0.5D - vpZ)).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.5D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.53D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
buffer.pos(matrix4f, (float) (x2 + 0.5D - vpX), (float) (y2 + 0.53D - vpY), (float) (z2 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.53D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.53D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) (x1 + 0.5D - vpX), (float) (y1 + 0.5D - vpY), (float) (z1 + 0.5D - vpZ)).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,13 +207,17 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
VoxelShape shape = state.getShape(player.world, pos);
|
||||
AxisAlignedBB toDraw = shape.isEmpty() ? VoxelShapes.fullCube().getBoundingBox() : shape.getBoundingBox();
|
||||
toDraw = toDraw.offset(pos);
|
||||
IRenderer.drawAABB(stack, toDraw, .002D);
|
||||
IRenderer.emitAABB(stack, toDraw, .002D);
|
||||
});
|
||||
|
||||
IRenderer.endLines(settings.renderSelectionBoxesIgnoreDepth.value);
|
||||
}
|
||||
|
||||
public static void drawDankLitGoalBox(MatrixStack stack, Entity player, Goal goal, float partialTicks, Color color) {
|
||||
private static void drawGoal(MatrixStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color) {
|
||||
drawGoal(stack, ctx, goal, partialTicks, color, true);
|
||||
}
|
||||
|
||||
private static void drawGoal(MatrixStack stack, IPlayerContext ctx, Goal goal, float partialTicks, Color color, boolean setupRender) {
|
||||
double renderPosX = posX();
|
||||
double renderPosY = posY();
|
||||
double renderPosZ = posZ();
|
||||
@@ -249,13 +249,14 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
y2 -= 0.5;
|
||||
maxY--;
|
||||
}
|
||||
drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender);
|
||||
} else if (goal instanceof GoalXZ) {
|
||||
GoalXZ goalPos = (GoalXZ) goal;
|
||||
|
||||
if (settings.renderGoalXZBeacon.value) {
|
||||
glPushAttrib(GL_LIGHTING_BIT);
|
||||
|
||||
Helper.mc.getTextureManager().bindTexture(TEXTURE_BEACON_BEAM);
|
||||
textureManager.bindTexture(TEXTURE_BEACON_BEAM);
|
||||
if (settings.renderGoalIgnoreDepth.value) {
|
||||
RenderSystem.disableDepthTest();
|
||||
}
|
||||
@@ -265,11 +266,11 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
|
||||
BeaconTileEntityRenderer.renderBeamSegment(
|
||||
stack,
|
||||
mc.getRenderTypeBuffers().getBufferSource(),
|
||||
ctx.minecraft().getRenderTypeBuffers().getBufferSource(),
|
||||
TEXTURE_BEACON_BEAM,
|
||||
settings.renderGoalAnimated.value ? partialTicks : 0,
|
||||
1.0F,
|
||||
settings.renderGoalAnimated.value ? player.world.getGameTime() : 0,
|
||||
settings.renderGoalAnimated.value ? ctx.world().getGameTime() : 0,
|
||||
0,
|
||||
256,
|
||||
color.getColorComponents(null),
|
||||
@@ -298,57 +299,73 @@ public final class PathRenderer implements IRenderer, Helper {
|
||||
y2 = 0;
|
||||
minY = 0 - renderPosY;
|
||||
maxY = 256 - renderPosY;
|
||||
drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender);
|
||||
} else if (goal instanceof GoalComposite) {
|
||||
for (Goal g : ((GoalComposite) goal).goals()) {
|
||||
drawDankLitGoalBox(stack, player, g, partialTicks, color);
|
||||
// Simple way to determine if goals can be batched, without having some sort of GoalRenderer
|
||||
boolean batch = Arrays.stream(((GoalComposite) goal).goals()).allMatch(IGoalRenderPos.class::isInstance);
|
||||
|
||||
if (batch) {
|
||||
IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
|
||||
}
|
||||
for (Goal g : ((GoalComposite) goal).goals()) {
|
||||
drawGoal(stack, ctx, g, partialTicks, color, !batch);
|
||||
}
|
||||
if (batch) {
|
||||
IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
|
||||
}
|
||||
return;
|
||||
} else if (goal instanceof GoalInverted) {
|
||||
drawDankLitGoalBox(stack, player, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value);
|
||||
return;
|
||||
drawGoal(stack, ctx, ((GoalInverted) goal).origin, partialTicks, settings.colorInvertedGoalBox.value);
|
||||
} else if (goal instanceof GoalYLevel) {
|
||||
GoalYLevel goalpos = (GoalYLevel) goal;
|
||||
minX = player.getPositionVec().x - settings.yLevelBoxSize.value - renderPosX;
|
||||
minZ = player.getPositionVec().z - settings.yLevelBoxSize.value - renderPosZ;
|
||||
maxX = player.getPositionVec().x + settings.yLevelBoxSize.value - renderPosX;
|
||||
maxZ = player.getPositionVec().z + settings.yLevelBoxSize.value - renderPosZ;
|
||||
minX = ctx.player().getPositionVec().x - settings.yLevelBoxSize.value - renderPosX;
|
||||
minZ = ctx.player().getPositionVec().z - settings.yLevelBoxSize.value - renderPosZ;
|
||||
maxX = ctx.player().getPositionVec().x + settings.yLevelBoxSize.value - renderPosX;
|
||||
maxZ = ctx.player().getPositionVec().z + settings.yLevelBoxSize.value - renderPosZ;
|
||||
minY = ((GoalYLevel) goal).level - renderPosY;
|
||||
maxY = minY + 2;
|
||||
y1 = 1 + y + goalpos.level - renderPosY;
|
||||
y2 = 1 - y + goalpos.level - renderPosY;
|
||||
} else {
|
||||
return;
|
||||
drawDankLitGoalBox(stack, color, minX, maxX, minZ, maxZ, minY, maxY, y1, y2, setupRender);
|
||||
}
|
||||
}
|
||||
|
||||
IRenderer.startLines(color, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
|
||||
private static void drawDankLitGoalBox(MatrixStack stack, Color colorIn, double minX, double maxX, double minZ, double maxZ, double minY, double maxY, double y1, double y2, boolean setupRender) {
|
||||
if (setupRender) {
|
||||
IRenderer.startLines(colorIn, settings.goalRenderLineWidthPixels.value, settings.renderGoalIgnoreDepth.value);
|
||||
}
|
||||
|
||||
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y1);
|
||||
renderHorizontalQuad(stack, minX, maxX, minZ, maxZ, y2);
|
||||
|
||||
Matrix4f matrix4f = stack.getLast().getMatrix();
|
||||
buffer.begin(GL_LINES, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(matrix4f, (float) minX, (float) minY, (float) minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) maxY, (float) minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) minY, (float) minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) maxY, (float) minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) minY, (float) maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) maxY, (float) maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) minY, (float) maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) maxY, (float) maxZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.pos(matrix4f, (float) minX, (float) minY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) maxY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) minY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) maxY, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) minY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) maxY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) minY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) maxY, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
|
||||
if (setupRender) {
|
||||
IRenderer.endLines(settings.renderGoalIgnoreDepth.value);
|
||||
}
|
||||
}
|
||||
|
||||
private static void renderHorizontalQuad(MatrixStack stack, double minX, double maxX, double minZ, double maxZ, double y) {
|
||||
if (y != 0) {
|
||||
Matrix4f matrix4f = stack.getLast().getMatrix();
|
||||
buffer.begin(GL_LINE_LOOP, DefaultVertexFormats.POSITION);
|
||||
buffer.pos(matrix4f, (float) minX, (float) y, (float) minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) y, (float) minZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) y, (float) maxZ).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) y, (float) maxZ).endVertex();
|
||||
tessellator.draw();
|
||||
buffer.pos(matrix4f, (float) minX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
buffer.pos(matrix4f, (float) maxX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) maxX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
buffer.pos(matrix4f, (float) maxX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
|
||||
buffer.pos(matrix4f, (float) minX, (float) y, (float) maxZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
buffer.pos(matrix4f, (float) minX, (float) y, (float) minZ).color(color[0], color[1], color[2], color[3]).endVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class PathingControlManager implements IPathingControlManager {
|
||||
if (newGoal.isInGoal(current.getPath().getDest())) {
|
||||
return false;
|
||||
}
|
||||
return !newGoal.toString().equals(current.getPath().getGoal().toString());
|
||||
return !newGoal.equals(current.getPath().getGoal());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
8
src/main/java/baritone/utils/accessor/IBitArray.java
Normal file
8
src/main/java/baritone/utils/accessor/IBitArray.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package baritone.utils.accessor;
|
||||
|
||||
public interface IBitArray {
|
||||
|
||||
long getMaxEntryValue();
|
||||
|
||||
int getBitsPerEntry();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package baritone.utils.accessor;
|
||||
|
||||
import net.minecraft.util.BitArray;
|
||||
import net.minecraft.util.palette.IPalette;
|
||||
|
||||
public interface IPalettedContainer<T> {
|
||||
|
||||
IPalette<T> getPalette();
|
||||
|
||||
BitArray getStorage();
|
||||
}
|
||||
@@ -17,13 +17,12 @@
|
||||
|
||||
package baritone.utils.player;
|
||||
|
||||
import baritone.api.BaritoneAPI;
|
||||
import baritone.Baritone;
|
||||
import baritone.api.cache.IWorldData;
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerContext;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.api.utils.RayTraceUtils;
|
||||
import baritone.api.utils.*;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -33,28 +32,52 @@ import net.minecraft.world.World;
|
||||
* @author Brady
|
||||
* @since 11/12/2018
|
||||
*/
|
||||
public enum PrimaryPlayerContext implements IPlayerContext, Helper {
|
||||
public final class BaritonePlayerContext implements IPlayerContext {
|
||||
|
||||
INSTANCE;
|
||||
private final Baritone baritone;
|
||||
private final Minecraft mc;
|
||||
private final IPlayerController playerController;
|
||||
|
||||
public BaritonePlayerContext(Baritone baritone, Minecraft mc) {
|
||||
this.baritone = baritone;
|
||||
this.mc = mc;
|
||||
this.playerController = new BaritonePlayerController(mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Minecraft minecraft() {
|
||||
return this.mc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientPlayerEntity player() {
|
||||
return mc.player;
|
||||
return this.mc.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayerController playerController() {
|
||||
return PrimaryPlayerController.INSTANCE;
|
||||
return this.playerController;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World world() {
|
||||
return mc.world;
|
||||
return this.mc.world;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWorldData worldData() {
|
||||
return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld();
|
||||
return this.baritone.getWorldProvider().getCurrentWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BetterBlockPos viewerPos() {
|
||||
final Entity entity = this.mc.getRenderViewEntity();
|
||||
return entity == null ? this.playerFeet() : BetterBlockPos.from(entity.getPosition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rotation playerRotations() {
|
||||
return this.baritone.getLookBehavior().getEffectiveRotation().orElseGet(IPlayerContext.super::playerRotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -17,9 +17,9 @@
|
||||
|
||||
package baritone.utils.player;
|
||||
|
||||
import baritone.api.utils.Helper;
|
||||
import baritone.api.utils.IPlayerController;
|
||||
import baritone.utils.accessor.IPlayerControllerMP;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.ClientPlayerEntity;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -40,9 +40,13 @@ import net.minecraft.world.World;
|
||||
* @author Brady
|
||||
* @since 12/14/2018
|
||||
*/
|
||||
public enum PrimaryPlayerController implements IPlayerController, Helper {
|
||||
public final class BaritonePlayerController implements IPlayerController {
|
||||
|
||||
INSTANCE;
|
||||
private final Minecraft mc;
|
||||
|
||||
public BaritonePlayerController(Minecraft mc) {
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void syncHeldItem() {
|
||||
Reference in New Issue
Block a user