excavator module

excavator: Minecraft 26.3 cheat module, full source for every implementation (2 clients: Meteor Client, OfflineClient).

2 implementationsWorldWORLD

Clients with this module

Full module source: 2 implementations

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/Excavator.javaJava · 144 lines · 5.3 KB

Excavate a selection area.

Settingsselection-bindlog-selectionkeep-activeshape-modeside-colorline-color
Excavator.javaJava · Minecraft 26.2 · 144 lines · 5.3 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.utils.BetterBlockPos;
11
import meteordevelopment.meteorclient.events.meteor.KeyInputEvent;
12
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
13
import meteordevelopment.meteorclient.events.render.Render3DEvent;
14
import meteordevelopment.meteorclient.renderer.ShapeMode;
15
import meteordevelopment.meteorclient.settings.*;
16
import meteordevelopment.meteorclient.systems.modules.Categories;
17
import meteordevelopment.meteorclient.systems.modules.Module;
18
import meteordevelopment.meteorclient.utils.misc.Keybind;
19
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
20
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
21
import meteordevelopment.orbit.EventHandler;
22
import net.minecraft.world.phys.BlockHitResult;
23
import com.mojang.blaze3d.platform.InputConstants;
24
25
public class Excavator extends Module {
26
    private final IBaritone baritone = BaritoneAPI.getProvider().getPrimaryBaritone();
27
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
28
    private final SettingGroup sgRendering = settings.createGroup("Rendering");
29
30
    // Keybindings
31
    private final Setting<Keybind> selectionBind = sgGeneral.add(new KeybindSetting.Builder()
32
        .name("selection-bind")
33
        .description("Bind to draw selection.")
34
        .defaultValue(Keybind.fromButton(InputConstants.MOUSE_BUTTON_RIGHT))
35
        .build()
36
    );
37
38
    // Logging
39
    private final Setting<Boolean> logSelection = sgGeneral.add(new BoolSetting.Builder()
40
        .name("log-selection")
41
        .description("Logs the selection coordinates to the chat.")
42
        .defaultValue(true)
43
        .build()
44
    );
45
46
    private final Setting<Boolean> keepActive = sgGeneral.add(new BoolSetting.Builder()
47
        .name("keep-active")
48
        .description("Keep the module active after finishing the excavation.")
49
        .defaultValue(false)
50
        .build()
51
    );
52
53
    // Rendering
54
    private final Setting<ShapeMode> shapeMode = sgRendering.add(new EnumSetting.Builder<ShapeMode>()
55
        .name("shape-mode")
56
        .description("How the shapes are rendered.")
57
        .defaultValue(ShapeMode.Both)
58
        .build()
59
    );
60
61
    private final Setting<SettingColor> sideColor = sgRendering.add(new ColorSetting.Builder()
62
        .name("side-color")
63
        .description("The side color.")
64
        .defaultValue(new SettingColor(255, 255, 255, 50))
65
        .build()
66
    );
67
68
    private final Setting<SettingColor> lineColor = sgRendering.add(new ColorSetting.Builder()
69
        .name("line-color")
70
        .description("The line color.")
71
        .defaultValue(new SettingColor(255, 255, 255, 255))
72
        .build()
73
    );
74
75
    private enum Status {
76
        SEL_START,
77
        SEL_END,
78
        WORKING
79
    }
80
81
    private Status status = Status.SEL_START;
82
    private BetterBlockPos start, end;
83
84
    public Excavator() {
85
        super(Categories.World, "excavator", "Excavate a selection area.");
86
    }
87
88
    @Override
89
    public void onDeactivate() {
90
        baritone.getSelectionManager().removeSelection(baritone.getSelectionManager().getLastSelection());
91
        if (baritone.getBuilderProcess().isActive()) baritone.getPathingBehavior().cancelEverything();
92
        status = Status.SEL_START;
93
    }
94
95
    @EventHandler
96
    private void onMouseClick(MouseClickEvent event) {
97
        if (event.action != KeyAction.Press || !selectionBind.get().isPressed() || mc.gui.screen() != null) {
98
            return;
99
        }
100
        selectCorners();
101
    }
102
103
    @EventHandler
104
    private void onKey(KeyInputEvent event) {
105
        if (event.action != KeyAction.Press || !selectionBind.get().isPressed() || mc.gui.screen() != null) {
106
            return;
107
        }
108
        selectCorners();
109
    }
110
111
    private void selectCorners() {
112
        if (!(mc.hitResult instanceof BlockHitResult result)) return;
113
114
        if (status == Status.SEL_START) {
115
            start = BetterBlockPos.from(result.getBlockPos());
116
            status = Status.SEL_END;
117
            if (logSelection.get()) {
118
                info("Start corner set: (%d, %d, %d)".formatted(start.x, start.y, start.z));
119
            }
120
        } else if (status == Status.SEL_END) {
121
            end = BetterBlockPos.from(result.getBlockPos());
122
            status = Status.WORKING;
123
            if (logSelection.get()) {
124
                info("End corner set: (%d, %d, %d)".formatted(end.x, end.y, end.z));
125
            }
126
            baritone.getSelectionManager().addSelection(start, end);
127
            baritone.getBuilderProcess().clearArea(start, end);
128
        }
129
    }
130
131
    @EventHandler
132
    private void onRender3D(Render3DEvent event) {
133
        if (status == Status.SEL_START || status == Status.SEL_END) {
134
            if (!(mc.hitResult instanceof BlockHitResult result)) return;
135
            event.renderer.box(result.getBlockPos(), sideColor.get(), lineColor.get(), shapeMode.get(), 0);
136
        } else if (status == Status.WORKING && !baritone.getBuilderProcess().isActive()) {
137
            if (keepActive.get()) {
138
                baritone.getSelectionManager().removeSelection(baritone.getSelectionManager().getLastSelection());
139
                status = Status.SEL_START;
140
            } else toggle();
141
        }
142
    }
143
}
144
OfflineClientWORLDsrc/main/java/com/jellypudding/offlineclient/modules/world/Excavator.javaJava · 335 lines · 11.7 KB

Digs out a box. Press the bind at each corner whilst it is on.

SettingsRangeMax blocksSpeedBlocks per tickRotateWalk to blocksKeep activeLog selection
Excavator.javaJava · Minecraft 26.2 · 335 lines · 11.7 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.PathFinder;
10
import com.jellypudding.offlineclient.path.PathGoal;
11
import com.jellypudding.offlineclient.path.PathWalker;
12
import com.jellypudding.offlineclient.util.InputUtil;
13
import com.jellypudding.offlineclient.render.BoxStyle;
14
import com.jellypudding.offlineclient.setting.BoolSetting;
15
import com.jellypudding.offlineclient.setting.EnumSetting;
16
import com.jellypudding.offlineclient.setting.NumberSetting;
17
import com.jellypudding.offlineclient.util.BlockMiner;
18
import com.jellypudding.offlineclient.util.BlockUtil;
19
import com.jellypudding.offlineclient.util.ChatUtil;
20
import net.minecraft.client.multiplayer.ClientLevel;
21
import net.minecraft.core.BlockPos;
22
import net.minecraft.world.InteractionHand;
23
import net.minecraft.world.phys.AABB;
24
import net.minecraft.world.phys.BlockHitResult;
25
import net.minecraft.world.phys.HitResult;
26
import net.minecraft.world.phys.Vec3;
27
28
import java.util.ArrayList;
29
import java.util.Comparator;
30
import java.util.HashMap;
31
import java.util.Iterator;
32
import java.util.List;
33
import java.util.Map;
34
import java.util.function.Predicate;
35
36
// Digs out a box marked with two corners. Blocks come out from the top down.
37
public final class Excavator extends Module {
38
39
    private static final int CORNER_COLOR = 0xFFFFD040;
40
41
    private final NumberSetting range = new NumberSetting("Range",
42
        "How far from your eyes a block may be.",
43
        4.5, 1, 6, 0.1).min(1).max(6);
44
    private final NumberSetting maxBlocks = new NumberSetting("Max blocks",
45
        "The most blocks one box may hold.", 4096, 64, 16384, 64)
46
        .min(1).max(65536);
47
    private final EnumSetting<Speed> speed = new EnumSetting<>("Speed",
48
        "How the blocks come down.", Speed.LEGIT)
49
        .describe(Speed.LEGIT, "One block at a time like a held click.")
50
        .describe(Speed.INSTANT, "Fires the break packets for several one hit blocks at once.");
51
    private final NumberSetting perTick = new NumberSetting("Blocks per tick",
52
        "How many one hit blocks to break each tick in Instant mode.", 4, 1, 16, 1)
53
        .min(1).under(speed, Speed.INSTANT);
54
    private final BoolSetting rotate = new BoolSetting("Rotate",
55
        "Turn towards each block on the server side.", true);
56
    private final BoolSetting walkTo = new BoolSetting("Walk to blocks",
57
        "Walks to the next block whilst it is out of reach.", false);
58
    private final BoolSetting keepActive = new BoolSetting("Keep active",
59
        "Stays on after the box is done so you can mark another one.", false);
60
    private final BoolSetting logSelection = new BoolSetting("Log selection",
61
        "Prints each corner you mark to chat.", true);
62
    private final BoxStyle boxStyle = BoxStyle.white(BoxStyle.Shape.BOTH);
63
    private final BoxStyle targetStyle = new BoxStyle("Target", BoxStyle.Shape.BOTH, 0);
64
65
    public enum Speed { LEGIT, INSTANT }
66
67
    // Ticks before a one hit block that did not vanish is sent again.
68
    private static final int RETRY_TICKS = 10;
69
70
    private final PathFinder finder = new PathFinder();
71
    private final PathWalker walker = new PathWalker();
72
73
    private BlockPos first;
74
    private BlockPos second;
75
    private final List<BlockPos> remaining = new ArrayList<>();
76
    private BlockPos current;
77
    private ClientLevel lastLevel;
78
79
    // One hit blocks already sent and the tick they may be sent again.
80
    private final Map<BlockPos, Integer> attempted = new HashMap<>();
81
    private int lastTick;
82
83
    public Excavator() {
84
        super("Excavator", "Digs out a box. Press the bind at each corner whilst it is on.", Category.WORLD);
85
        addSettings(range, maxBlocks, speed, perTick, rotate, walkTo, keepActive, logSelection);
86
        addSettings(boxStyle.settings());
87
        addSettings(targetStyle.settings());
88
        searchTags("dig", "cuboid", "selection", "quarry");
89
    }
90
91
    @Override
92
    public String getSuffix() {
93
        if (first == null) {
94
            return "pick a corner";
95
        }
96
        if (second == null) {
97
            return "pick the other corner";
98
        }
99
        return remaining.size() + " left";
100
    }
101
102
    @Override
103
    public ExclusivityGroup getExclusivityGroup() {
104
        return ExclusivityGroup.MINING;
105
    }
106
107
    @Override
108
    protected void onEnable() {
109
        clear();
110
        lastLevel = mc.level;
111
    }
112
113
    @Override
114
    protected void onDisable() {
115
        BlockMiner.release();
116
        clear();
117
        lastLevel = null;
118
    }
119
120
    // Bringing this back at launch would start digging at once.
121
    @Override
122
    public boolean savesEnabledState() {
123
        return false;
124
    }
125
126
    private void clear() {
127
        stopWalking();
128
        first = null;
129
        second = null;
130
        remaining.clear();
131
        attempted.clear();
132
        current = null;
133
    }
134
135
    // The bind marks the block under the crosshair whilst the module is on.
136
    // Pressing it with nothing in view turns the module off again.
137
    @Override
138
    public void onKeybind() {
139
        if (!isEnabled() || !inGame()) {
140
            toggle();
141
            return;
142
        }
143
        if (mc.hitResult instanceof BlockHitResult hit && hit.getType() == HitResult.Type.BLOCK) {
144
            mark(hit.getBlockPos().immutable());
145
            return;
146
        }
147
        toggle();
148
    }
149
150
    private void mark(BlockPos pos) {
151
        if (first == null || second != null) {
152
            clear();
153
            first = pos;
154
            ChatUtil.message("§bExcavator §7first corner at §f" + BlockUtil.text(pos) + "§7.");
155
            return;
156
        }
157
        second = pos;
158
        if (!build()) {
159
            second = null;
160
            return;
161
        }
162
        if (logSelection.isOn()) {
163
            ChatUtil.message("§bExcavator §7second corner at §f" + BlockUtil.text(pos)
164
                + "§7. §f" + remaining.size() + "§7 blocks to dig.");
165
        }
166
    }
167
168
    // The top layers come first. Sand and gravel never drop onto a cleared spot.
169
    private boolean build() {
170
        remaining.clear();
171
        current = null;
172
        long volume = (long) (Math.abs(first.getX() - second.getX()) + 1)
173
            * (Math.abs(first.getY() - second.getY()) + 1)
174
            * (Math.abs(first.getZ() - second.getZ()) + 1);
175
        if (volume > maxBlocks.getInt()) {
176
            ChatUtil.error("That box holds " + volume + " blocks and the limit is "
177
                + maxBlocks.getInt() + ". Pick a smaller one.");
178
            return false;
179
        }
180
        Vec3 eye = mc.player.getEyePosition();
181
        for (BlockPos pos : BlockPos.betweenClosed(first, second)) {
182
            remaining.add(pos.immutable());
183
        }
184
        Comparator<BlockPos> topDownThenNear = Comparator.<BlockPos>comparingInt(BlockPos::getY).reversed()
185
            .thenComparingDouble(pos -> eye.distanceToSqr(Vec3.atCenterOf(pos)));
186
        remaining.sort(topDownThenNear);
187
        return true;
188
    }
189
190
    @Subscribe
191
    private void onTick(TickEvent event) {
192
        current = null;
193
        if (!inGame() || mc.player.isSpectator()) {
194
            return;
195
        }
196
        if (mc.level != lastLevel) {
197
            // Corners taken in another world point at nothing here.
198
            lastLevel = mc.level;
199
            clear();
200
            return;
201
        }
202
        if (second == null) {
203
            return;
204
        }
205
        // Holding attack means the player is mining by hand.
206
        if (InputUtil.physicallyHeld(mc.options.keyAttack) || mc.player.isUsingItem()) {
207
            stopWalking();
208
            return;
209
        }
210
        if (remaining.isEmpty()) {
211
            ChatUtil.message("§bExcavator §7finished that box.");
212
            clear();
213
            if (!keepActive.isOn()) {
214
                setEnabled(false);
215
            }
216
            return;
217
        }
218
        if (speed.is(Speed.INSTANT) && breakInstantly()) {
219
            return;
220
        }
221
        current = next(pos -> true);
222
        if (current != null && !BlockMiner.mine(current, rotate.isOn())) {
223
            remaining.remove(current);
224
            current = null;
225
        }
226
        if (current == null && walkTo.isOn() && !remaining.isEmpty()) {
227
            walkOn();
228
        } else {
229
            stopWalking();
230
        }
231
    }
232
233
    // Heads for the closest block left whilst none of them is in reach.
234
    private void walkOn() {
235
        PathFinder.Result result = finder.poll();
236
        if (result != null) {
237
            walker.follow(result.nodes());
238
        }
239
        if (finder.busy()) {
240
            return;
241
        }
242
        if (walker.arrived() || walker.lost()) {
243
            BlockPos target = closestLeft();
244
            if (target != null) {
245
                finder.search(PathFinder.standingAt(mc.player),
246
                    new PathGoal.Around(target, Math.max(1, range.getValue() - 1)));
247
            }
248
            return;
249
        }
250
        walker.tick(finder.liveRules());
251
    }
252
253
    private BlockPos closestLeft() {
254
        Vec3 eye = mc.player.getEyePosition();
255
        BlockPos best = null;
256
        double bestDistance = Double.MAX_VALUE;
257
        for (BlockPos pos : remaining) {
258
            double distance = eye.distanceToSqr(Vec3.atCenterOf(pos));
259
            if (distance < bestDistance) {
260
                bestDistance = distance;
261
                best = pos;
262
            }
263
        }
264
        return best;
265
    }
266
267
    private void stopWalking() {
268
        finder.cancel();
269
        walker.stop();
270
    }
271
272
    // Sends the break packets for the one hit blocks in reach. True when any
273
    // went out. Slower blocks fall through to the held click path.
274
    private boolean breakInstantly() {
275
        int now = mc.player.tickCount;
276
        if (now < lastTick) {
277
            attempted.clear();
278
        }
279
        lastTick = now;
280
        attempted.values().removeIf(expiry -> expiry <= now);
281
        int sent = 0;
282
        while (sent < perTick.getInt()) {
283
            BlockPos pos = next(candidate -> BlockUtil.canInstantBreak(candidate)
284
                && !attempted.containsKey(candidate));
285
            if (pos == null) {
286
                break;
287
            }
288
            BlockMiner.breakInstantly(pos);
289
            attempted.put(pos, now + RETRY_TICKS);
290
            current = pos;
291
            sent++;
292
        }
293
        if (sent > 0) {
294
            mc.player.swing(InteractionHand.MAIN_HAND);
295
        }
296
        return sent > 0;
297
    }
298
299
    // Blocks that are already gone drop out of the queue on the way past.
300
    private BlockPos next(Predicate<BlockPos> wanted) {
301
        Iterator<BlockPos> it = remaining.iterator();
302
        while (it.hasNext()) {
303
            BlockPos pos = it.next();
304
            if (!BlockUtil.diggable(pos)) {
305
                it.remove();
306
                continue;
307
            }
308
            // The block underfoot waits until the player has moved off it.
309
            if (!BlockUtil.isStandingOn(pos) && BlockUtil.distanceTo(pos) <= range.getValue()
310
                && wanted.test(pos)) {
311
                return pos;
312
            }
313
        }
314
        return null;
315
    }
316
317
    @Subscribe
318
    private void onRender3D(Render3DEvent event) {
319
        if (first == null) {
320
            return;
321
        }
322
        if (second == null) {
323
            boxStyle.draw(event.getBatch(), new AABB(first).inflate(0.005), true);
324
            return;
325
        }
326
        AABB box = new AABB(first).minmax(new AABB(second));
327
        boxStyle.draw(event.getBatch(), box.inflate(0.005), true);
328
        event.getBatch().outlineBox(new AABB(first).deflate(0.3), CORNER_COLOR, true);
329
        event.getBatch().outlineBox(new AABB(second).deflate(0.3), CORNER_COLOR, true);
330
        if (current != null) {
331
            targetStyle.draw(event.getBatch(), current, false);
332
        }
333
    }
334
}
335