Skip to content

Commit d2e3364

Browse files
committed
[feat] auto-tool inventory swap support
1 parent c50139f commit d2e3364

File tree

1 file changed

+51
-1
lines changed
  • src/main/java/meteordevelopment/meteorclient/systems/modules/player

1 file changed

+51
-1
lines changed

src/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoTool.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import meteordevelopment.meteorclient.systems.modules.world.InfinityMiner;
1818
import meteordevelopment.meteorclient.utils.Utils;
1919
import meteordevelopment.meteorclient.utils.player.InvUtils;
20+
import meteordevelopment.meteorclient.utils.player.SlotUtils;
2021
import meteordevelopment.meteorclient.utils.world.BlockUtils;
2122
import meteordevelopment.orbit.EventHandler;
2223
import meteordevelopment.orbit.EventPriority;
@@ -80,6 +81,31 @@ public class AutoTool extends Module {
8081
.build()
8182
);
8283

84+
private final Setting<Boolean> invSwap = sgGeneral.add(new BoolSetting.Builder()
85+
.name("swap-from-inventory")
86+
.description("Search tools in the entire inventory")
87+
.defaultValue(false)
88+
.build()
89+
);
90+
91+
private final Setting<Integer> invSwapSlot = sgGeneral.add(new IntSetting.Builder()
92+
.name("swap-slot")
93+
.description("Slot to swap tools from inventory into")
94+
.defaultValue(8)
95+
.range(0, 8)
96+
.noSlider()
97+
.visible(invSwap::get)
98+
.build()
99+
);
100+
101+
private final Setting<Boolean> invSwapReturn = sgGeneral.add(new BoolSetting.Builder()
102+
.name("return-swapped-tool-back")
103+
.description("Swap the tool back into the inventory")
104+
.defaultValue(false)
105+
.visible(invSwap::get)
106+
.build()
107+
);
108+
83109
private final Setting<Integer> switchDelay = sgGeneral.add((new IntSetting.Builder()
84110
.name("switch-delay")
85111
.description("Delay in ticks before switching tools.")
@@ -116,6 +142,7 @@ public class AutoTool extends Module {
116142
private boolean shouldSwitch;
117143
private int ticks;
118144
private int bestSlot;
145+
private int toolWasIn;
119146

120147
public AutoTool() {
121148
super(Categories.Player, "auto-tool", "Automatically switches to the most effective tool when performing an action.");
@@ -125,6 +152,13 @@ public AutoTool() {
125152
private void onTick(TickEvent.Post event) {
126153
if (Modules.get().isActive(InfinityMiner.class)) return;
127154

155+
if (invSwapReturn.get() && !mc.options.attackKey.isPressed() && wasPressed && toolWasIn != -1) {
156+
InvUtils.quickSwap().fromId(invSwapSlot.get()).to(toolWasIn);
157+
toolWasIn = -1;
158+
wasPressed = false;
159+
return;
160+
}
161+
128162
if (switchBack.get() && !mc.options.attackKey.isPressed() && wasPressed && InvUtils.previousSlot != -1) {
129163
InvUtils.swapBack();
130164
wasPressed = false;
@@ -156,7 +190,9 @@ private void onStartBreakingBlock(StartBreakingBlockEvent event) {
156190
double bestScore = -1;
157191
bestSlot = -1;
158192

159-
for (int i = 0; i < 9; i++) {
193+
int max = invSwap.get() ? SlotUtils.MAIN_END : 9;
194+
195+
for (int i = 0; i < max; i++) {
160196
ItemStack itemStack = mc.player.getInventory().getStack(i);
161197

162198
if (listMode.get() == ListMode.Whitelist && !whitelist.get().contains(itemStack.getItem())) continue;
@@ -183,11 +219,25 @@ private void onStartBreakingBlock(StartBreakingBlockEvent event) {
183219
}
184220
}
185221

222+
int returnToolTo = toolWasIn;
223+
224+
if (bestSlot > 8) {
225+
toolWasIn = bestSlot;
226+
bestSlot = invSwapSlot.get();
227+
}
228+
186229
if ((bestSlot != -1 && (bestScore > getScore(currentStack, blockState, silkTouchForEnderChest.get(), fortuneForOresCrops.get(), prefer.get(), itemStack -> ToolSaver.canUse(itemStack) || ToolSaver.canUse(currentStack) || !isTool(currentStack))))) {
187230
ticks = switchDelay.get();
188231

232+
if (invSwapReturn.get() && returnToolTo > 8) InvUtils.quickSwap().fromId(invSwapSlot.get()).to(returnToolTo);
233+
189234
if (ticks == 0) InvUtils.swap(bestSlot, true);
190235
else shouldSwitch = true;
236+
237+
if (toolWasIn > 8) {
238+
if (bestSlot == invSwapSlot.get()) InvUtils.quickSwap().fromId(invSwapSlot.get()).to(toolWasIn);
239+
else toolWasIn = -1;
240+
}
191241
}
192242

193243
}

0 commit comments

Comments
 (0)