InfinityMiner module

InfinityMiner: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

1 implementationWORLD

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.

OfflineClientWORLDsrc/main/java/com/jellypudding/offlineclient/modules/world/InfinityMiner.javaJava · 298 lines · 11.1 KB

Mines ore for ever and lets Mending heal the pickaxe on the way.

SettingsTarget blocksTarget itemsRepair blocksRepair atMine atScan rangeWhen fullRotateShow target
InfinityMiner.javaJava · Minecraft 26.2 · 298 lines · 11.1 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.world;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.Render3DEvent;
5
import com.jellypudding.offlineclient.event.events.TickEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.ExclusivityGroup;
8
import com.jellypudding.offlineclient.module.Module;
9
import com.jellypudding.offlineclient.path.PathWalker;
10
import com.jellypudding.offlineclient.path.Trip;
11
import com.jellypudding.offlineclient.render.BoxStyle;
12
import com.jellypudding.offlineclient.setting.BoolSetting;
13
import com.jellypudding.offlineclient.setting.EnumSetting;
14
import com.jellypudding.offlineclient.setting.NumberSetting;
15
import com.jellypudding.offlineclient.setting.RegistryListSetting;
16
import com.jellypudding.offlineclient.util.BlockMiner;
17
import com.jellypudding.offlineclient.util.BlockUtil;
18
import com.jellypudding.offlineclient.util.ChatUtil;
19
import com.jellypudding.offlineclient.util.InventoryUtil;
20
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
21
import com.jellypudding.offlineclient.util.ItemUtil;
22
import net.minecraft.core.BlockPos;
23
import net.minecraft.core.registries.BuiltInRegistries;
24
import net.minecraft.network.chat.Component;
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.Items;
29
import net.minecraft.world.item.enchantment.Enchantments;
30
import net.minecraft.world.level.block.Block;
31
import net.minecraft.world.level.block.Blocks;
32
33
import java.util.HashMap;
34
import java.util.List;
35
import java.util.Map;
36
37
// Mines for as long as the pickaxe lasts. When it wears down the bot swaps to
38
// ore that drops experience and lets Mending heal it before going back.
39
public final class InfinityMiner extends Module {
40
41
    public enum WhenFull { STOP, WALK_HOME, LOG_OUT, WALK_HOME_AND_LOG_OUT }
42
43
    private static final int SCAN_TICKS = 40;
44
    // Ticks a spot the walker could not reach is left alone.
45
    private static final int SHUN_TICKS = 1200;
46
    private static final double GOAL_RADIUS = 3;
47
    private static final int PERCENT = 100;
48
49
    private final RegistryListSetting<Block> targetBlocks = new RegistryListSetting<>("Target blocks",
50
        "The ore mined whilst the pickaxe is healthy. Click to pick it.", BuiltInRegistries.BLOCK,
51
        List.of(Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE));
52
    private final RegistryListSetting<Item> targetItems = new RegistryListSetting<>("Target items",
53
        "What the ore drops. A full bag with none of these part stacked counts as full.",
54
        BuiltInRegistries.ITEM, List.of(Items.DIAMOND));
55
    private final RegistryListSetting<Block> repairBlocks = new RegistryListSetting<>("Repair blocks",
56
        "The ore mined for experience whilst the pickaxe heals. Click to pick it.",
57
        BuiltInRegistries.BLOCK,
58
        List.of(Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, Blocks.REDSTONE_ORE,
59
            Blocks.DEEPSLATE_REDSTONE_ORE, Blocks.NETHER_QUARTZ_ORE));
60
    private final NumberSetting repairAt = new NumberSetting("Repair at",
61
        "Pickaxe durability that starts the repair.", 20, 1, 99, 1, "%").min(1).max(99);
62
    private final NumberSetting mineAt = new NumberSetting("Mine at",
63
        "Pickaxe durability that ends the repair.", 70, 1, 99, 1, "%").min(1).max(99);
64
    private final NumberSetting scanRange = new NumberSetting("Scan range",
65
        "How far around you ore is looked for.", 16, 4, 48, 1, " blocks").min(2).max(64);
66
    private final EnumSetting<WhenFull> whenFull = new EnumSetting<>("When full",
67
        "What happens once the bag is full.", WhenFull.STOP)
68
        .describe(WhenFull.STOP, "Switches off where you stand.")
69
        .describe(WhenFull.WALK_HOME, "Walks back to where you switched it on.")
70
        .describe(WhenFull.LOG_OUT, "Leaves the server where you stand.")
71
        .describe(WhenFull.WALK_HOME_AND_LOG_OUT, "Walks back to the start and leaves the server there.");
72
    private final BoolSetting rotate = new BoolSetting("Rotate",
73
        "Turns towards each block on the server side.", true);
74
    private final BoolSetting render = new BoolSetting("Show target",
75
        "Outlines the block being walked to.", true);
76
    private final BoxStyle targetBox = new BoxStyle(BoxStyle.Shape.BOTH, 180).under(render);
77
78
    private final Trip trip = new Trip();
79
    private final SlotSwap slots = new SlotSwap();
80
    private final Map<BlockPos, Integer> shunned = new HashMap<>();
81
82
    private BlockPos home;
83
    private BlockPos target;
84
    private boolean repairing;
85
    private boolean headingHome;
86
    private int scanTimer;
87
88
    public InfinityMiner() {
89
        super("InfinityMiner", "Mines ore for ever and lets Mending heal the pickaxe on the way.",
90
            Category.WORLD);
91
        addSettings(targetBlocks, targetItems, repairBlocks, repairAt, mineAt, scanRange, whenFull,
92
            rotate, render);
93
        addSettings(targetBox.settings());
94
        searchTags("infinity miner", "auto mine", "mending", "ore bot");
95
    }
96
97
    @Override
98
    public boolean savesEnabledState() {
99
        return false;
100
    }
101
102
    @Override
103
    public ExclusivityGroup getExclusivityGroup() {
104
        return ExclusivityGroup.MINING;
105
    }
106
107
    @Override
108
    public String getSuffix() {
109
        if (headingHome) {
110
            return "going home";
111
        }
112
        return repairing ? "repairing" : null;
113
    }
114
115
    @Override
116
    protected void onEnable() {
117
        target = null;
118
        repairing = false;
119
        headingHome = false;
120
        scanTimer = 0;
121
        shunned.clear();
122
        home = inGame() ? mc.player.blockPosition() : null;
123
        trip.finder().breakBlocks(true);
124
        trip.walker().turn(PathWalker.Turn.CLIENT);
125
    }
126
127
    @Override
128
    protected void onDisable() {
129
        trip.stop();
130
        BlockMiner.release();
131
        slots.restoreIfMine();
132
        target = null;
133
    }
134
135
    @Subscribe
136
    private void onTick(TickEvent event) {
137
        if (!inGame() || mc.player.isSpectator() || mc.gui.screen() != null) {
138
            return;
139
        }
140
        if (headingHome) {
141
            walkHome();
142
            return;
143
        }
144
        if (isFull()) {
145
            onFull();
146
            return;
147
        }
148
        if (!holdPickaxe()) {
149
            ChatUtil.error("InfinityMiner needs a Mending pickaxe without Silk Touch in the hotbar.");
150
            setEnabled(false);
151
            return;
152
        }
153
        if (repairAt.getValue() >= mineAt.getValue()) {
154
            ChatUtil.error("Repair at has to be lower than Mine at.");
155
            setEnabled(false);
156
            return;
157
        }
158
        updateRepairing();
159
        forgetShunned();
160
        if (target != null && !wanted(target)) {
161
            target = null;
162
            trip.stop();
163
        }
164
        if (target == null && !scan()) {
165
            return;
166
        }
167
        if (BlockUtil.distanceTo(target) <= mc.player.blockInteractionRange()) {
168
            trip.stop();
169
            BlockMiner.mine(target, rotate.isOn());
170
            return;
171
        }
172
        BlockMiner.release();
173
        if (!trip.active()) {
174
            trip.start(target, GOAL_RADIUS);
175
        }
176
        // A walk that ends short of reach has run into something the walker cannot pass.
177
        Trip.State state = trip.tick();
178
        if (state == Trip.State.FAILED || state == Trip.State.ARRIVED) {
179
            shunned.put(target, mc.player.tickCount);
180
            target = null;
181
        }
182
    }
183
184
    // A worn pickaxe swaps the target to experience ore until it is healthy again.
185
    private void updateRepairing() {
186
        ItemStack pick = mc.player.getMainHandItem();
187
        double left = (pick.getMaxDamage() - pick.getDamageValue()) * (double) PERCENT / pick.getMaxDamage();
188
        if (!repairing && left <= repairAt.getValue()) {
189
            repairing = true;
190
            target = null;
191
            ChatUtil.message("The pickaxe is worn. Mining for experience now.");
192
        } else if (repairing && left >= mineAt.getValue()) {
193
            repairing = false;
194
            target = null;
195
            ChatUtil.message("The pickaxe has healed. Back to the ore.");
196
        }
197
    }
198
199
    private boolean wanted(BlockPos pos) {
200
        Block block = BlockUtil.state(pos).getBlock();
201
        return (repairing ? repairBlocks : targetBlocks).contains(block);
202
    }
203
204
    // The nearest wanted ore in range. A scan is not cheap and only runs now and then.
205
    private boolean scan() {
206
        if (scanTimer-- > 0) {
207
            return false;
208
        }
209
        scanTimer = SCAN_TICKS;
210
        for (BlockPos pos : BlockUtil.positionsWithin(scanRange.getValue())) {
211
            if (wanted(pos) && !shunned.containsKey(pos)) {
212
                target = pos.immutable();
213
                return true;
214
            }
215
        }
216
        return false;
217
    }
218
219
    private void forgetShunned() {
220
        int now = mc.player.tickCount;
221
        shunned.values().removeIf(when -> now - when > SHUN_TICKS || now < when);
222
    }
223
224
    private boolean holdPickaxe() {
225
        int slot = InventoryUtil.hotbarSlot(stack -> stack.is(ItemTags.PICKAXES)
226
            && ItemUtil.enchantLevel(Enchantments.MENDING, stack) > 0
227
            && ItemUtil.enchantLevel(Enchantments.SILK_TOUCH, stack) == 0);
228
        if (slot == -1) {
229
            return false;
230
        }
231
        slots.select(slot);
232
        return true;
233
    }
234
235
    // Full means no empty slot and no part stack of anything the ore drops.
236
    private boolean isFull() {
237
        for (int i = 0; i < InventoryUtil.WHOLE_INVENTORY; i++) {
238
            ItemStack stack = mc.player.getInventory().getItem(i);
239
            if (stack.isEmpty()) {
240
                return false;
241
            }
242
            if (targetItems.contains(stack.getItem()) && stack.getCount() < stack.getMaxStackSize()) {
243
                return false;
244
            }
245
        }
246
        return true;
247
    }
248
249
    private void onFull() {
250
        BlockMiner.release();
251
        switch (whenFull.getValue()) {
252
            case STOP -> {
253
                ChatUtil.message("The bag is full.");
254
                setEnabled(false);
255
            }
256
            case LOG_OUT -> logOut();
257
            case WALK_HOME, WALK_HOME_AND_LOG_OUT -> {
258
                headingHome = true;
259
                target = null;
260
                trip.start(home, 0);
261
                ChatUtil.message("The bag is full. Walking home.");
262
            }
263
        }
264
    }
265
266
    private void walkHome() {
267
        switch (trip.tick()) {
268
            case ARRIVED -> {
269
                if (whenFull.is(WhenFull.WALK_HOME_AND_LOG_OUT)) {
270
                    logOut();
271
                } else {
272
                    ChatUtil.message("Home with a full bag.");
273
                    setEnabled(false);
274
                }
275
            }
276
            case FAILED -> {
277
                ChatUtil.error("Could not find the way home.");
278
                setEnabled(false);
279
            }
280
            default -> {
281
            }
282
        }
283
    }
284
285
    private void logOut() {
286
        setEnabled(false);
287
        mc.player.connection.getConnection().disconnect(
288
            Component.literal("§b[§3Offline§b] §fInfinityMiner filled the bag."));
289
    }
290
291
    @Subscribe
292
    private void onRender3D(Render3DEvent event) {
293
        if (render.isOn() && target != null) {
294
            targetBox.draw(event.getBatch(), target, true);
295
        }
296
    }
297
}
298