| 45 | import java.util.function.Predicate; |
| 46 | |
| 47 | public final class InventoryBehavior extends Behavior implements Helper { |
| 48 | |
| 49 | int ticksSinceLastInventoryMove; |
| 50 | int[] lastTickRequestedMove; // not everything asks every tick, so remember the request while coming to a halt |
| 51 | |
| 52 | public InventoryBehavior(Baritone baritone) { |
| 53 | super(baritone); |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public void onTick(TickEvent event) { |
| 58 | if (!Baritone.settings().allowInventory.value) { |
| 59 | return; |
| 60 | } |
| 61 | if (event.getType() == TickEvent.Type.OUT) { |
| 62 | return; |
| 63 | } |
| 64 | if (ctx.player().containerMenu != ctx.player().inventoryMenu) { |
| 65 | // we have a crafting table or a chest or something open |
| 66 | return; |
| 67 | } |
| 68 | ticksSinceLastInventoryMove++; |
| 69 | if (firstValidThrowaway() >= 9) { // aka there are none on the hotbar, but there are some in main inventory |
| 70 | requestSwapWithHotBar(firstValidThrowaway(), 8); |
| 71 | } |
| 72 | int pick = bestToolAgainst(Blocks.STONE); |
| 73 | if (pick >= 9) { |
| 74 | requestSwapWithHotBar(pick, 0); |
| 75 | } |
| 76 | if (lastTickRequestedMove != null) { |
| 77 | logDebug("Remembering to move " + lastTickRequestedMove[0] + " " + lastTickRequestedMove[1] + " from a previous tick"); |
| 78 | requestSwapWithHotBar(lastTickRequestedMove[0], lastTickRequestedMove[1]); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | public boolean attemptToPutOnHotbar(int inMainInvy, Predicate<Integer> disallowedHotbar) { |
| 83 | OptionalInt destination = getTempHotbarSlot(disallowedHotbar); |
| 84 | if (destination.isPresent()) { |
| 85 | if (!requestSwapWithHotBar(inMainInvy, destination.getAsInt())) { |
| 86 | return false; |
| 87 | } |
| 88 | } |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | public OptionalInt getTempHotbarSlot(Predicate<Integer> disallowedHotbar) { |
| 93 | // we're using 0 and 8 for pickaxe and throwaway |
| 94 | ArrayList<Integer> candidates = new ArrayList<>(); |
| 95 | for (int i = 1; i < 8; i++) { |
| 96 | if (ctx.player().getInventory().getNonEquipmentItems().get(i).isEmpty() && !disallowedHotbar.test(i)) { |
| 97 | candidates.add(i); |
| 98 | } |
| 99 | } |
| 100 | if (candidates.isEmpty()) { |
| 101 | for (int i = 1; i < 8; i++) { |
| 102 | if (!disallowedHotbar.test(i)) { |
| 103 | candidates.add(i); |
| 104 | } |
nothing calls this directly
no outgoing calls
no test coverage detected