diff --git a/USAGE.md b/USAGE.md index 5a63c05ee..681298b01 100644 --- a/USAGE.md +++ b/USAGE.md @@ -44,7 +44,7 @@ Some common examples: - `save waypointName` to save a waypoint. `goto waypointName` to go to it. - `build` to build a schematic. `build blah` will load `schematics/blah.schematic` and build it with the origin being your player feet. `build blah x y z` to set the origin. Any of those can be relative to your player (`~ 69 ~-420` would build at x=player x, y=69, z=player z-420). - `schematica` to build the schematic that is currently open in schematica -- `tunnel` to dig just straight ahead and make a tunnel +- `tunnel height width depth` to dig and make a tunnel. If you don't supply numbers then it just digs a 1x2 tunnel. - `farm` to automatically harvest, replant, or bone meal crops - `axis` to go to an axis or diagonal axis at y=120 (`axisHeight` is a configurable setting, defaults to 120). - `explore x z` to explore the world from the origin of x,z. Leave out x and z to default to player feet. This will continually path towards the closest chunk to the origin that it's never seen before. `explorefilter filter.json` with optional invert can be used to load in a list of chunks to load. @@ -73,6 +73,8 @@ There are about a hundred settings, but here are some fun / interesting / import - `worldExploringChunkOffset` - `acceptableThrowawayItems` - `blocksToAvoidBreaking` +- `mineScanDroppedItems` +- `allowDiagonalAscend` diff --git a/src/launch/java/baritone/launch/mixins/MixinClientPlayNetHandler.java b/src/launch/java/baritone/launch/mixins/MixinClientPlayNetHandler.java index 1fa6b54d0..e31856c4d 100644 --- a/src/launch/java/baritone/launch/mixins/MixinClientPlayNetHandler.java +++ b/src/launch/java/baritone/launch/mixins/MixinClientPlayNetHandler.java @@ -21,6 +21,7 @@ import baritone.api.BaritoneAPI; import baritone.api.IBaritone; import baritone.api.event.events.ChunkEvent; import baritone.api.event.events.type.EventState; +import net.minecraft.client.entity.player.ClientPlayerEntity; import net.minecraft.client.network.play.ClientPlayNetHandler; import net.minecraft.network.play.server.SChunkDataPacket; import net.minecraft.network.play.server.SCombatPacket; @@ -47,7 +48,8 @@ public class MixinClientPlayNetHandler { ) private void preRead(SPacketChunkData packetIn, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (NetHandlerPlayClient) (Object) this) { + ClientPlayerEntity player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) { ibaritone.getGameEventHandler().onChunkEvent( new ChunkEvent( EventState.PRE, @@ -66,7 +68,8 @@ public class MixinClientPlayNetHandler { ) private void postHandleChunkData(SChunkDataPacket packetIn, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) { + ClientPlayerEntity player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) { ibaritone.getGameEventHandler().onChunkEvent( new ChunkEvent( EventState.POST, @@ -85,7 +88,8 @@ public class MixinClientPlayNetHandler { ) private void preChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) { + ClientPlayerEntity player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) { ibaritone.getGameEventHandler().onChunkEvent( new ChunkEvent(EventState.PRE, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ()) ); @@ -99,7 +103,8 @@ public class MixinClientPlayNetHandler { ) private void postChunkUnload(SUnloadChunkPacket packet, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) { + ClientPlayerEntity player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) { ibaritone.getGameEventHandler().onChunkEvent( new ChunkEvent(EventState.POST, ChunkEvent.Type.UNLOAD, packet.getX(), packet.getZ()) ); @@ -116,7 +121,8 @@ public class MixinClientPlayNetHandler { ) private void onPlayerDeath(SCombatPacket packetIn, CallbackInfo ci) { for (IBaritone ibaritone : BaritoneAPI.getProvider().getAllBaritones()) { - if (ibaritone.getPlayerContext().player().connection == (ClientPlayNetHandler) (Object) this) { + ClientPlayerEntity player = ibaritone.getPlayerContext().player(); + if (player != null && player.connection == (ClientPlayNetHandler) (Object) this) { ibaritone.getGameEventHandler().onPlayerDeath(); } } diff --git a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java index 12f64bf21..05cde10be 100644 --- a/src/launch/java/baritone/launch/mixins/MixinMinecraft.java +++ b/src/launch/java/baritone/launch/mixins/MixinMinecraft.java @@ -145,7 +145,7 @@ public class MixinMinecraft { ) private boolean passEvents(Screen screen) { // allow user input is only the primary baritone - return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().getCurrent() != null && player != null) || screen.passEvents; + return (BaritoneAPI.getProvider().getPrimaryBaritone().getPathingBehavior().isPathing() && player != null) || screen.passEvents; } @Inject( diff --git a/src/main/java/baritone/behavior/PathingBehavior.java b/src/main/java/baritone/behavior/PathingBehavior.java index 86fd95055..50ca7425f 100644 --- a/src/main/java/baritone/behavior/PathingBehavior.java +++ b/src/main/java/baritone/behavior/PathingBehavior.java @@ -103,7 +103,7 @@ public final class PathingBehavior extends Behavior implements IPathingBehavior, @Override public void onPlayerSprintState(SprintStateEvent event) { - if (current != null) { + if (isPathing()) { event.setState(current.isSprinting()); } } diff --git a/src/main/java/baritone/command/defaults/TunnelCommand.java b/src/main/java/baritone/command/defaults/TunnelCommand.java index 991a7ff81..3cce423a5 100644 --- a/src/main/java/baritone/command/defaults/TunnelCommand.java +++ b/src/main/java/baritone/command/defaults/TunnelCommand.java @@ -18,11 +18,13 @@ package baritone.command.defaults; import baritone.api.IBaritone; +import baritone.api.command.Command; +import baritone.api.command.argument.IArgConsumer; +import baritone.api.command.exception.CommandException; import baritone.api.pathing.goals.Goal; import baritone.api.pathing.goals.GoalStrictDirection; -import baritone.api.command.Command; -import baritone.api.command.exception.CommandException; -import baritone.api.command.argument.IArgConsumer; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; import java.util.Arrays; import java.util.List; @@ -36,13 +38,56 @@ public class TunnelCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { - args.requireMax(0); - Goal goal = new GoalStrictDirection( - ctx.playerFeet(), - ctx.player().getHorizontalFacing() - ); - baritone.getCustomGoalProcess().setGoalAndPath(goal); - logDirect(String.format("Goal: %s", goal.toString())); + args.requireMax(3); + if (args.hasExactly(3)) { + boolean cont = true; + int height = Integer.parseInt(args.getArgs().get(0).getValue()); + int width = Integer.parseInt(args.getArgs().get(1).getValue()); + int depth = Integer.parseInt(args.getArgs().get(2).getValue()); + + if (width < 1 || height < 2 || depth < 1 || height > 255) { + logDirect("Width and depth must at least be 1 block; Height must at least be 2 blocks, and cannot be greater than the build limit."); + cont = false; + } + + if (cont) { + height--; + width--; + BlockPos corner1; + BlockPos corner2; + Direction enumFacing = ctx.player().getHorizontalFacing(); + int addition = ((width % 2 == 0) ? 0 : 1); + switch (enumFacing) { + case EAST: + corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z - width / 2); + corner2 = new BlockPos(ctx.playerFeet().x + depth, ctx.playerFeet().y + height, ctx.playerFeet().z + width / 2 + addition); + break; + case WEST: + corner1 = new BlockPos(ctx.playerFeet().x, ctx.playerFeet().y, ctx.playerFeet().z + width / 2 + addition); + corner2 = new BlockPos(ctx.playerFeet().x - depth, ctx.playerFeet().y + height, ctx.playerFeet().z - width / 2); + break; + case NORTH: + corner1 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y, ctx.playerFeet().z); + corner2 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y + height, ctx.playerFeet().z - depth); + break; + case SOUTH: + corner1 = new BlockPos(ctx.playerFeet().x + width / 2 + addition, ctx.playerFeet().y, ctx.playerFeet().z); + corner2 = new BlockPos(ctx.playerFeet().x - width / 2, ctx.playerFeet().y + height, ctx.playerFeet().z + depth); + break; + default: + throw new IllegalStateException("Unexpected value: " + enumFacing); + } + logDirect(String.format("Creating a tunnel %s block(s) high, %s block(s) wide, and %s block(s) deep", height+1, width+1, depth)); + baritone.getBuilderProcess().clearArea(corner1, corner2); + } + } else { + Goal goal = new GoalStrictDirection( + ctx.playerFeet(), + ctx.player().getHorizontalFacing() + ); + baritone.getCustomGoalProcess().setGoalAndPath(goal); + logDirect(String.format("Goal: %s", goal.toString())); + } } @Override @@ -61,7 +106,8 @@ public class TunnelCommand extends Command { "The tunnel command sets a goal that tells Baritone to mine completely straight in the direction that you're facing.", "", "Usage:", - "> tunnel" + "> tunnel - No arguments, mines in a 1x2 radius.", + "> tunnel - Tunnels in a user defined height, width and depth." ); } } diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 01e724ee4..958f5d4d3 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -309,7 +309,7 @@ public interface MovementHelper extends ActionCosts, Helper { if (block == Blocks.FARMLAND || block == Blocks.GRASS_PATH) { return true; } - if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST) { + if (block == Blocks.ENDER_CHEST || block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST ) { return true; } if (isWater(state)) { diff --git a/src/main/java/baritone/process/BuilderProcess.java b/src/main/java/baritone/process/BuilderProcess.java index fe87d59f2..625e4fbcd 100644 --- a/src/main/java/baritone/process/BuilderProcess.java +++ b/src/main/java/baritone/process/BuilderProcess.java @@ -210,7 +210,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } BlockState curr = bcc.bsi.get0(x, y, z); - if (!(curr.getBlock() instanceof AirBlock) && !(curr.getBlock() == Blocks.WATER || curr.getBlock() == Blocks.LAVA) && !valid(curr, desired)) { + 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 rot = RotationUtils.reachable(ctx.player(), pos, ctx.playerController().getBlockReachDistance()); if (rot.isPresent()) { @@ -251,7 +251,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil continue; // irrelevant } BlockState curr = bcc.bsi.get0(x, y, z); - if (MovementHelper.isReplaceable(x, y, z, curr, bcc.bsi) && !valid(curr, desired)) { + if (MovementHelper.isReplaceable(x, y, z, curr, bcc.bsi) && !valid(curr, desired, false)) { if (dy == 1 && bcc.bsi.get0(x, y + 1, z).getBlock() instanceof AirBlock) { continue; } @@ -330,7 +330,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (!meme.canPlace()) { continue; } - if (valid(wouldBePlaced, desired)) { + if (valid(wouldBePlaced, desired, true)) { return OptionalInt.of(i); } } @@ -473,7 +473,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil outer: for (BlockState desired : desirableOnHotbar) { for (int i = 0; i < 9; i++) { - if (valid(approxPlaceable.get(i), desired)) { + if (valid(approxPlaceable.get(i), desired, true)) { usefulSlots.add(i); continue outer; } @@ -484,7 +484,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil outer: for (int i = 9; i < 36; i++) { for (BlockState desired : noValidHotbarOption) { - if (valid(approxPlaceable.get(i), desired)) { + if (valid(approxPlaceable.get(i), desired, true)) { baritone.getInventoryBehavior().attemptToPutOnHotbar(i, usefulSlots::contains); break outer; } @@ -540,7 +540,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (desired != null) { // we care about this position BetterBlockPos pos = new BetterBlockPos(x, y, z); - if (valid(bcc.bsi.get0(x, y, z), desired)) { + if (valid(bcc.bsi.get0(x, y, z), desired, false)) { incorrectPositions.remove(pos); observedCompleted.add(BetterBlockPos.longHash(pos)); } else { @@ -567,7 +567,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } if (bcc.bsi.worldContainsLoadedChunk(blockX, blockZ)) { // check if its in render distance, not if its in cache // we can directly observe this block, it is in render distance - if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current, this.approxPlaceable))) { + if (valid(bcc.bsi.get0(blockX, blockY, blockZ), schematic.desiredState(x, y, z, current, this.approxPlaceable), false)) { observedCompleted.add(BetterBlockPos.longHash(blockX, blockY, blockZ)); } else { incorrectPositions.add(new BetterBlockPos(blockX, blockY, blockZ)); @@ -785,7 +785,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil return result; } - private boolean valid(BlockState current, BlockState desired) { + private boolean valid(BlockState current, BlockState desired, boolean itemVerify) { if (desired == null) { return true; } @@ -799,7 +799,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil if (desired.getBlock() instanceof AirBlock && Baritone.settings().buildIgnoreBlocks.value.contains(current.getBlock())) { return true; } - if (!(current.getBlock() instanceof AirBlock) && Baritone.settings().buildIgnoreExisting.value) { + if (!(current.getBlock() instanceof AirBlock) && Baritone.settings().buildIgnoreExisting.value && !itemVerify) { return true; } return current.equals(desired); @@ -881,7 +881,7 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil } // it should be a real block // is it already that block? - if (valid(bsi.get0(x, y, z), sch)) { + if (valid(bsi.get0(x, y, z), sch, false)) { return Baritone.settings().breakCorrectBlockPenaltyMultiplier.value; } else { // can break if it's wrong diff --git a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java index 06206eecd..b76eeec92 100644 --- a/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java +++ b/src/main/java/baritone/utils/BlockStateInterfaceAccessWrapper.java @@ -41,7 +41,7 @@ public final class BlockStateInterfaceAccessWrapper implements IBlockReader { @Nullable @Override public TileEntity getTileEntity(BlockPos pos) { - throw new UnsupportedOperationException("getTileEntity not supported by BlockStateInterfaceAccessWrapper"); + return null; } @Override