From 26256e71554e379cc2b8a5f55eb83f728b1c4eee Mon Sep 17 00:00:00 2001 From: Leijurv Date: Wed, 17 Apr 2019 22:17:09 -0700 Subject: [PATCH] mine is now MUCH more epic --- .../api/pathing/goals/GoalTwoBlocks.java | 6 +- .../java/baritone/process/MineProcess.java | 62 +++++++++++++++++-- .../java/baritone/utils/pathing/Favoring.java | 3 +- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java index b1dc07a1d..f1026ab50 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java +++ b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java @@ -31,17 +31,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { /** * The X block position of this goal */ - private final int x; + protected final int x; /** * The Y block position of this goal */ - private final int y; + protected final int y; /** * The Z block position of this goal */ - private final int z; + protected final int z; public GoalTwoBlocks(BlockPos pos) { this(pos.getX(), pos.getY(), pos.getZ()); diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index cc168c562..5ace2130c 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -24,7 +24,9 @@ import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommandType; import baritone.api.utils.BlockUtils; import baritone.api.utils.IPlayerContext; +import baritone.api.utils.Rotation; import baritone.api.utils.RotationUtils; +import baritone.api.utils.input.Input; import baritone.cache.CachedChunk; import baritone.cache.WorldScanner; import baritone.pathing.movement.CalculationContext; @@ -32,6 +34,8 @@ import baritone.pathing.movement.MovementHelper; import baritone.utils.BaritoneProcessHelper; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; @@ -94,14 +98,35 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro return null; } int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; + List curr = new ArrayList<>(knownOreLocations); if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain - List curr = new ArrayList<>(knownOreLocations); CalculationContext context = new CalculationContext(baritone, true); Baritone.getExecutor().execute(() -> rescan(curr, context)); } if (Baritone.settings().legitMine.value) { addNearby(); } + Optional shaft = curr.stream() + .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ()) + .filter(pos -> pos.getY() > ctx.playerFeet().getY()) + .filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof BlockAir)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =( + .min(Comparator.comparingDouble(ctx.player()::getDistanceSq)); + baritone.getInputOverrideHandler().clearAllKeys(); + if (shaft.isPresent()) { + BlockPos pos = shaft.get(); + IBlockState state = baritone.bsi.get0(pos); + if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) { + Optional rot = RotationUtils.reachable(ctx, pos); + if (rot.isPresent() && isSafeToCancel) { + baritone.getLookBehavior().updateTarget(rot.get(), true); + MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos)); + if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot.get())) { + baritone.getInputOverrideHandler().setInputForceState(Input.CLICK_LEFT, true); + } + return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); + } + } + } PathingCommand command = updateGoal(); if (command == null) { // none in range @@ -178,15 +203,42 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro knownOreLocations = locs; } + private static boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List locs) { + return locs.contains(pos) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, pos) instanceof BlockAir); + } + private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List locs) { if (!Baritone.settings().forceInternalMining.value) { - return new GoalTwoBlocks(loc); + return new GoalThreeBlocks(loc); } + //if upwardGoal is false, and downward is true + // Here, BlockStateInterface is used because the position may be in a cached chunk (the targeted block is one that is kept track of) - boolean upwardGoal = locs.contains(loc.up()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.up()) == Blocks.AIR); - boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.down()) == Blocks.AIR); - return upwardGoal == downwardGoal ? new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : new GoalBlock(loc.down()); + boolean upwardGoal = internalMiningGoal(loc.up(), ctx, locs); + boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs); + boolean doubleDownwardGoal = internalMiningGoal(loc.down(2), ctx, locs); + return upwardGoal == downwardGoal ? doubleDownwardGoal ? new GoalThreeBlocks(loc) : new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : doubleDownwardGoal ? new GoalTwoBlocks(loc.down()) : new GoalBlock(loc.down()); + } + + private static class GoalThreeBlocks extends GoalTwoBlocks { + + public GoalThreeBlocks(BlockPos pos) { + super(pos); + } + + @Override + public boolean isInGoal(int x, int y, int z) { + return x == this.x && (y == this.y || y == this.y - 1 || y == this.y - 2) && z == this.z; + } + + @Override + public double heuristic(int x, int y, int z) { + int xDiff = x - this.x; + int yDiff = y - this.y; + int zDiff = z - this.z; + return GoalBlock.calculate(xDiff, yDiff < -1 ? yDiff + 2 : yDiff == -1 ? 0 : yDiff, zDiff); + } } public static List droppedItemsScan(List mining, World world) { diff --git a/src/main/java/baritone/utils/pathing/Favoring.java b/src/main/java/baritone/utils/pathing/Favoring.java index 8a6017582..56ccb0069 100644 --- a/src/main/java/baritone/utils/pathing/Favoring.java +++ b/src/main/java/baritone/utils/pathing/Favoring.java @@ -19,6 +19,7 @@ package baritone.utils.pathing; import baritone.api.pathing.calc.IPath; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.Helper; import baritone.api.utils.IPlayerContext; import baritone.pathing.movement.CalculationContext; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; @@ -31,7 +32,7 @@ public final class Favoring { for (Avoidance avoid : Avoidance.create(ctx)) { avoid.applySpherical(favorings); } - System.out.println("Favoring size: " + favorings.size()); + Helper.HELPER.logDebug("Favoring size: " + favorings.size()); } public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances