infinity-miner module

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

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.

Meteor ClientWorldsrc/main/java/meteordevelopment/meteorclient/systems/modules/world/InfinityMiner.javaJava · 247 lines · 8.9 KB

Allows you to essentially mine forever by mining repair blocks when the durability gets low. Needs a mending pickaxe.

Settingstarget-blockstarget-itemsrepair-blocksrepair-thresholdmine-thresholdwalk-homelog-out
InfinityMiner.javaJava · Minecraft 26.2 · 247 lines · 8.9 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.world;
7
8
import baritone.api.BaritoneAPI;
9
import baritone.api.IBaritone;
10
import baritone.api.Settings;
11
import baritone.api.pathing.goals.GoalBlock;
12
import baritone.api.process.ICustomGoalProcess;
13
import baritone.api.process.IMineProcess;
14
import meteordevelopment.meteorclient.events.world.TickEvent;
15
import meteordevelopment.meteorclient.settings.*;
16
import meteordevelopment.meteorclient.systems.modules.Categories;
17
import meteordevelopment.meteorclient.systems.modules.Module;
18
import meteordevelopment.meteorclient.utils.Utils;
19
import meteordevelopment.meteorclient.utils.player.FindItemResult;
20
import meteordevelopment.meteorclient.utils.player.InvUtils;
21
import meteordevelopment.orbit.EventHandler;
22
import net.minecraft.core.BlockPos;
23
import net.minecraft.network.chat.Component;
24
import net.minecraft.network.protocol.common.ClientboundDisconnectPacket;
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
import net.minecraft.world.level.block.LiquidBlock;
33
34
import java.util.List;
35
import java.util.function.Predicate;
36
37
public class InfinityMiner extends Module {
38
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
39
    private final SettingGroup sgWhenFull = settings.createGroup("When Full");
40
41
    // General
42
43
    public final Setting<List<Block>> targetBlocks = sgGeneral.add(new BlockListSetting.Builder()
44
        .name("target-blocks")
45
        .description("The target blocks to mine.")
46
        .defaultValue(Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE)
47
        .filter(this::filterBlocks)
48
        .build()
49
    );
50
51
    public final Setting<List<Item>> targetItems = sgGeneral.add(new ItemListSetting.Builder()
52
        .name("target-items")
53
        .description("The target items to collect.")
54
        .defaultValue(Items.DIAMOND)
55
        .build()
56
    );
57
58
    public final Setting<List<Block>> repairBlocks = sgGeneral.add(new BlockListSetting.Builder()
59
        .name("repair-blocks")
60
        .description("The repair blocks to mine.")
61
        .defaultValue(Blocks.COAL_ORE, Blocks.REDSTONE_ORE, Blocks.NETHER_QUARTZ_ORE)
62
        .filter(this::filterBlocks)
63
        .build()
64
    );
65
66
    public final Setting<Double> startRepairing = sgGeneral.add(new DoubleSetting.Builder()
67
        .name("repair-threshold")
68
        .description("The durability percentage at which to start repairing.")
69
        .defaultValue(20)
70
        .range(1, 99)
71
        .sliderRange(1, 99)
72
        .build()
73
    );
74
75
    public final Setting<Double> startMining = sgGeneral.add(new DoubleSetting.Builder()
76
        .name("mine-threshold")
77
        .description("The durability percentage at which to start mining.")
78
        .defaultValue(70)
79
        .range(1, 99)
80
        .sliderRange(1, 99)
81
        .build()
82
    );
83
84
    // When Full
85
86
    public final Setting<Boolean> walkHome = sgWhenFull.add(new BoolSetting.Builder()
87
        .name("walk-home")
88
        .description("Will walk 'home' when your inventory is full.")
89
        .defaultValue(false)
90
        .build()
91
    );
92
93
    public final Setting<Boolean> logOut = sgWhenFull.add(new BoolSetting.Builder()
94
        .name("log-out")
95
        .description("Logs out when your inventory is full. Will walk home FIRST if walk home is enabled.")
96
        .defaultValue(false)
97
        .build()
98
    );
99
100
    private final IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
101
    private final Settings baritoneSettings = BaritoneAPI.getSettings();
102
103
    private final BlockPos.MutableBlockPos homePos = new BlockPos.MutableBlockPos();
104
105
    private boolean prevMineScanDroppedItems;
106
    private boolean repairing;
107
108
    public InfinityMiner() {
109
        super(Categories.World, "infinity-miner", "Allows you to essentially mine forever by mining repair blocks when the durability gets low. Needs a mending pickaxe.");
110
    }
111
112
    @Override
113
    public void onActivate() {
114
        prevMineScanDroppedItems = baritoneSettings.mineScanDroppedItems.value;
115
        baritoneSettings.mineScanDroppedItems.value = true;
116
        homePos.set(mc.player.blockPosition());
117
        repairing = false;
118
    }
119
120
    @Override
121
    public void onDeactivate() {
122
        baritone.getPathingBehavior().cancelEverything();
123
        baritoneSettings.mineScanDroppedItems.value = prevMineScanDroppedItems;
124
    }
125
126
    @EventHandler
127
    private void onTick(TickEvent.Post event) {
128
        if (isFull()) {
129
            if (walkHome.get()) {
130
                if (isBaritoneNotWalking()) {
131
                    info("Walking home.");
132
                    baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(homePos));
133
                } else if (mc.player.blockPosition().equals(homePos) && logOut.get()) logOut();
134
            } else if (logOut.get()) logOut();
135
            else {
136
                info("Inventory full, stopping process.");
137
                toggle();
138
            }
139
140
            return;
141
        }
142
143
        if (!findPickaxe()) {
144
            error("Could not find a usable mending pickaxe.");
145
            toggle();
146
            return;
147
        }
148
149
        if (!checkThresholds()) {
150
            error("Start mining value can't be lower than start repairing value.");
151
            toggle();
152
            return;
153
        }
154
155
        if (repairing) {
156
            if (!needsRepair()) {
157
                warning("Finished repairing, going back to mining.");
158
                repairing = false;
159
                baritoneSettings.mineScanDroppedItems.value = true;
160
                mineTargetBlocks();
161
                return;
162
            }
163
164
            if (isBaritoneNotMining()) mineRepairBlocks();
165
        } else {
166
            if (needsRepair()) {
167
                warning("Pickaxe needs repair, beginning repair process");
168
                repairing = true;
169
                baritoneSettings.mineScanDroppedItems.value = false;
170
                mineRepairBlocks();
171
                return;
172
            }
173
174
            if (isBaritoneNotMining()) mineTargetBlocks();
175
        }
176
    }
