Mine blocks of a certain type @author leijurv
| 52 | * @author leijurv |
| 53 | */ |
| 54 | public final class MineProcess extends BaritoneProcessHelper implements IMineProcess { |
| 55 | |
| 56 | private BlockOptionalMetaLookup filter; |
| 57 | private List<BlockPos> knownOreLocations; |
| 58 | private List<BlockPos> blacklist; // inaccessible |
| 59 | private Map<BlockPos, Long> anticipatedDrops; |
| 60 | private BlockPos branchPoint; |
| 61 | private GoalRunAway branchPointRunaway; |
| 62 | private int desiredQuantity; |
| 63 | private int tickCount; |
| 64 | |
| 65 | public MineProcess(Baritone baritone) { |
| 66 | super(baritone); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean isActive() { |
| 71 | return filter != null; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { |
| 76 | if (desiredQuantity > 0) { |
| 77 | int curr = ctx.player().getInventory().getNonEquipmentItems().stream() |
| 78 | .filter(stack -> filter.has(stack)) |
| 79 | .mapToInt(ItemStack::getCount).sum(); |
| 80 | if (curr >= desiredQuantity) { |
| 81 | logDirect("Have " + curr + " valid items"); |
| 82 | cancel(); |
| 83 | return null; |
| 84 | } |
| 85 | } |
| 86 | if (calcFailed) { |
| 87 | if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { |
| 88 | logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance..."); |
| 89 | if (Baritone.settings().notificationOnMineFail.value) { |
| 90 | logNotification("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...", true); |
| 91 | } |
| 92 | knownOreLocations.stream().min(Comparator.comparingDouble(ctx.playerFeet()::distSqr)).ifPresent(blacklist::add); |
| 93 | knownOreLocations.removeIf(blacklist::contains); |
| 94 | } else { |
| 95 | logDirect("Unable to find any path to " + filter + ", canceling mine"); |
| 96 | if (Baritone.settings().notificationOnMineFail.value) { |
| 97 | logNotification("Unable to find any path to " + filter + ", canceling mine", true); |
| 98 | } |
| 99 | cancel(); |
| 100 | return null; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | updateLoucaSystem(); |
| 105 | int mineGoalUpdateInterval = Baritone.settings().mineGoalUpdateInterval.value; |
| 106 | List<BlockPos> curr = new ArrayList<>(knownOreLocations); |
| 107 | if (mineGoalUpdateInterval != 0 && tickCount++ % mineGoalUpdateInterval == 0) { // big brain |
| 108 | CalculationContext context = new CalculationContext(baritone, true); |
| 109 | Baritone.getExecutor().execute(() -> rescan(curr, context)); |
| 110 | } |
| 111 | if (Baritone.settings().legitMine.value) { |
nothing calls this directly
no outgoing calls
no test coverage detected