MCPcopy Create free account
hub / github.com/cabaletta/baritone / onTick

Method onTick

src/main/java/baritone/process/MineProcess.java:74–146  ·  view source on GitHub ↗
(boolean calcFailed, boolean isSafeToCancel)

Source from the content-addressed store, hash-verified

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) {
112 if (!addNearby()) {
113 cancel();
114 return null;
115 }
116 }
117 Optional<BlockPos> shaft = curr.stream()
118 .filter(pos -> pos.getX() == ctx.playerFeet().getX() && pos.getZ() == ctx.playerFeet().getZ())
119 .filter(pos -> pos.getY() >= ctx.playerFeet().getY())
120 .filter(pos -> !(BlockStateInterface.get(ctx, pos).getBlock() instanceof AirBlock)) // after breaking a block, it takes mineGoalUpdateInterval ticks for it to actually update this list =(
121 .min(Comparator.comparingDouble(ctx.playerFeet().above()::distSqr));
122 baritone.getInputOverrideHandler().clearAllKeys();
123 if (shaft.isPresent() && ctx.player().onGround()) {
124 BlockPos pos = shaft.get();
125 BlockState state = baritone.bsi.get0(pos);
126 if (!MovementHelper.avoidBreaking(baritone.bsi, pos.getX(), pos.getY(), pos.getZ(), state)) {
127 Optional<Rotation> rot = RotationUtils.reachable(ctx, pos);
128 if (rot.isPresent() && isSafeToCancel) {
129 baritone.getLookBehavior().updateTarget(rot.get(), true);
130 MovementHelper.switchToBestToolFor(ctx, ctx.world().getBlockState(pos));
131 if (ctx.isLookingAt(pos) || ctx.playerRotations().isReallyCloseTo(rot.get())) {

Callers

nothing calls this directly

Calls 15

settingsMethod · 0.95
updateLoucaSystemMethod · 0.95
getExecutorMethod · 0.95
rescanMethod · 0.95
addNearbyMethod · 0.95
getMethod · 0.95
avoidBreakingMethod · 0.95
reachableMethod · 0.95
switchToBestToolForMethod · 0.95
updateGoalMethod · 0.95
filterMethod · 0.80
logDirectMethod · 0.80

Tested by

no test coverage detected