mine is now MUCH more epic

This commit is contained in:
Leijurv 2019-04-17 22:17:09 -07:00
parent 6599736e00
commit 26256e7155
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
3 changed files with 62 additions and 9 deletions

View File

@ -31,17 +31,17 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos {
/** /**
* The X block position of this goal * The X block position of this goal
*/ */
private final int x; protected final int x;
/** /**
* The Y block position of this goal * The Y block position of this goal
*/ */
private final int y; protected final int y;
/** /**
* The Z block position of this goal * The Z block position of this goal
*/ */
private final int z; protected final int z;
public GoalTwoBlocks(BlockPos pos) { public GoalTwoBlocks(BlockPos pos) {
this(pos.getX(), pos.getY(), pos.getZ()); this(pos.getX(), pos.getY(), pos.getZ());

View File

@ -24,7 +24,9 @@ import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType; import baritone.api.process.PathingCommandType;
import baritone.api.utils.BlockUtils; import baritone.api.utils.BlockUtils;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
import baritone.api.utils.Rotation;
import baritone.api.utils.RotationUtils; import baritone.api.utils.RotationUtils;
import baritone.api.utils.input.Input;
import baritone.cache.CachedChunk; import baritone.cache.CachedChunk;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
@ -32,6 +34,8 @@ import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import net.minecraft.block.Block; 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.Entity;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
@ -94,14 +98,35 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
return null; return null;
} }
int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value;
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain
List<BlockPos> curr = new ArrayList<>(knownOreLocations);
CalculationContext context = new CalculationContext(baritone, true); CalculationContext context = new CalculationContext(baritone, true);
Baritone.getExecutor().execute(() -> rescan(curr, context)); Baritone.getExecutor().execute(() -> rescan(curr, context));
} }
if (Baritone.settings().legitMine.value) { if (Baritone.settings().legitMine.value) {
addNearby(); addNearby();
} }
Optional<BlockPos> 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<Rotation> 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(); PathingCommand command = updateGoal();
if (command == null) { if (command == null) {
// none in range // none in range
@ -178,15 +203,42 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
knownOreLocations = locs; knownOreLocations = locs;
} }
private static boolean internalMiningGoal(BlockPos pos, IPlayerContext ctx, List<BlockPos> locs) {
return locs.contains(pos) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, pos) instanceof BlockAir);
}
private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List<BlockPos> locs) { private static Goal coalesce(IPlayerContext ctx, BlockPos loc, List<BlockPos> locs) {
if (!Baritone.settings().forceInternalMining.value) { 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) // 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 upwardGoal = internalMiningGoal(loc.up(), ctx, locs);
boolean downwardGoal = locs.contains(loc.down()) || (Baritone.settings().internalMiningAirException.value && BlockStateInterface.getBlock(ctx, loc.down()) == Blocks.AIR); boolean downwardGoal = internalMiningGoal(loc.down(), ctx, locs);
return upwardGoal == downwardGoal ? new GoalTwoBlocks(loc) : upwardGoal ? new GoalBlock(loc) : new GoalBlock(loc.down()); 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<BlockPos> droppedItemsScan(List<Block> mining, World world) { public static List<BlockPos> droppedItemsScan(List<Block> mining, World world) {

View File

@ -19,6 +19,7 @@ package baritone.utils.pathing;
import baritone.api.pathing.calc.IPath; import baritone.api.pathing.calc.IPath;
import baritone.api.utils.BetterBlockPos; import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext; import baritone.api.utils.IPlayerContext;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2DoubleOpenHashMap;
@ -31,7 +32,7 @@ public final class Favoring {
for (Avoidance avoid : Avoidance.create(ctx)) { for (Avoidance avoid : Avoidance.create(ctx)) {
avoid.applySpherical(favorings); 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 public Favoring(IPath previous, CalculationContext context) { // create one just from previous path, no mob avoidances