auto-tool module

auto-tool: Minecraft 26.3 cheat module, full source for every implementation (1 client: Meteor Client).

1 implementationPlayer

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

Meteor ClientPlayersrc/main/java/meteordevelopment/meteorclient/systems/modules/player/AutoTool.javaJava · 255 lines · 9.7 KB

Automatically switches to the most effective tool when performing an action.

Settingsprefersilk-touch-for-ender-chestfortune-for-ores-and-cropsanti-breakanti-break-percentageswitch-backswitch-delaylist-modewhitelistblacklist
AutoTool.javaJava · Minecraft 26.2 · 255 lines · 9.7 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.player;
7
8
9
import meteordevelopment.meteorclient.events.entity.player.StartBreakingBlockEvent;
10
import meteordevelopment.meteorclient.events.world.TickEvent;
11
import meteordevelopment.meteorclient.settings.*;
12
import meteordevelopment.meteorclient.systems.modules.Categories;
13
import meteordevelopment.meteorclient.systems.modules.Module;
14
import meteordevelopment.meteorclient.systems.modules.Modules;
15
import meteordevelopment.meteorclient.systems.modules.render.Xray;
16
import meteordevelopment.meteorclient.systems.modules.world.InfinityMiner;
17
import meteordevelopment.meteorclient.utils.Utils;
18
import meteordevelopment.meteorclient.utils.misc.ListMode;
19
import meteordevelopment.meteorclient.utils.player.InvUtils;
20
import meteordevelopment.meteorclient.utils.world.BlockUtils;
21
import meteordevelopment.orbit.EventHandler;
22
import meteordevelopment.orbit.EventPriority;
23
import net.minecraft.core.component.DataComponents;
24
import net.minecraft.tags.BlockTags;
25
import net.minecraft.tags.ItemTags;
26
import net.minecraft.world.item.Item;
27
import net.minecraft.world.item.ItemStack;
28
import net.minecraft.world.item.ShearsItem;
29
import net.minecraft.world.item.enchantment.Enchantments;
30
import net.minecraft.world.level.block.*;
31
import net.minecraft.world.level.block.state.BlockState;
32
33
import java.util.List;
34
import java.util.function.Predicate;
35
36
public class AutoTool extends Module {
37
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
38
    private final SettingGroup sgWhitelist = settings.createGroup("Whitelist");
39
40
    // General
41
42
    private final Setting<EnchantPreference> prefer = sgGeneral.add(new EnumSetting.Builder<EnchantPreference>()
43
        .name("prefer")
44
        .description("Either to prefer Silk Touch, Fortune, or none.")
45
        .defaultValue(EnchantPreference.Fortune)
46
        .build()
47
    );
48
49
    private final Setting<Boolean> silkTouchForEnderChest = sgGeneral.add(new BoolSetting.Builder()
50
        .name("silk-touch-for-ender-chest")
51
        .description("Mines Ender Chests only with the Silk Touch enchantment.")
52
        .defaultValue(true)
53
        .build()
54
    );
55
56
    private final Setting<Boolean> fortuneForOresCrops = sgGeneral.add(new BoolSetting.Builder()
57
        .name("fortune-for-ores-and-crops")
58
        .description("Mines Ores and crops only with the Fortune enchantment.")
59
        .defaultValue(false)
60
        .build()
61
    );
62
63
    private final Setting<Boolean> antiBreak = sgGeneral.add(new BoolSetting.Builder()
64
        .name("anti-break")
65
        .description("Stops you from breaking your tool.")
66
        .defaultValue(false)
67
        .build()
68
    );
69
70
    private final Setting<Integer> breakDurability = sgGeneral.add(new IntSetting.Builder()
71
        .name("anti-break-percentage")
72
        .description("The durability percentage to stop using a tool.")
73
        .defaultValue(10)
74
        .range(1, 100)
75
        .sliderRange(1, 100)
76
        .visible(antiBreak::get)
77
        .build()
78
    );
79
80
    private final Setting<Boolean> switchBack = sgGeneral.add(new BoolSetting.Builder()
81
        .name("switch-back")
82
        .description("Switches your hand to whatever was selected when releasing your attack key.")
83
        .defaultValue(false)
84
        .build()
85
    );
86
87
    private final Setting<Integer> switchDelay = sgGeneral.add((new IntSetting.Builder()
88
        .name("switch-delay")
89
        .description("Delay in ticks before switching tools.")
90
        .defaultValue(0)
91
        .build()
92
    ));
93
94
    // Whitelist and blacklist
95
96
    private final Setting<ListMode> listMode = sgWhitelist.add(new EnumSetting.Builder<ListMode>()
97
        .name("list-mode")
98
        .description("Selection mode.")
99
        .defaultValue(ListMode.Blacklist)
100
        .build()
101
    );
102
103
    private final Setting<List<Item>> whitelist = sgWhitelist.add(new ItemListSetting.Builder()
104
        .name("whitelist")
105
        .description("The tools you want to use.")
106
        .visible(() -> listMode.get() == ListMode.Whitelist)
107
        .filter(AutoTool::isTool)
108
        .build()
109
    );
110
111
    private final Setting<List<Item>> blacklist = sgWhitelist.add(new ItemListSetting.Builder()
112
        .name("blacklist")
113
        .description("The tools you don't want to use.")
114
        .visible(() -> listMode.get() == ListMode.Blacklist)
115
        .filter(AutoTool::isTool)
116
        .build()
117
    );
118
119
    private boolean wasPressed;
120
    private boolean shouldSwitch;
121
    private int ticks;
122
    private int bestSlot;
123
124
    public AutoTool() {
125
        super(Categories.Player, "auto-tool", "Automatically switches to the most effective tool when performing an action.");
126
    }
127
128
    @EventHandler
129
    private void onTick(TickEvent.Post event) {
130
        if (Modules.get().isActive(InfinityMiner.class)) return;
131
132
        if (switchBack.get() && !mc.options.keyAttack.isDown() && wasPressed && InvUtils.previousSlot != -1) {
133
            InvUtils.swapBack();
134
            wasPressed = false;
135
            return;
136
        }
137
138
        if (ticks <= 0 && shouldSwitch && bestSlot != -1) {
139
            InvUtils.swap(bestSlot, switchBack.get());
140
            shouldSwitch = false;
141
        } else {
142
            ticks--;
143
        }
144
145
        wasPressed = mc.options.keyAttack.isDown();
146
    }
147
148
    @EventHandler(priority = EventPriority.HIGH)
149
    private void onStartBreakingBlock(StartBreakingBlockEvent event) {
150
        if (Modules.get().isActive(InfinityMiner.class)) return;
151
        if (mc.player.isCreative()) return;
152
153
        // Get blockState
154
        BlockState blockState = mc.level.getBlockState(event.blockPos);
155
        if (!BlockUtils.canBreak(event.blockPos, blockState)) return;
156
157
        // Check if we should switch to a better tool
158
        ItemStack currentStack = mc.player.getMainHandItem();
159
160
        double bestScore = -1;
161
        bestSlot = -1;
162
163
        for (int i = 0; i < 9; i++) {
164
            ItemStack itemStack = mc.player.getInventory().getItem(i);
165
166
            boolean itemInList = (listMode.get() == ListMode.Whitelist ? whitelist.get() : blacklist.get()).contains(itemStack.getItem());
167
            if (!listMode.get().allows(itemInList)) continue;
168
169
            double score = getScore(itemStack, blockState, silkTouchForEnderChest.get(), fortuneForOresCrops.get(), prefer.get(), itemStack2 -> !shouldStopUsing(itemStack2));
170
            if (score < 0) continue;
171
172
            if (score > bestScore) {
173
                bestScore = score;
174
                bestSlot = i;
175
            }
176
        }
177
178
        if ((bestSlot != -1 && (bestScore > getScore(currentStack, blockState, silkTouchForEnderChest.get(), fortuneForOresCrops.get(), prefer.get(), itemStack -> !shouldStopUsing(itemStack))) || shouldStopUsing(currentStack) || !isTool(currentStack))) {
179
            ticks = switchDelay.get();
180
181
            if (ticks == 0) InvUtils.swap(bestSlot, true);
182
            else shouldSwitch = true;
183
        }
184
185
        // Anti break
186
        currentStack = mc.player.getMainHandItem();
187
188
        if (shouldStopUsing(currentStack) && isTool(currentStack)) {
189
            mc.options.keyAttack.setDown(false);
190
            event.cancel();
191
        }
192
    }
193
194
    private boolean shouldStopUsing(ItemStack itemStack) {
195
        return antiBreak.get() && (itemStack.getMaxDamage() - itemStack.getDamageValue()) < (itemStack.getMaxDamage() * breakDurability.get() / 100);
196
    }
197
198
    public static double getScore(ItemStack itemStack, BlockState state, boolean silkTouchEnderChest, boolean fortuneOre, EnchantPreference enchantPreference, Predicate<ItemStack> good) {
199
        if (!good.test(itemStack) || !isTool(itemStack)) return -1;
200
        if (!itemStack.isCorrectToolForDrops(state) &&
201
            !(itemStack.is(ItemTags.SWORDS) && (state.getBlock() instanceof BambooStalkBlock || state.getBlock() instanceof BambooSaplingBlock)) &&
202
            !(itemStack.getItem() instanceof ShearsItem && state.getBlock() instanceof LeavesBlock || state.is(BlockTags.WOOL)))
203
            return -1;
204
205
        if (silkTouchEnderChest
206
            && state.getBlock() == Blocks.ENDER_CHEST
207
            && !Utils.hasEnchantments(itemStack, Enchantments.SILK_TOUCH)) {
208
            return -1;
209
        }
210
211
        if (fortuneOre
212
            && isFortunable(state.getBlock())
213
            && !Utils.hasEnchantments(itemStack, Enchantments.FORTUNE)) {
214
            return -1;
215
        }
216
217
        double score = 0;
218
219
        score += itemStack.getDestroySpeed(state) * 1000;
220
        score += Utils.getEnchantmentLevel(itemStack, Enchantments.UNBREAKING);
221
        score += Utils.getEnchantmentLevel(itemStack, Enchantments.EFFICIENCY);
222
        score += Utils.getEnchantmentLevel(itemStack, Enchantments.MENDING);
223
224
        if (enchantPreference == EnchantPreference.Fortune)
225
            score += Utils.getEnchantmentLevel(itemStack, Enchantments.FORTUNE);
226
        if (enchantPreference == EnchantPreference.SilkTouch)
227
            score += Utils.getEnchantmentLevel(itemStack, Enchantments.SILK_TOUCH);
228
229
        if (itemStack.is(ItemTags.SWORDS) && (state.getBlock() instanceof BambooStalkBlock || state.getBlock() instanceof BambooSaplingBlock))
230
            score += 9000 + (itemStack.get(DataComponents.TOOL).getMiningSpeed(state) * 1000);
231
232
        return score;
233
    }
234
235
    public static boolean isTool(Item item) {
236
        return isTool(item.getDefaultInstance());
237
    }
238
239
    public static boolean isTool(ItemStack itemStack) {
240
        return itemStack.is(ItemTags.AXES) || itemStack.is(ItemTags.HOES) || itemStack.is(ItemTags.PICKAXES) || itemStack.is(ItemTags.SHOVELS) || itemStack.getItem() instanceof ShearsItem;
241
    }
242
243
    private static boolean isFortunable(Block block) {
244
        if (block == Blocks.ANCIENT_DEBRIS) return false;
245
        return Xray.ORES.contains(block) || block instanceof CropBlock;
246
    }
247
248
    public enum EnchantPreference {
249
        None,
250
        Fortune,
251
        SilkTouch
252
    }
253
254
}
255