177
178
    private boolean needsRepair() {
179
        ItemStack itemStack = mc.player.getMainHandItem();
180
        double toolPercentage = ((itemStack.getMaxDamage() - itemStack.getDamageValue()) * 100f) / (float) itemStack.getMaxDamage();
181
        return !(toolPercentage > startMining.get() || (toolPercentage > startRepairing.get() && !repairing));
182
    }
183
184
    private boolean findPickaxe() {
185
        Predicate<ItemStack> pickaxePredicate = (stack -> stack.is(ItemTags.PICKAXES)
186
            && Utils.hasEnchantment(stack, Enchantments.MENDING)
187
            && !Utils.hasEnchantment(stack, Enchantments.SILK_TOUCH));
188
        FindItemResult bestPick = InvUtils.findInHotbar(pickaxePredicate);
189
190
        if (bestPick.isOffhand())
191
            InvUtils.shiftClick().fromOffhand().toHotbar(mc.player.getInventory().getSelectedSlot());
192
        else if (bestPick.isHotbar()) InvUtils.swap(bestPick.slot(), false);
193
194
        return InvUtils.testInMainHand(pickaxePredicate);
195
    }
196
197
    private boolean checkThresholds() {
198
        return startRepairing.get() < startMining.get();
199
    }
200
201
    private void mineTargetBlocks() {
202
        Block[] array = new Block[targetBlocks.get().size()];
203
204
        baritone.getPathingBehavior().cancelEverything();
205
        baritone.getMineProcess().mine(targetBlocks.get().toArray(array));
206
    }
207
208
    private void mineRepairBlocks() {
209
        Block[] array = new Block[repairBlocks.get().size()];
210
211
        baritone.getPathingBehavior().cancelEverything();
212
        baritone.getMineProcess().mine(repairBlocks.get().toArray(array));
213
    }
214
215
    private void logOut() {
216
        toggle();
217
        mc.player.connection.send(new ClientboundDisconnectPacket(Component.literal("[Infinity Miner] Inventory is full.")));
218
    }
219
220
    private boolean isBaritoneNotMining() {
221
        return !(baritone.getPathingControlManager().mostRecentInControl().orElse(null) instanceof IMineProcess);
222
    }
223
224
    private boolean isBaritoneNotWalking() {
225
        return !(baritone.getPathingControlManager().mostRecentInControl().orElse(null) instanceof ICustomGoalProcess);
226
    }
227
228
    private boolean filterBlocks(Block block) {
229
        return block != Blocks.AIR && block.defaultBlockState().getDestroySpeed(mc.level, null) != -1 && !(block instanceof LiquidBlock);
230
    }
231
232
    private boolean isFull() {
233
        for (int i = 0; i <= 35; i++) {
234
            ItemStack itemStack = mc.player.getInventory().getItem(i);
235
            if (itemStack.isEmpty()) return false;
236
237
            for (Item item : targetItems.get()) {
238
                if (itemStack.getItem() == item && itemStack.getCount() < itemStack.getMaxStackSize()) {
239
                    return false;
240
                }
241
            }
242
        }
243
244
        return true;
245
    }
246
}
247