VeinMiner module

VeinMiner: 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/VeinMiner.javaJava · 253 lines · 9.3 KB

Mines a whole vein of ore when you break one block of it.

SettingsRangeDelayMax blocksTargetsBlocksList modeFlatLine of sightRotateRender
VeinMiner.javaJava · Minecraft 26.2 · 253 lines · 9.3 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.BlockBreakEvent;
5
import com.jellypudding.offlineclient.event.events.Render3DEvent;
6
import com.jellypudding.offlineclient.event.events.TickEvent;
7
import com.jellypudding.offlineclient.module.Category;
8
import com.jellypudding.offlineclient.module.ExclusivityGroup;
9
import com.jellypudding.offlineclient.module.Module;
10
import com.jellypudding.offlineclient.render.BoxStyle;
11
import com.jellypudding.offlineclient.setting.BoolSetting;
12
import com.jellypudding.offlineclient.setting.EnumSetting;
13
import com.jellypudding.offlineclient.setting.NumberSetting;
14
import com.jellypudding.offlineclient.setting.RegistryListSetting;
15
import com.jellypudding.offlineclient.util.BlockMiner;
16
import com.jellypudding.offlineclient.util.BlockUtil;
17
import com.jellypudding.offlineclient.util.SwingMode;
18
import net.minecraft.core.BlockPos;
19
import net.minecraft.core.registries.BuiltInRegistries;
20
import net.minecraft.tags.BlockTags;
21
import net.minecraft.world.level.block.Block;
22
import net.minecraft.world.level.block.Blocks;
23
import net.minecraft.world.level.block.state.BlockState;
24
25
import java.util.ArrayDeque;
26
import java.util.Comparator;
27
import java.util.Deque;
28
import java.util.LinkedHashSet;
29
import java.util.List;
30
import java.util.Set;
31
32
// Mining an ore mines every connected ore of the same kind too.
33
// Deepslate and stone variants count as one vein.
34
public final class VeinMiner extends Module {
35
36
    public enum Targets { ORES, ORES_AND_LOGS, ANY_BLOCK, LIST }
37
38
    public enum ListMode { WHITELIST, BLACKLIST }
39
40
    private final NumberSetting range = new NumberSetting("Range",
41
        "How far from your eyes a vein block may be.", 4.5, 1, 6, 0.1).min(1).max(6);
42
    private final NumberSetting delay = new NumberSetting("Delay",
43
        "Ticks to wait between one block and the next.", 0, 0, 20, 1, " ticks").min(0);
44
    private final NumberSetting maxBlocks = new NumberSetting("Max blocks",
45
        "The most blocks one vein may contain.", 32, 1, 128, 1).min(1);
46
    private final EnumSetting<Targets> targets = new EnumSetting<>("Targets",
47
        "Which block types count as a vein.", Targets.ORES)
48
        .describe(Targets.ORES, "Only ore veins.")
49
        .describe(Targets.ORES_AND_LOGS, "Ore veins and tree trunks.")
50
        .describe(Targets.ANY_BLOCK, "Any run of matching blocks.")
51
        .describe(Targets.LIST, "Whatever the list below allows.");
52
    private final RegistryListSetting<Block> blocks = new RegistryListSetting<>("Blocks",
53
        "The blocks the list applies to. Click to pick them.", BuiltInRegistries.BLOCK,
54
        List.of(Blocks.STONE, Blocks.DIRT, Blocks.GRASS_BLOCK))
55
        .under(targets, Targets.LIST);
56
    private final EnumSetting<ListMode> listMode = new EnumSetting<>("List mode",
57
        "What the list means.", ListMode.BLACKLIST)
58
        .describe(ListMode.WHITELIST, "Only the listed blocks start a vein.")
59
        .describe(ListMode.BLACKLIST, "Everything but the listed blocks starts a vein.")
60
        .under(targets, Targets.LIST);
61
    private final BoolSetting flat = new BoolSetting("Flat",
62
        "Never mines a vein block below your feet so the floor stays under you.", false);
63
    private final BoolSetting lineOfSight = new BoolSetting("Line of sight",
64
        "Skips vein blocks your eyes cannot see.", false);
65
    private final BoolSetting rotate = new BoolSetting("Rotate",
66
        "Turn towards each block on the server side.", true);
67
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
68
    private final BoolSetting render = new BoolSetting("Render",
69
        "Draws a box on every block in the vein.", true);
70
    private final BoxStyle veinBox = new BoxStyle(BoxStyle.Shape.BOTH, 30).under(render);
71
72
    private final Set<BlockPos> vein = new LinkedHashSet<>();
73
    private String veinFamily;
74
    private BlockPos current;
75
    private BlockPos minedByHand;
76
    private int waitTicks;
77
78
    public VeinMiner() {
79
        super("VeinMiner", "Mines a whole vein of ore when you break one block of it.", Category.WORLD);
80
        addSettings(range, delay, maxBlocks, targets, blocks, listMode, flat, lineOfSight,
81
            rotate, swing, render);
82
        addSettings(veinBox.settings());
83
        searchTags("vein", "ore", "mining");
84
    }
85
86
    @Override
87
    public String getSuffix() {
88
        return count(vein.size());
89
    }
90
91
    @Override
92
    public ExclusivityGroup getExclusivityGroup() {
93
        return ExclusivityGroup.MINING;
94
    }
95
96
    @Override
97
    protected void onEnable() {
98
        clear();
99
    }
100
101
    @Override
102
    protected void onDisable() {
103
        BlockMiner.release();
104
        clear();
105
    }
106
107
    private void clear() {
108
        vein.clear();
109
        veinFamily = null;
110
        current = null;
111
        minedByHand = null;
112
        waitTicks = 0;
113
    }
114
115
    // Fires for the block mined by hand.
116
    @Subscribe
117
    private void onBlockBreak(BlockBreakEvent event) {
118
        if (BlockMiner.isSelfCall() || !inGame()) {
119
            return;
120
        }
121
        BlockPos pos = event.getPos();
122
        minedByHand = pos;
123
        if (vein.contains(pos)) {
124
            return;
125
        }
126
        BlockState state = BlockUtil.state(pos);
127
        if (isTarget(pos, state)) {
128
            build(pos, state);
129
        }
130
    }
131
132
    @Subscribe
133
    private void onTick(TickEvent event) {
134
        BlockPos byHand = minedByHand;
135
        minedByHand = null;
136
        if (!inGame() || mc.player.isSpectator()) {
137
            return;
138
        }
139
        prune();
140
        if (vein.isEmpty()) {
141
            current = null;
142
            return;
143
        }
144
        // The block under the crosshair keeps its vanilla mining.
145
        if (byHand != null && vein.contains(byHand)) {
146
            current = null;
147
            return;
148
        }
149
        if (current != null && BlockUtil.state(current).isAir()) {
150
            current = null;
151
            waitTicks = delay.getInt();
152
        }
153
        if (waitTicks > 0) {
154
            waitTicks--;
155
            BlockMiner.keepControl();
156
            return;
157
        }
158
        if (current == null || !vein.contains(current)) {
159
            current = vein.stream()
160
                .min(Comparator.comparingDouble(BlockUtil::distanceTo))
161
                .orElse(null);
162
        }
163
        if (current == null) {
164
            return;
165
        }
166
        if (!BlockMiner.mine(current, rotate.isOn(), swing.getValue())) {
167
            vein.remove(current);
168
            current = null;
169
        }
170
    }
171
172
    private void prune() {
173
        vein.removeIf(pos -> {
174
            BlockState state = BlockUtil.state(pos);
175
            return state.isAir()
176
                || !BlockUtil.family(state.getBlock()).equals(veinFamily)
177
                || !reachable(pos);
178
        });
179
        if (vein.isEmpty()) {
180
            veinFamily = null;
181
        }
182
    }
183
184
    // Flood fills from the origin. Corners count as touching.
185
    private void build(BlockPos origin, BlockState state) {
186
        vein.clear();
187
        veinFamily = BlockUtil.family(state.getBlock());
188
        current = null;
189
        waitTicks = 0;
190
191
        Deque<BlockPos> queue = new ArrayDeque<>();
192
        queue.add(origin);
193
        vein.add(origin);
194
        int limit = maxBlocks.getInt();
195
        while (!queue.isEmpty() && vein.size() < limit) {
196
            BlockPos here = queue.poll();
197
            for (int dx = -1; dx <= 1 && vein.size() < limit; dx++) {
198
                for (int dy = -1; dy <= 1 && vein.size() < limit; dy++) {
199
                    for (int dz = -1; dz <= 1 && vein.size() < limit; dz++) {
200
                        if (dx == 0 && dy == 0 && dz == 0) {
201
                            continue;
202
                        }
203
                        BlockPos next = here.offset(dx, dy, dz);
204
                        if (vein.contains(next) || !reachable(next)) {
205
                            continue;
206
                        }
207
                        BlockState nextState = BlockUtil.state(next);
208
                        if (nextState.isAir() || !BlockUtil.family(nextState.getBlock()).equals(veinFamily)) {
209
                            continue;
210
                        }
211
                        vein.add(next);
212
                        queue.add(next);
213
                    }
214
                }
215
            }
216
        }
217
    }
218
219
    // Range plus the optional floor guard and line of sight test.
220
    private boolean reachable(BlockPos pos) {
221
        if (BlockUtil.distanceTo(pos) > range.getValue()) {
222
            return false;
223
        }
224
        if (flat.isOn() && pos.getY() < mc.player.getBlockY()) {
225
            return false;
226
        }
227
        return !lineOfSight.isOn() || BlockUtil.canSee(pos);
228
    }
229
230
    private boolean isTarget(BlockPos pos, BlockState state) {
231
        if (state.isAir() || !BlockUtil.isBreakable(pos)) {
232
            return false;
233
        }
234
        if (state.getShape(mc.level, pos).isEmpty()) {
235
            return false;
236
        }
237
        return switch (targets.getValue()) {
238
            case ORES -> BlockUtil.isOre(state);
239
            case ORES_AND_LOGS -> BlockUtil.isOre(state) || state.is(BlockTags.LOGS);
240
            case ANY_BLOCK -> true;
241
            case LIST -> blocks.contains(state.getBlock()) == listMode.is(ListMode.WHITELIST);
242
        };
243
    }
244
245
    @Subscribe
246
    private void onRender3D(Render3DEvent event) {
247
        if (!render.isOn()) {
248
            return;
249
        }
250
        veinBox.drawAll(event.getBatch(), vein, false);
251
    }
252
}
253