nuker module

nuker: Minecraft 26.3 cheat module, full source for every implementation (4 clients: Meteor Client, MelaHack (ThunderHack fork), OfflineClient, …).

4 implementationsWorldMISCWORLD

Full module source: 4 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/Nuker.javaJava · 585 lines · 21.8 KB

Breaks blocks around you.

Settingsshapemoderangeupdownleftrightforwardbackwalls-rangedelaymax-blocks-per-ticksort-modepacket-mineonly-suitable-toolsinteractrotatelist-modeblacklistwhitelistselect-block-bindswingbounding-boxnuke-box-modeside-colorline-colorbroken-blocksnuke-block-mode
Nuker.javaJava · Minecraft 26.2 · 585 lines · 21.8 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 it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
9
import meteordevelopment.meteorclient.events.entity.player.BlockBreakingCooldownEvent;
10
import meteordevelopment.meteorclient.events.meteor.KeyInputEvent;
11
import meteordevelopment.meteorclient.events.meteor.MouseClickEvent;
12
import meteordevelopment.meteorclient.events.render.Render3DEvent;
13
import meteordevelopment.meteorclient.events.world.TickEvent;
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.Utils;
19
import meteordevelopment.meteorclient.utils.misc.Keybind;
20
import meteordevelopment.meteorclient.utils.misc.ListMode;
21
import meteordevelopment.meteorclient.utils.misc.Names;
22
import meteordevelopment.meteorclient.utils.misc.input.KeyAction;
23
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
24
import meteordevelopment.meteorclient.utils.player.Rotations;
25
import meteordevelopment.meteorclient.utils.render.RenderUtils;
26
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
27
import meteordevelopment.meteorclient.utils.world.BlockIterator;
28
import meteordevelopment.meteorclient.utils.world.BlockUtils;
29
import meteordevelopment.orbit.EventHandler;
30
import meteordevelopment.orbit.EventPriority;
31
import net.minecraft.core.BlockPos;
32
import net.minecraft.core.Direction;
33
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
34
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
35
import net.minecraft.world.InteractionHand;
36
import net.minecraft.world.level.ClipContext;
37
import net.minecraft.world.level.block.Block;
38
import net.minecraft.world.phys.AABB;
39
import net.minecraft.world.phys.BlockHitResult;
40
import net.minecraft.world.phys.HitResult;
41
import net.minecraft.world.phys.Vec3;
42
43
import java.util.ArrayList;
44
import java.util.Comparator;
45
import java.util.List;
46
import java.util.Set;
47
48
public class Nuker extends Module {
49
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
50
    private final SettingGroup sgWhitelist = settings.createGroup("Whitelist");
51
    private final SettingGroup sgRender = settings.createGroup("Render");
52
53
    // General
54
55
    private final Setting<Shape> shape = sgGeneral.add(new EnumSetting.Builder<Shape>()
56
        .name("shape")
57
        .description("The shape of nuking algorithm.")
58
        .defaultValue(Shape.Sphere)
59
        .build()
60
    );
61
62
    private final Setting<Mode> mode = sgGeneral.add(new EnumSetting.Builder<Mode>()
63
        .name("mode")
64
        .description("The way the blocks are broken.")
65
        .defaultValue(Mode.Flatten)
66
        .build()
67
    );
68
69
    private final Setting<Double> range = sgGeneral.add(new DoubleSetting.Builder()
70
        .name("range")
71
        .description("The break range.")
72
        .defaultValue(4)
73
        .min(0)
74
        .visible(() -> shape.get() != Shape.Cube)
75
        .build()
76
    );
77
78
    private final Setting<Integer> range_up = sgGeneral.add(new IntSetting.Builder()
79
        .name("up")
80
        .description("The break range.")
81
        .defaultValue(1)
82
        .min(0)
83
        .visible(() -> shape.get() == Shape.Cube)
84
        .build()
85
    );
86
87
    private final Setting<Integer> range_down = sgGeneral.add(new IntSetting.Builder()
88
        .name("down")
89
        .description("The break range.")
90
        .defaultValue(1)
91
        .min(0)
92
        .visible(() -> shape.get() == Shape.Cube)
93
        .build()
94
    );
95
96
    private final Setting<Integer> range_left = sgGeneral.add(new IntSetting.Builder()
97
        .name("left")
98
        .description("The break range.")
99
        .defaultValue(1)
100
        .min(0)
101
        .visible(() -> shape.get() == Shape.Cube)
102
        .build()
103
    );
104
105
    private final Setting<Integer> range_right = sgGeneral.add(new IntSetting.Builder()
106
        .name("right")
107
        .description("The break range.")
108
        .defaultValue(1)
109
        .min(0)
110
        .visible(() -> shape.get() == Shape.Cube)
111
        .build()
112
    );
113
114
    private final Setting<Integer> range_forward = sgGeneral.add(new IntSetting.Builder()
115
        .name("forward")
116
        .description("The break range.")
117
        .defaultValue(1)
118
        .min(0)
119
        .visible(() -> shape.get() == Shape.Cube)
120
        .build()
121
    );
122
123
    private final Setting<Integer> range_back = sgGeneral.add(new IntSetting.Builder()
124
        .name("back")
125
        .description("The break range.")
126
        .defaultValue(1)
127
        .min(0)
128
        .visible(() -> shape.get() == Shape.Cube)
129
        .build()
130
    );
131
132
    private final Setting<Double> wallsRange = sgGeneral.add(new DoubleSetting.Builder()
133
        .name("walls-range")
134
        .description("Range in which to break when behind blocks.")
135
        .defaultValue(4.0)
136
        .min(0)
137
        .sliderMax(6)
138
        .build()
139
    );
140
141
    private final Setting<Integer> delay = sgGeneral.add(new IntSetting.Builder()
142
        .name("delay")
143
        .description("Delay in ticks between breaking blocks.")
144
        .defaultValue(0)
145
        .build()
146
    );
147
148
    private final Setting<Integer> maxBlocksPerTick = sgGeneral.add(new IntSetting.Builder()
149
        .name("max-blocks-per-tick")
150
        .description("Maximum blocks to try to break per tick. Useful when insta mining.")
151
        .defaultValue(1)
152
        .min(1)
153
        .build()
154
    );
155
156
    private final Setting<SortMode> sortMode = sgGeneral.add(new EnumSetting.Builder<SortMode>()
157
        .name("sort-mode")
158
        .description("The blocks you want to mine first.")
159
        .defaultValue(SortMode.Closest)
160
        .build()
161
    );
162
163
    private final Setting<Boolean> packetMine = sgGeneral.add(new BoolSetting.Builder()
164
        .name("packet-mine")
165
        .description("Attempt to instamine everything at once.")
166
        .defaultValue(false)
167
        .build()
168
    );
169
170
    private final Setting<Boolean> suitableTools = sgGeneral.add(new BoolSetting.Builder()
171
        .name("only-suitable-tools")
172
        .description("Only mines when using an appropriate for the block.")
173
        .defaultValue(false)
174
        .build()
175
    );
176
177
    private final Setting<Boolean> interact = sgGeneral.add(new BoolSetting.Builder()
178
        .name("interact")
179
        .description("Interacts with the block instead of mining.")
180
        .defaultValue(false)
181
        .build()
182
    );
183
184
    private final Setting<Boolean> rotate = sgGeneral.add(new BoolSetting.Builder()
185
        .name("rotate")
186
        .description("Rotates server-side to the block being mined.")
187
        .defaultValue(true)
188
        .build()
189
    );
190
191
    // Whitelist and blacklist
192
193
    private final Setting<ListMode> listMode = sgWhitelist.add(new EnumSetting.Builder<ListMode>()
194
        .name("list-mode")
195
        .description("Selection mode.")
196
        .defaultValue(ListMode.Blacklist)
197
        .build()
198
    );
199
200
    private final Setting<List<Block>> blacklist = sgWhitelist.add(new BlockListSetting.Builder()
201
        .name("blacklist")
202
        .description("The blocks you don't want to mine.")
203
        .visible(() -> listMode.get() == ListMode.Blacklist)
204
        .build()
205
    );
206
207
    private final Setting<List<Block>> whitelist = sgWhitelist.add(new BlockListSetting.Builder()
208
        .name("whitelist")
209
        .description("The blocks you want to mine.")
210
        .visible(() -> listMode.get() == ListMode.Whitelist)
211
        .build()
212
    );
213
214
    private final Setting<Keybind> selectBlockBind = sgWhitelist.add(new KeybindSetting.Builder()
215
        .name("select-block-bind")
216
        .description("Adds targeted block to list when this button is pressed.")
217
        .defaultValue(Keybind.none())
218
        .build()
219
    );
220
221
    // Rendering
222
223
    private final Setting<Boolean> swing = sgRender.add(new BoolSetting.Builder()
224
        .name("swing")
225
        .description("Whether to swing hand client-side.")
226
        .defaultValue(true)
227
        .build()
228
    );
229
230
    private final Setting<Boolean> enableRenderBounding = sgRender.add(new BoolSetting.Builder()
231
        .name("bounding-box")
232
        .description("Enable rendering bounding box for Cube and Uniform Cube.")
233
        .defaultValue(true)
234
        .build()
235
    );
236
237
    private final Setting<ShapeMode> shapeModeBox = sgRender.add(new EnumSetting.Builder<ShapeMode>()
238
        .name("nuke-box-mode")
239
        .description("How the shape for the bounding box is rendered.")
240
        .defaultValue(ShapeMode.Both)
241
        .build()
242
    );
243
244
    private final Setting<SettingColor> sideColorBox = sgRender.add(new ColorSetting.Builder()
245
        .name("side-color")
246
        .description("The side color of the bounding box.")
247
        .defaultValue(new SettingColor(16, 106, 144, 100))
248
        .build()
249
    );
250
251
    private final Setting<SettingColor> lineColorBox = sgRender.add(new ColorSetting.Builder()
252
        .name("line-color")
253
        .description("The line color of the bounding box.")
254
        .defaultValue(new SettingColor(16, 106, 144, 255))
255
        .build()
256
    );
257
258
    private final Setting<Boolean> enableRenderBreaking = sgRender.add(new BoolSetting.Builder()
259
        .name("broken-blocks")
260
        .description("Enable rendering bounding box for Cube and Uniform Cube.")
261
        .defaultValue(true)
262
        .build()
263
    );
264
265
    private final Setting<ShapeMode> shapeModeBreak = sgRender.add(new EnumSetting.Builder<ShapeMode>()
266
        .name("nuke-block-mode")
267
        .description("How the shapes for broken blocks are rendered.")
268
        .defaultValue(ShapeMode.Both)
269
        .visible(enableRenderBreaking::get)
270
        .build()
271
    );
272
273
    private final Setting<SettingColor> sideColor = sgRender.add(new ColorSetting.Builder()
274
        .name("side-color")
275
        .description("The side color of the target block rendering.")
276
        .defaultValue(new SettingColor(255, 0, 0, 80))
277
        .visible(enableRenderBreaking::get)
278
        .build()
279
    );
280
281
    private final Setting<SettingColor> lineColor = sgRender.add(new ColorSetting.Builder()
282
        .name("line-color")
283
        .description("The line color of the target block rendering.")
284
        .defaultValue(new SettingColor(255, 0, 0, 255))
285
        .visible(enableRenderBreaking::get)
286
        .build()
287
    );
288
289
    private final List<BlockPos> blocks = new ArrayList<>();
290
    private final Set<BlockPos> interacted = new ObjectOpenHashSet<>();
291
292
    private boolean firstBlock;
293
    private final BlockPos.MutableBlockPos lastBlockPos = new BlockPos.MutableBlockPos();
294
295
    private int timer;
296
    private int noBlockTimer;
297
298
    private final BlockPos.MutableBlockPos pos1 = new BlockPos.MutableBlockPos(); // Rendering for cubes
299
    private final BlockPos.MutableBlockPos pos2 = new BlockPos.MutableBlockPos();
300
    int maxh = 0;
301
    int maxv = 0;
302
303
    public Nuker() {
304
        super(Categories.World, "nuker", "Breaks blocks around you.");
305
    }
306
307
    @Override
308
    public void onActivate() {
309
        firstBlock = true;
310
        timer = 0;
311
        noBlockTimer = 0;
312
        interacted.clear();
313
    }
314
315
    @EventHandler
316
    private void onRender(Render3DEvent event) {
317
        if (enableRenderBounding.get()) {
318
            // Render bounding box if cube and should break stuff
319
            if (shape.get() != Shape.Sphere && mode.get() != Mode.Smash) {
320
                int minX = Math.min(pos1.getX(), pos2.getX());
321
                int minY = Math.min(pos1.getY(), pos2.getY());
322
                int minZ = Math.min(pos1.getZ(), pos2.getZ());
323
                int maxX = Math.max(pos1.getX(), pos2.getX());
324
                int maxY = Math.max(pos1.getY(), pos2.getY());
325
                int maxZ = Math.max(pos1.getZ(), pos2.getZ());
326
                event.renderer.box(minX, minY, minZ, maxX, maxY, maxZ, sideColorBox.get(), lineColorBox.get(), shapeModeBox.get(), 0);
327
            }
328
        }
329
    }
330
331
    @EventHandler
332
    private void onMouseClick(MouseClickEvent event) {
333
        if (event.action == KeyAction.Press) addTargetedBlockToList();
334
    }
335
336
    @EventHandler
337
    private void onKey(KeyInputEvent event) {
338
        if (event.action == KeyAction.Press) addTargetedBlockToList();
339
    }
340
341
    @EventHandler
342
    private void onTickPre(TickEvent.Pre event) {
343
        // Update timer
344
        if (timer > 0) {
345
            timer--;
346
            return;
347
        }
348
349
        // Calculate some stuff
350
        double pX = mc.player.getX(), pY = mc.player.getY(), pZ = mc.player.getZ();
351
        double rangeSq = Math.pow(range.get(), 2);
352
        BlockPos playerBlockPos = mc.player.blockPosition();
353
354
        if (shape.get() == Shape.UniformCube) range.set((double) Math.round(range.get()));
355
356
        double pX_ = pX;
357
        double pZ_ = pZ;
358
        int r = (int) Math.round(range.get());
359
360
        if (shape.get() == Shape.UniformCube) {
361
            pX_ += 1; // weird position stuff
362
            pos1.set(pX_ - r, pY - r + 1, pZ - r + 1); // down
363
            pos2.set(pX_ + r - 1, pY + r, pZ + r); // up
364
            maxh = 0;
365
            maxv = 0;
366
        } else {
367
            // Only change me if you want to mess with 3D rotations:
368
            // I messed with it
369
            Direction direction = mc.player.getDirection();
370
            switch (direction) {
371
                case Direction.SOUTH -> {
372
                    pZ_ += 1;
373
                    pX_ += 1;
374
                    pos1.set(pX_ - (range_right.get() + 1), Math.ceil(pY) - range_down.get(), pZ_ - (range_back.get() + 1)); // down
375
                    pos2.set(pX_ + range_left.get(), Math.ceil(pY + range_up.get() + 1), pZ_ + range_forward.get()); // up
376
                }
377
                case Direction.WEST -> {
378
                    pos1.set(pX_ - range_forward.get(), Math.ceil(pY) - range_down.get(), pZ_ - range_right.get()); // down
379
                    pos2.set(pX_ + range_back.get() + 1, Math.ceil(pY + range_up.get() + 1), pZ_ + range_left.get() + 1); // up
380
                }
381
                case Direction.NORTH -> {
382
                    pX_ += 1;
383
                    pZ_ += 1;
384
                    pos1.set(pX_ - (range_left.get() + 1), Math.ceil(pY) - range_down.get(), pZ_ - (range_forward.get() + 1)); // down
385
                    pos2.set(pX_ + range_right.get(), Math.ceil(pY + range_up.get() + 1), pZ_ + range_back.get()); // up
386
                }
387
                case Direction.EAST -> {
388
                    pX_ += 1;
389
                    pos1.set(pX_ - (range_back.get() + 1), Math.ceil(pY) - range_down.get(), pZ_ - range_left.get()); // down
390
                    pos2.set(pX_ + range_forward.get(), Math.ceil(pY + range_up.get() + 1), pZ_ + range_right.get() + 1); // up
391
                }
392
            }
393
394
            // get largest horizontal
395
            maxh = 1 + Math.max(Math.max(Math.max(range_back.get(), range_right.get()), range_forward.get()), range_left.get());
396
            maxv = 1 + Math.max(range_up.get(), range_down.get());
397
        }
398
399
        // Flatten
400
        if (mode.get() == Mode.Flatten) pos1.setY((int) Math.floor(pY + 0.5));
401
402
        AABB box = new AABB(Vec3.atCenterOf(pos1), Vec3.atCenterOf(pos2));
403
404
        // Find blocks to break
405
        BlockIterator.register(Math.max((int) Math.ceil(range.get() + 1), maxh), Math.max((int) Math.ceil(range.get()), maxv), (blockPos, blockState) -> {
406
            Vec3 center = Vec3.atCenterOf(blockPos);
407
            switch (shape.get()) {
408
                case Sphere -> {
409
                    if (center.distanceToSqr(pX, pY, pZ) > rangeSq)
410
                        return;
411
                }
412
                case UniformCube -> {
413
                    if (chebyshevDist(playerBlockPos.getX(), playerBlockPos.getY(), playerBlockPos.getZ(), blockPos.getX(), blockPos.getY(), blockPos.getZ()) >= range.get())
414
                        return;
415
                }
416
                case Cube -> {
417
                    if (!box.contains(center)) return;
418
                }
419
            }
420
421
            // Flatten
422
            if (mode.get() == Mode.Flatten && blockPos.getY() + 0.5 < pY) return;
423
424
            // Smash
425
            if (mode.get() == Mode.Smash && blockState.getDestroySpeed(mc.level, blockPos) != 0) return;
426
427
            // Use only optimal tools
428
            if (suitableTools.get() && !interact.get() && !mc.player.getMainHandItem().isCorrectToolForDrops(blockState))
429
                return;
430
431
            // Block must be breakable
432
            if (!BlockUtils.canBreak(blockPos, blockState) && !interact.get()) return;
433
434
            // Raycast to block
435
            if (isOutOfRange(blockPos)) return;
436
437
            // Check whitelist or blacklist
438
            boolean blockInList = (listMode.get() == ListMode.Whitelist ? whitelist.get() : blacklist.get()).contains(blockState.getBlock());
439
            if (!listMode.get().allows(blockInList)) return;
440
441
            if (interact.get() && interacted.contains(blockPos)) return;
442
443
            // Add block
444
            blocks.add(blockPos.immutable());
445
        });
446
447
        // Break block if found
448
        BlockIterator.after(() -> {
449
            // Sort blocks
450
            if (sortMode.get() == SortMode.TopDown)
451
                blocks.sort(Comparator.comparingDouble(value -> -value.getY()));
452
            else if (sortMode.get() != SortMode.None)
453
                blocks.sort(Comparator.comparingDouble(value -> Utils.squaredDistance(pX, pY, pZ, value.getX() + 0.5, value.getY() + 0.5, value.getZ() + 0.5) * (sortMode.get() == SortMode.Closest ? 1 : -1)));
454
455
            // Check if some block was found
456
            if (blocks.isEmpty()) {
457
                interacted.clear();
458
                // If no block was found for long enough then set firstBlock flag to true to not wait before breaking another again
459
                if (noBlockTimer++ >= delay.get()) firstBlock = true;
460
                return;
461
            } else {
462
                noBlockTimer = 0;
463
            }
464
465
            // Update timer
466
            if (!firstBlock && !lastBlockPos.equals(blocks.getFirst())) {
467
                timer = delay.get();
468
469
                firstBlock = false;
470
                lastBlockPos.set(blocks.getFirst());
471
472
                if (timer > 0) return;
473
            }
474
475
            // Break
476
            int count = 0;
477
478
            for (BlockPos block : blocks) {
479
                if (count >= maxBlocksPerTick.get()) break;
480
481
                boolean canInstaMine = BlockUtils.canInstaBreak(block);
482
483
                if (rotate.get())
484
                    Rotations.rotate(Rotations.getYaw(block), Rotations.getPitch(block), () -> breakBlock(block));
485
                else breakBlock(block);
486
487
                if (enableRenderBreaking.get())
488
                    RenderUtils.renderTickingBlock(block, sideColor.get(), lineColor.get(), shapeModeBreak.get(), 0, 8, true, false);
489
                lastBlockPos.set(block);
490
491
                count++;
492
                if (!canInstaMine && !packetMine.get() /* With packet mine attempt to break everything possible at once */)
493
                    break;
494
            }
495
496
            firstBlock = false;
497
498
            // Clear current block positions
499
            blocks.clear();
500
        });
501
    }
502
503
    private void breakBlock(BlockPos blockPos) {
504
        if (interact.get()) {
505
            // Interact mode
506
            BlockUtils.interact(new BlockHitResult(Vec3.atCenterOf(blockPos), BlockUtils.getDirection(blockPos), blockPos, true), InteractionHand.MAIN_HAND, swing.get());
507
            interacted.add(blockPos);
508
        } else if (packetMine.get()) {
509
            // Packet mine mode
510
            mc.gameMode.startPrediction(mc.level, sequence -> new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, blockPos, BlockUtils.getDirection(blockPos), sequence));
511
512
            if (swing.get()) mc.player.swing(InteractionHand.MAIN_HAND);
513
            else mc.getConnection().send(new ServerboundSwingPacket(InteractionHand.MAIN_HAND));
514
515
            mc.gameMode.startPrediction(mc.level, sequence -> new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, blockPos, BlockUtils.getDirection(blockPos), sequence));
516
        } else {
517
            // Legit mine mode
518
            BlockUtils.breakBlock(blockPos, swing.get());
519
        }
520
    }
521
522
    private boolean isOutOfRange(BlockPos blockPos) {
523
        Vec3 pos = Vec3.atCenterOf(blockPos);
524
        ClipContext clipContext = new ClipContext(mc.player.getEyePosition(), pos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player);
525
        BlockHitResult result = mc.level.clip(clipContext);
526
        if (result == null || !result.getBlockPos().equals(blockPos))
527
            return !PlayerUtils.isWithin(pos, wallsRange.get());
528
529
        return false;
530
    }
531
532
    private void addTargetedBlockToList() {
533
        if (!selectBlockBind.get().isPressed() || mc.gui.screen() != null) return;
534
535
        HitResult hitResult = mc.hitResult;
536
        if (hitResult == null || hitResult.getType() != HitResult.Type.BLOCK) return;
537
538
        BlockPos pos = ((BlockHitResult) hitResult).getBlockPos();
539
        Block targetBlock = mc.level.getBlockState(pos).getBlock();
540
541
        List<Block> list = listMode.get() == ListMode.Whitelist ? whitelist.get() : blacklist.get();
542
        String modeName = listMode.get().name();
543
544
        if (list.contains(targetBlock)) {
545
            list.remove(targetBlock);
546
            info("Removed " + Names.get(targetBlock) + " from " + modeName);
547
        } else {
548
            list.add(targetBlock);
549
            info("Added " + Names.get(targetBlock) + " to " + modeName);
550
        }
551
    }
552
553
    @EventHandler(priority = EventPriority.HIGHEST)
554
    private void onBlockBreakingCooldown(BlockBreakingCooldownEvent event) {
555
        event.cooldown = 0;
556
    }
557
558
    public enum Mode {
559
        All,
560
        Flatten,
561
        Smash
562
    }
563
564
    public enum SortMode {
565
        None,
566
        Closest,
567
        Furthest,
568
        TopDown
569
    }
570
571
    public enum Shape {
572
        Cube,
573
        UniformCube,
574
        Sphere
575
    }
576
577
    public static int chebyshevDist(int x1, int y1, int z1, int x2, int y2, int z2) {
578
        // Gets the largest X, Y or Z difference, chebyshev distance
579
        int dX = Math.abs(x2 - x1);
580
        int dY = Math.abs(y2 - y1);
581
        int dZ = Math.abs(z2 - z1);
582
        return Math.max(Math.max(dX, dY), dZ);
583
    }
584
}
585
MelaHack (ThunderHack fork)MISCsrc/main/java/thunder/hack/features/modules/misc/Nuker.javaJava · 296 lines · 12.7 KB

Automatically mines huge amounts of blocks.

SettingsSelectedBlocksModeDelayBlocksIgnoreWallsFlattenCreativeAvoidLavaRangeColorModeColor
Nuker.javaJava · Minecraft 26.2 · 296 lines · 12.7 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.misc;
2
3
import meteordevelopment.orbit.EventHandler;
4
import net.minecraft.ChatFormatting;
5
import net.minecraft.core.BlockPos;
6
import net.minecraft.core.Direction;
7
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
8
import net.minecraft.world.InteractionHand;
9
import net.minecraft.world.level.ClipContext;
10
import net.minecraft.world.level.block.Block;
11
import net.minecraft.world.level.block.Blocks;
12
import net.minecraft.world.level.block.LiquidBlock;
13
import net.minecraft.world.level.block.state.BlockState;
14
import net.minecraft.world.phys.AABB;
15
import net.minecraft.world.phys.BlockHitResult;
16
import net.minecraft.world.phys.HitResult;
17
import net.minecraft.world.phys.Vec3;
18
import thunder.hack.core.Managers;
19
import thunder.hack.core.manager.client.ModuleManager;
20
import thunder.hack.events.impl.EventAttackBlock;
21
import thunder.hack.events.impl.EventSetBlockState;
22
import thunder.hack.events.impl.EventSync;
23
import thunder.hack.events.impl.PlayerUpdateEvent;
24
import thunder.hack.features.modules.Module;
25
import thunder.hack.features.modules.client.HudEditor;
26
import thunder.hack.features.modules.player.SpeedMine;
27
import thunder.hack.setting.Setting;
28
import thunder.hack.setting.impl.ColorSetting;
29
import thunder.hack.setting.impl.ItemSelectSetting;
30
import thunder.hack.utility.Timer;
31
import thunder.hack.utility.world.ExplosionUtility;
32
import thunder.hack.utility.player.InteractionUtility;
33
import thunder.hack.utility.player.PlayerUtility;
34
import thunder.hack.utility.render.Render2DEngine;
35
import thunder.hack.utility.render.Render3DEngine;
36
import thunder.hack.utility.render.Render3DEngine.FillAction;
37
import thunder.hack.utility.render.Render3DEngine.OutlineAction;
38
import java.awt.*;
39
import java.util.ArrayList;
40
41
import static net.minecraft.world.level.block.Blocks.*;
42
import static thunder.hack.features.modules.client.ClientSettings.isRu;
43
import static thunder.hack.utility.render.Render3DEngine.FILLED_QUEUE;
44
import static thunder.hack.utility.render.Render3DEngine.FillAction;
45
import static thunder.hack.utility.render.Render3DEngine.OUTLINE_QUEUE;
46
import static thunder.hack.utility.render.Render3DEngine.OutlineAction;
47
48
import com.mojang.blaze3d.vertex.PoseStack;
49
50
public class Nuker extends Module {
51
    public Nuker() {
52
        super("Nuker", Category.MISC);
53
    }
54
55
    public final Setting<ItemSelectSetting> selectedBlocks = new Setting<>("SelectedBlocks", new ItemSelectSetting(new ArrayList<>()));
56
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.Default);
57
    private final Setting<Integer> delay = new Setting<>("Delay", 25, 0, 1000);
58
    private final Setting<BlockSelection> blocks = new Setting<>("Blocks", BlockSelection.Select);
59
    private final Setting<Boolean> ignoreWalls = new Setting<>("IgnoreWalls", false);
60
    private final Setting<Boolean> flatten = new Setting<>("Flatten", false);
61
    private final Setting<Boolean> creative = new Setting<>("Creative", false);
62
    private final Setting<Boolean> avoidLava = new Setting<>("AvoidLava", false);
63
    private final Setting<Float> range = new Setting<>("Range", 4.2f, 1.5f, 25f);
64
    private final Setting<ColorMode> colorMode = new Setting<>("ColorMode", ColorMode.Sync);
65
    public final Setting<ColorSetting> color = new Setting<>("Color", new ColorSetting(0x2250b4b4), v -> colorMode.getValue() == ColorMode.Custom);
66
67
    private Block targetBlockType;
68
    private BlockData blockData;
69
    private Timer breakTimer = new Timer();
70
71
    private NukerThread nukerThread = new NukerThread();
72
    private float rotationYaw, rotationPitch;
73
74
    @Override
75
    public void onEnable() {
76
        nukerThread = new NukerThread();
77
        nukerThread.setName("ThunderHack-NukerThread");
78
        nukerThread.setDaemon(true);
79
        nukerThread.start();
80
    }
81
82
    @Override
83
    public void onDisable() {
84
        nukerThread.interrupt();
85
    }
86
87
    @Override
88
    public void onUpdate() {
89
        if (!nukerThread.isAlive()) {
90
            nukerThread = new NukerThread();
91
            nukerThread.setName("ThunderHack-NukerThread");
92
            nukerThread.setDaemon(true);
93
            nukerThread.start();
94
        }
95
    }
96
97
    @EventHandler
98
    public void onBlockInteract(EventAttackBlock e) {
99
        if (mc.level.isEmptyBlock(e.getBlockPos())) return;
100
        if (blocks.getValue().equals(BlockSelection.Select) && targetBlockType != mc.level.getBlockState(e.getBlockPos()).getBlock()) {
101
            targetBlockType = mc.level.getBlockState(e.getBlockPos()).getBlock();
102
            sendMessage(isRu() ? "Выбран блок: " + ChatFormatting.AQUA + targetBlockType.getName().getString() : "Selected block: " + ChatFormatting.AQUA + targetBlockType.getName().getString());
103
        }
104
    }
105
106
    @EventHandler
107
    public void onBlockDestruct(EventSetBlockState e) {
108
        if (blockData != null && e.getPos() == blockData.bp && e.getState().isAir()) {
109
            blockData = null;
110
            new Thread(() -> {
111
                if ((targetBlockType != null || blocks.getValue().equals(BlockSelection.All)) && !mc.options.keyAttack.isDown() && blockData == null) {
112
                    blockData = getNukerBlockPos();
113
                }
114
            }).start();
115
        }
116
    }
117
118
    @EventHandler
119
    public void onSync(EventSync e) {
120
        if(rotationYaw != -999) {
121
            mc.player.setYRot(rotationYaw);
122
            mc.player.setXRot(rotationPitch);
123
            rotationYaw = -999;
124
        }
125
    }
126
127
128
    @EventHandler
129
    public void onPlayerUpdate(PlayerUpdateEvent e) {
130
        if (blockData != null) {
131
            if ((mc.level.getBlockState(blockData.bp).getBlock() != targetBlockType && blocks.getValue().equals(BlockSelection.Select))
132
                    || PlayerUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(blockData.bp)) > range.getPow2Value()
133
                    || mc.level.isEmptyBlock(blockData.bp))
134
                blockData = null;
135
        }
136
137
        if (blockData == null || mc.options.keyAttack.isDown()) return;
138
139
        float[] angle = InteractionUtility.calculateAngle(blockData.vec3d);
140
        rotationYaw = (angle[0]);
141
        rotationPitch = (angle[1]);
142
        ModuleManager.rotations.fixRotation = rotationYaw;
143
144
        if (mode.getValue() == Mode.Default) {
145
            breakBlock();
146
        }
147
148
        if (mode.getValue() == Mode.FastAF) {
149
            int intRange = (int) (Math.floor(range.getValue()) + 1);
150
            Iterable<BlockPos> blocks_ = BlockPos.withinManhattan(new BlockPos(BlockPos.containing(mc.player.position()).above()), intRange, intRange, intRange);
151
152
            for (BlockPos b : blocks_) {
153
                if (flatten.getValue() && b.getY() < mc.player.getY())
154
                    continue;
155
156
                if (avoidLava.getValue() && checkLava(b))
157
                    continue;
158
159
                BlockState state = mc.level.getBlockState(b);
160
161
                if (PlayerUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(b)) <= range.getPow2Value()) {
162
                    if (isAllowed(state.getBlock())) {
163
                        try {
164
                            sendSequencedPacket(id -> new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, b, Direction.UP, id));
165
                            mc.gameMode.destroyBlock(b);
166
                            mc.player.swing(InteractionHand.MAIN_HAND);
167
                        } catch (Exception ignored) {
168
                        }
169
                    }
170
                }
171
            }
172
        }
173
    }
174
175
    public synchronized void breakBlock() {
176
        if (blockData == null || mc.options.keyAttack.isDown()) return;
177
        if (ModuleManager.speedMine.isEnabled() && ModuleManager.speedMine.mode.getValue() == SpeedMine.Mode.Packet) {
178
            if (!ModuleManager.speedMine.alreadyActing(blockData.bp)) {
179
                mc.gameMode.startDestroyBlock(blockData.bp, blockData.dir);
180
                mc.player.swing(InteractionHand.MAIN_HAND);
181
            }
182
        } else {
183
            BlockPos cache = blockData.bp;
184
            mc.gameMode.continueDestroyBlock(blockData.bp, blockData.dir);
185
            mc.player.swing(InteractionHand.MAIN_HAND);
186
            if (creative.getValue())
187
                mc.gameMode.destroyBlock(cache);
188
        }
189
    }
190
191
    public void onRender3D(PoseStack stack) {
192
        BlockPos renderBp = null;
193
194
        if (blockData != null && blockData.bp != null)
195
            renderBp = blockData.bp;
196
197
        if (renderBp != null) {
198
            Color color1 = colorMode.getValue() == ColorMode.Sync ? HudEditor.getColor(1) : color.getValue().getColorObject();
199
            OUTLINE_QUEUE.add(new OutlineAction(new AABB(blockData.bp), color1, 2));
200
            FILLED_QUEUE.add(new FillAction(new AABB(blockData.bp), Render2DEngine.injectAlpha(color1, 100)));
201
        }
202
203
        if (mode.getValue() == Mode.Fast && breakTimer.passedMs(delay.getValue())) {
204
            breakBlock();
205
            breakTimer.reset();
206
        }
207
    }
208
209
    public BlockData getNukerBlockPos() {
210
        int intRange = (int) (Math.floor(range.getValue()) + 1);
211
        Iterable<BlockPos> blocks_ = BlockPos.withinManhattan(new BlockPos(BlockPos.containing(mc.player.position()).above()), intRange, intRange, intRange);
212
213
        for (BlockPos b : blocks_) {
214
            BlockState state = mc.level.getBlockState(b);
215
            if (flatten.getValue() && b.getY() < mc.player.getY())
216
                continue;
217
            if (PlayerUtility.squaredDistanceFromEyes(net.minecraft.world.phys.Vec3.atBottomCenterOf(b)) <= range.getPow2Value()) {
218
                if (avoidLava.getValue() && checkLava(b))
219
                    continue;
220
                if (isAllowed(state.getBlock())) {
221
                    if (ignoreWalls.getValue()) {
222
                        BlockHitResult result = ExplosionUtility.rayCastBlock(new ClipContext(InteractionUtility.getEyesPos(mc.player), net.minecraft.world.phys.Vec3.atBottomCenterOf(b), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, mc.player), b);
223
                        if(result != null)
224
                            return new BlockData(b, result.getLocation(), result.getDirection());
225
                    } else {
226
                        for (float x1 = 0f; x1 <= 1f; x1 += 0.2f) {
227
                            for (float y1 = 0f; y1 <= 1; y1 += 0.2f) {
228
                                for (float z1 = 0f; z1 <= 1; z1 += 0.2f) {
229
                                    Vec3 p = new Vec3(b.getX() + x1, b.getY() + y1, b.getZ() + z1);
230
                                    BlockHitResult bhr = mc.level.clip(new ClipContext(InteractionUtility.getEyesPos(mc.player), p, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player));
231
                                    if (bhr != null && bhr.getType() == HitResult.Type.BLOCK && bhr.getBlockPos().equals(b))
232
                                        return new BlockData(b, p, bhr.getDirection());
233
                                }
234
                            }
235
                        }
236
                    }
237
                }
238
            }
239
        }
240
        return null;
241
    }
242
243
    private boolean checkLava(BlockPos base) {
244
        for (Direction dir : Direction.values())
245
            if (mc.level.getBlockState(base.relative(dir)).getBlock() == Blocks.LAVA)
246
                return true;
247
        return false;
248
    }
249
250
    public class NukerThread extends Thread {
251
        @Override
252
        public void run() {
253
            while (!Thread.currentThread().isInterrupted()) {
254
                try {
255
                    if (!Module.fullNullCheck()) {
256
                        while (Managers.ASYNC.ticking.get()) {
257
                        }
258
259
                        if ((targetBlockType != null || !blocks.getValue().equals(BlockSelection.Select)) && !mc.options.keyAttack.isDown() && blockData == null) {
260
                            blockData = getNukerBlockPos();
261
                        }
262
                    } else {
263
                        Thread.yield();
264
                    }
265
                } catch (Exception ignored) {
266
                }
267
            }
268
        }
269
    }
270
271
    private boolean isAllowed(Block block) {
272
        boolean allowed = selectedBlocks.getValue().getItemsById().contains(block.getDescriptionId().replace("block.minecraft.", ""));
273
        return switch (blocks.getValue()) {
274
            case All -> block != BEDROCK && block != AIR && block != CAVE_AIR && !(block instanceof LiquidBlock) ;
275
            case Select -> block == targetBlockType;
276
            case WhiteList -> allowed;
277
            default -> !allowed && block != BEDROCK && block != AIR && block != CAVE_AIR && !(block instanceof LiquidBlock) ;
278
        };
279
    }
280
281
    private enum Mode {
282
        Default, Fast, FastAF
283
    }
284
285
    private enum ColorMode {
286
        Custom, Sync
287
    }
288
289
    private enum BlockSelection {
290
        Select, All, BlackList, WhiteList
291
    }
292
293
    public record BlockData(BlockPos bp, Vec3 vec3d, Direction dir) {
294
    }
295
}
296
OfflineClientWORLDsrc/main/java/com/jellypudding/offlineclient/modules/world/Nuker.javaJava · 548 lines · 21.8 KB

Breaks all blocks around you.

SettingsShapeRangeWalls rangeModeBlocksList modeSelect block bindLock targetFlatSmashSuitable tools onlyInteractSpeedBlocks per tickDelayAuto toolRotateOrderHighlight strengthBounding box
Nuker.javaJava · Minecraft 26.2 · 548 lines · 21.8 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.KeyPressEvent;
6
import com.jellypudding.offlineclient.event.events.Render3DEvent;
7
import com.jellypudding.offlineclient.event.events.TickEvent;
8
import com.jellypudding.offlineclient.module.Category;
9
import com.jellypudding.offlineclient.module.ExclusivityGroup;
10
import com.jellypudding.offlineclient.module.Module;
11
import com.jellypudding.offlineclient.util.InputUtil;
12
import com.jellypudding.offlineclient.render.BoxStyle;
13
import com.jellypudding.offlineclient.render.DrawBatch;
14
import com.jellypudding.offlineclient.setting.BoolSetting;
15
import com.jellypudding.offlineclient.setting.EnumSetting;
16
import com.jellypudding.offlineclient.setting.KeybindSetting;
17
import com.jellypudding.offlineclient.setting.NumberSetting;
18
import com.jellypudding.offlineclient.setting.RegistryListSetting;
19
import com.jellypudding.offlineclient.util.BlockMiner;
20
import com.jellypudding.offlineclient.util.BlockUtil;
21
import com.jellypudding.offlineclient.util.ChatUtil;
22
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
23
import com.jellypudding.offlineclient.util.ItemUtil;
24
import com.jellypudding.offlineclient.util.RotationPriority;
25
import com.jellypudding.offlineclient.util.SwingMode;
26
import net.minecraft.core.BlockPos;
27
import net.minecraft.core.Direction;
28
import net.minecraft.core.registries.BuiltInRegistries;
29
import net.minecraft.world.level.block.Block;
30
import net.minecraft.world.level.block.Blocks;
31
import net.minecraft.world.level.block.state.BlockState;
32
import net.minecraft.world.phys.AABB;
33
import net.minecraft.world.phys.BlockHitResult;
34
import net.minecraft.world.phys.HitResult;
35
import net.minecraft.world.phys.Vec3;
36
import org.lwjgl.glfw.GLFW;
37
38
import java.util.ArrayList;
39
import java.util.Comparator;
40
import java.util.HashMap;
41
import java.util.HashSet;
42
import java.util.List;
43
import java.util.Locale;
44
import java.util.Map;
45
import java.util.Set;
46
47
// Legit mode mines one block at a time like a held click.
48
// Instant mode fires the break packets straight away.
49
public final class Nuker extends Module {
50
51
    public enum Shape { SPHERE, UNIFORM_CUBE, CUBE }
52
53
    public enum Mode { ALL, SELECTED, LIST }
54
55
    public enum ListMode { WHITELIST, BLACKLIST }
56
57
    public enum Speed { LEGIT, INSTANT }
58
59
    public enum Order { NEAREST, FURTHEST, FASTEST, TOP_DOWN }
60
61
    private static final int RETRY_TICKS = 10;
62
    private static final int SLOW_GRACE_TICKS = 20;
63
64
    private static final int MAX_HIGHLIGHTS = 64;
65
66
    // The furthest a cube side may reach out.
67
    private static final int MAX_SIDE = 6;
68
69
    private final EnumSetting<Shape> shape = new EnumSetting<>("Shape",
70
        "The region searched for blocks.", Shape.SPHERE)
71
        .describe(Shape.SPHERE, "A ball of the given radius around you.")
72
        .describe(Shape.UNIFORM_CUBE, "A cube of the rounded range on every side.")
73
        .describe(Shape.CUBE, "A box with its own reach on each of the six sides.");
74
    private final NumberSetting range = new NumberSetting("Range",
75
        "How far from your eyes to break blocks.",
76
        4.5, 1, 6, 0.1).min(1).max(6).under(shape, Shape.SPHERE, Shape.UNIFORM_CUBE);
77
    private final NumberSetting up = sideSetting("Up", "above your feet").under(shape, Shape.CUBE);
78
    private final NumberSetting down = sideSetting("Down", "below your feet").under(shape, Shape.CUBE);
79
    private final NumberSetting left = sideSetting("Left", "to your left").under(shape, Shape.CUBE);
80
    private final NumberSetting right = sideSetting("Right", "to your right").under(shape, Shape.CUBE);
81
    private final NumberSetting forward = sideSetting("Forward", "in front of you").under(shape, Shape.CUBE);
82
    private final NumberSetting back = sideSetting("Back", "behind you").under(shape, Shape.CUBE);
83
    private final NumberSetting wallsRange = new NumberSetting("Walls range",
84
        "How far to break blocks with no clear view from your eyes.",
85
        4.5, 0, 6, 0.1).min(0).max(6);
86
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode",
87
        "Which blocks the module is allowed to break.", Mode.ALL)
88
        .describe(Mode.ALL, "Every block in range.")
89
        .describe(Mode.SELECTED, "Only the block type you click.")
90
        .describe(Mode.LIST, "Whatever the list below allows.");
91
    private final RegistryListSetting<Block> blocks = new RegistryListSetting<>("Blocks",
92
        "The blocks the list applies to. Click to pick them.", BuiltInRegistries.BLOCK,
93
        List.of(Blocks.BEDROCK, Blocks.BARRIER, Blocks.REINFORCED_DEEPSLATE,
94
            Blocks.SPAWNER, Blocks.TRIAL_SPAWNER, Blocks.VAULT, Blocks.END_PORTAL_FRAME,
95
            Blocks.CHEST, Blocks.TRAPPED_CHEST, Blocks.ENDER_CHEST,
96
            Blocks.BARREL, Blocks.SHULKER_BOX))
97
        .under(mode, Mode.LIST);
98
    private final EnumSetting<ListMode> listMode = new EnumSetting<>("List mode",
99
        "What the list means.", ListMode.BLACKLIST)
100
        .describe(ListMode.WHITELIST, "The list is what gets broken.")
101
        .describe(ListMode.BLACKLIST, "The list is what gets left alone.")
102
        .under(mode, Mode.LIST);
103
    private final KeybindSetting selectBind = new KeybindSetting("Select block bind",
104
        "Adds or removes the block under your crosshair from the list.", KeybindSetting.UNBOUND)
105
        .under(mode, Mode.LIST);
106
    private final BoolSetting lockTarget = new BoolSetting("Lock target",
107
        "Keeps the block you picked instead of following your next click.", false)
108
        .under(mode, Mode.SELECTED);
109
    private final BoolSetting flat = new BoolSetting("Flat",
110
        "Only breaks blocks at your feet or higher.", false);
111
    private final BoolSetting smash = new BoolSetting("Smash",
112
        "Only breaks blocks with no hardness such as plants and torches.", false);
113
    private final BoolSetting suitableTools = new BoolSetting("Suitable tools only",
114
        "Skips blocks your held item is the wrong tool for.", false);
115
    private final BoolSetting interact = new BoolSetting("Interact",
116
        "Right clicks each matching block once instead of breaking it.", false);
117
    private final EnumSetting<Speed> speed = new EnumSetting<>("Speed",
118
        "How the blocks come down.", Speed.LEGIT)
119
        .describe(Speed.LEGIT, "One block at a time like a held click.")
120
        .describe(Speed.INSTANT, "Fires the break packets for several at once.")
121
        .unless(interact);
122
    private final NumberSetting perTick = new NumberSetting("Blocks per tick",
123
        "How many one hit blocks to break each tick in Instant mode.", 4, 1, 16, 1)
124
        .min(1).under(speed, () -> !interact.isOn() && speed.is(Speed.INSTANT));
125
    private final NumberSetting delay = new NumberSetting("Delay",
126
        "Ticks to wait before starting on a new block.", 0, 0, 20, 1, " ticks").min(0);
127
    private final BoolSetting autoTool = new BoolSetting("Auto tool",
128
        "Holds your fastest tool before the break packets go out.", true)
129
        .under(speed, () -> !interact.isOn() && speed.is(Speed.INSTANT));
130
    private final BoolSetting rotate = new BoolSetting("Rotate",
131
        "Turn towards the block on the server side.", true);
132
    private final EnumSetting<Order> order = new EnumSetting<>("Order",
133
        "Which block gets dealt with first.", Order.NEAREST)
134
        .describe(Order.NEAREST, "The closest block first.")
135
        .describe(Order.FURTHEST, "The furthest block first.")
136
        .describe(Order.FASTEST, "The quickest block to break first.")
137
        .describe(Order.TOP_DOWN, "The highest block first.");
138
    private final EnumSetting<SwingMode> swing = SwingMode.setting(SwingMode.BOTH);
139
    private final BoxStyle blockStyle = new BoxStyle("Block", BoxStyle.Shape.BOTH, 0);
140
    private final NumberSetting highlightStrength = new NumberSetting("Highlight strength",
141
        "How strongly the blocks waiting their turn show.", 35, 0, 100, 5, "%").max(100);
142
    private final BoolSetting boundingBox = new BoolSetting("Bounding box",
143
        "Draws the cube region you are clearing.", true)
144
        .under(shape, Shape.UNIFORM_CUBE, Shape.CUBE);
145
    private final BoxStyle regionStyle = new BoxStyle("Region", BoxStyle.Shape.BOTH, 192)
146
        .under(boundingBox);
147
148
    private Block selected;
149
    private BlockPos current;
150
    private final Map<BlockPos, Integer> attempted = new HashMap<>();
151
    private final Set<BlockPos> interacted = new HashSet<>();
152
    private BlockPos slowPending;
153
    private int slowDeadline;
154
    private int lastTick;
155
    private BlockPos lastChosen;
156
    private int waitTicks;
157
158
    private final SlotSwap slots = new SlotSwap();
159
160
    // Filled once a tick and read by the renderer.
161
    private final List<BlockPos> candidates = new ArrayList<>();
162
163
    // The drawn cube for the two box shapes. Null whilst the shape is a sphere.
164
    private AABB region;
165
166
    // A block is scanned several times a tick and one raycast each covers them all.
167
    private final Map<BlockPos, Boolean> sightCache = new HashMap<>();
168
169
    public Nuker() {
170
        super("Nuker", "Breaks all blocks around you.", Category.WORLD);
171
        addSettings(shape, range, up, down, left, right, forward, back, wallsRange,
172
            mode, blocks, listMode, selectBind, lockTarget, flat, smash, suitableTools,
173
            interact, speed, perTick, delay, autoTool, rotate, order, swing);
174
        addSettings(blockStyle.settings());
175
        addSettings(highlightStrength, boundingBox);
176
        addSettings(regionStyle.settings());
177
        searchTags("dig", "excavate", "break blocks");
178
    }
179
180
    private static NumberSetting sideSetting(String name, String where) {
181
        return new NumberSetting(name, "How many blocks " + where + " to clear.",
182
            1, 0, MAX_SIDE, 1, " blocks").min(0).max(MAX_SIDE);
183
    }
184
185
    @Override
186
    public String getSuffix() {
187
        if (mode.is(Mode.SELECTED)) {
188
            return selected == null ? "Nothing selected" : BlockUtil.blockName(selected);
189
        }
190
        if (mode.is(Mode.LIST)) {
191
            return listMode.getValueString();
192
        }
193
        return shape.is(Shape.CUBE) ? "Cube" : range.getValueString();
194
    }
195
196
    @Override
197
    public ExclusivityGroup getExclusivityGroup() {
198
        return ExclusivityGroup.MINING;
199
    }
200
201
    @Override
202
    protected void onEnable() {
203
        reset();
204
        if (mode.is(Mode.SELECTED) && inGame()) {
205
            selectLookedAtBlock();
206
        }
207
    }
208
209
    @Override
210
    protected void onDisable() {
211
        BlockMiner.release();
212
        slots.restoreIfMine();
213
        reset();
214
    }
215
216
    private void reset() {
217
        current = null;
218
        attempted.clear();
219
        interacted.clear();
220
        candidates.clear();
221
        sightCache.clear();
222
        slowPending = null;
223
        lastChosen = null;
224
        waitTicks = 0;
225
        lastTick = 0;
226
        region = null;
227
    }
228
229
    private void selectLookedAtBlock() {
230
        if (mc.hitResult instanceof BlockHitResult hit && hit.getType() == HitResult.Type.BLOCK) {
231
            select(hit.getBlockPos());
232
        }
233
    }
234
235
    private void select(BlockPos pos) {
236
        if (lockTarget.isOn() && selected != null) {
237
            return;
238
        }
239
        BlockState state = BlockUtil.state(pos);
240
        if (state.isAir() || state.getBlock() == selected) {
241
            return;
242
        }
243
        selected = state.getBlock();
244
        current = null;
245
        ChatUtil.message("§bNuker §7now breaks §f" + BlockUtil.blockName(selected) + "§7.");
246
    }
247
248
    // A real click on a block in Selected mode picks that block type.
249
    @Subscribe
250
    private void onBlockBreak(BlockBreakEvent event) {
251
        if (BlockMiner.isSelfCall() || !mode.is(Mode.SELECTED) || !inGame()) {
252
            return;
253
        }
254
        select(event.getPos());
255
    }
256
257
    @Subscribe
258
    private void onKeyPress(KeyPressEvent event) {
259
        if (event.getAction() != GLFW.GLFW_PRESS || mc.gui.screen() != null) {
260
            return;
261
        }
262
        if (!selectBind.isBound() || event.getKey() != selectBind.getValue()) {
263
            return;
264
        }
265
        if (!inGame() || !mode.is(Mode.LIST)) {
266
            return;
267
        }
268
        if (!(mc.hitResult instanceof BlockHitResult hit) || hit.getType() != HitResult.Type.BLOCK) {
269
            return;
270
        }
271
        Block block = BlockUtil.state(hit.getBlockPos()).getBlock();
272
        String list = listMode.getValueString().toLowerCase(Locale.ROOT);
273
        if (blocks.contains(block)) {
274
            blocks.remove(block);
275
            ChatUtil.message("§bNuker §7took §f" + BlockUtil.blockName(block)
276
                + "§7 off the " + list + ".");
277
        } else {
278
            blocks.add(block);
279
            ChatUtil.message("§bNuker §7added §f" + BlockUtil.blockName(block)
280
                + "§7 to the " + list + ".");
281
        }
282
    }
283
284
    @Subscribe
285
    private void onTick(TickEvent event) {
286
        candidates.clear();
287
        sightCache.clear();
288
        region = null;
289
        if (!inGame() || mc.player.isSpectator()) {
290
            current = null;
291
            slots.restoreIfMine();
292
            return;
293
        }
294
        // Holding attack means the player is mining by hand.
295
        if (InputUtil.physicallyHeld(mc.options.keyAttack) || mc.player.isUsingItem()) {
296
            current = null;
297
            slots.restoreIfMine();
298
            return;
299
        }
300
        if (mode.is(Mode.SELECTED) && selected == null) {
301
            slots.restoreIfMine();
302
            return;
303
        }
304
        collect();
305
        sortCandidates();
306
        if (candidates.isEmpty()) {
307
            interacted.clear();
308
            waitTicks = 0;
309
            lastChosen = null;
310
            slots.restoreIfMine();
311
            return;
312
        }
313
        // A fresh target waits out the delay before anything is sent.
314
        BlockPos first = candidates.getFirst();
315
        if (lastChosen != null && !lastChosen.equals(first)) {
316
            waitTicks = delay.getInt();
317
        }
318
        lastChosen = first;
319
        if (waitTicks > 0) {
320
            waitTicks--;
321
            BlockMiner.release();
322
            return;
323
        }
324
        if (interact.isOn()) {
325
            slots.restoreIfMine();
326
            interactWith(first);
327
        } else if (speed.is(Speed.LEGIT)) {
328
            slots.restoreIfMine();
329
            mineLegit();
330
        } else {
331
            mineInstant();
332
        }
333
    }
334
335
    // Fills the candidate list with every block the region and the filters allow.
336
    private void collect() {
337
        if (shape.is(Shape.SPHERE)) {
338
            for (BlockPos pos : BlockUtil.positionsWithin(range.getValue())) {
339
                if (wanted(pos)) {
340
                    candidates.add(pos);
341
                }
342
            }
343
            return;
344
        }
345
        BlockPos centre = mc.player.blockPosition();
346
        if (shape.is(Shape.UNIFORM_CUBE)) {
347
            int r = Math.max(0, (int) Math.round(range.getValue()) - 1);
348
            region = new AABB(centre.offset(-r, -r, -r)).minmax(new AABB(centre.offset(r, r, r)));
349
            for (BlockPos pos : BlockPos.betweenClosed(centre.offset(-r, -r, -r), centre.offset(r, r, r))) {
350
                BlockPos fixed = pos.immutable();
351
                if (wanted(fixed)) {
352
                    candidates.add(fixed);
353
                }
354
            }
355
            return;
356
        }
357
        Direction facing = mc.player.getDirection();
358
        Direction side = facing.getClockWise();
359
        int ahead = forward.getInt();
360
        int behind = back.getInt();
361
        int starboard = right.getInt();
362
        int port = left.getInt();
363
        BlockPos far = centre.offset(facing.getStepX() * ahead + side.getStepX() * starboard,
364
            up.getInt(), facing.getStepZ() * ahead + side.getStepZ() * starboard);
365
        BlockPos near = centre.offset(-facing.getStepX() * behind - side.getStepX() * port,
366
            -down.getInt(), -facing.getStepZ() * behind - side.getStepZ() * port);
367
        region = new AABB(near).minmax(new AABB(far));
368
        for (BlockPos pos : BlockPos.betweenClosed(near, far)) {
369
            BlockPos fixed = pos.immutable();
370
            if (wanted(fixed)) {
371
                candidates.add(fixed);
372
            }
373
        }
374
    }
375
376
    private void sortCandidates() {
377
        switch (order.getValue()) {
378
            case NEAREST -> candidates.sort(Comparator.comparingDouble(BlockUtil::distanceTo));
379
            case FURTHEST -> candidates.sort(
380
                Comparator.comparingDouble((BlockPos pos) -> -BlockUtil.distanceTo(pos)));
381
            case FASTEST -> candidates.sort(Comparator.comparingInt(BlockUtil::breakTicks));
382
            case TOP_DOWN -> candidates.sort(Comparator.comparingInt((BlockPos pos) -> -pos.getY()));
383
        }
384
    }
385
386
    private void interactWith(BlockPos pos) {
387
        if (BlockUtil.useOn(pos, rotate.isOn(), false)) {
388
            swing.getValue().swing();
389
        }
390
        interacted.add(pos);
391
    }
392
393
    private void mineLegit() {
394
        if (current != null && !candidates.contains(current)) {
395
            current = null;
396
        }
397
        if (current == null) {
398
            current = candidates.getFirst();
399
        }
400
        if (!BlockMiner.mine(current, rotate.isOn(), swing.getValue())) {
401
            current = null;
402
        }
403
    }
404
405
    // One hit blocks get their packets right away. A slower block is only queued
406
    // when the previous one is gone or its break time has run out.
407
    private void mineInstant() {
408
        int now = mc.player.tickCount;
409
        // The tick count restarts on a respawn.
410
        if (now < lastTick) {
411
            attempted.clear();
412
            slowPending = null;
413
        }
414
        lastTick = now;
415
        attempted.values().removeIf(expiry -> expiry <= now);
416
        if (slowPending != null && (!candidates.contains(slowPending) || now >= slowDeadline)) {
417
            slowPending = null;
418
        }
419
        if (autoTool.isOn()) {
420
            // The tool has to be in hand before anything is judged a one hit block.
421
            holdTool(slowPending != null ? slowPending : candidates.getFirst());
422
        }
423
424
        int sent = 0;
425
        for (BlockPos pos : candidates) {
426
            if (sent >= perTick.getInt()) {
427
                break;
428
            }
429
            if (attempted.containsKey(pos)) {
430
                continue;
431
            }
432
            if (rotate.isOn()) {
433
                BlockUtil.faceVector(Vec3.atCenterOf(pos), RotationPriority.MINE);
434
            }
435
            if (BlockUtil.canInstantBreak(pos)) {
436
                BlockMiner.breakInstantly(pos);
437
                attempted.put(pos, now + RETRY_TICKS);
438
                sent++;
439
            } else if (slowPending == null) {
440
                BlockMiner.breakInstantly(pos);
441
                slowPending = pos;
442
                slowDeadline = now + BlockUtil.breakTicks(pos) + SLOW_GRACE_TICKS;
443
                attempted.put(pos, slowDeadline);
444
                sent++;
445
            }
446
        }
447
        if (sent > 0) {
448
            swing.getValue().swing();
449
        }
450
    }
451
452
    // Instant mode never reaches the vanilla mining call and AutoTool never sees
453
    // the block. This holds the tool the same way the single block miner does.
454
    private void holdTool(BlockPos pos) {
455
        if (pos == null) {
456
            slots.restoreIfMine();
457
            return;
458
        }
459
        // A slot the player picked themselves is left alone.
460
        if (slots.isHolding() && !slots.stillMine()) {
461
            slots.forget();
462
            return;
463
        }
464
        ItemUtil.selectBestTool(BlockUtil.state(pos), slots);
465
    }
466
467
    private boolean wanted(BlockPos pos) {
468
        BlockState state = BlockUtil.state(pos);
469
        if (state.isAir()) {
470
            return false;
471
        }
472
        if (!interact.isOn() && !BlockUtil.isBreakable(pos)) {
473
            return false;
474
        }
475
        if (state.getShape(mc.level, pos).isEmpty()) {
476
            return false;
477
        }
478
        if (mode.is(Mode.SELECTED) && state.getBlock() != selected) {
479
            return false;
480
        }
481
        if (mode.is(Mode.LIST)
482
            && blocks.contains(state.getBlock()) != listMode.is(ListMode.WHITELIST)) {
483
            return false;
484
        }
485
        if (smash.isOn() && state.getDestroySpeed(mc.level, pos) != 0) {
486
            return false;
487
        }
488
        if (flat.isOn() && pos.getY() + 0.5 < mc.player.getY()) {
489
            return false;
490
        }
491
        if (suitableTools.isOn() && !interact.isOn()
492
            && !mc.player.getMainHandItem().isCorrectToolForDrops(state)) {
493
            return false;
494
        }
495
        if (interact.isOn() && interacted.contains(pos)) {
496
            return false;
497
        }
498
        if (BlockUtil.isStandingOn(pos)) {
499
            return false;
500
        }
501
        return inReach(pos);
502
    }
503
504
    // The server refuses anything past the interaction range whatever the region says.
505
    private boolean inReach(BlockPos pos) {
506
        double distance = BlockUtil.distanceTo(pos);
507
        if (distance > mc.player.blockInteractionRange() + 1) {
508
            return false;
509
        }
510
        if (shape.is(Shape.SPHERE) && distance > range.getValue()) {
511
            return false;
512
        }
513
        return distance <= wallsRange.getValue() || hasLineOfSight(pos);
514
    }
515
516
    private boolean hasLineOfSight(BlockPos pos) {
517
        Boolean cached = sightCache.get(pos);
518
        if (cached != null) {
519
            return cached;
520
        }
521
        boolean result = BlockUtil.canSee(pos);
522
        sightCache.put(pos, result);
523
        return result;
524
    }
525
526
    @Subscribe
527
    private void onRender3D(Render3DEvent event) {
528
        if (region != null && boundingBox.isOn()) {
529
            regionStyle.draw(event.getBatch(), region, false);
530
        }
531
        float strength = (float) (highlightStrength.getValue() / 100);
532
        if (strength > 0) {
533
            int drawn = 0;
534
            for (BlockPos candidate : candidates) {
535
                if (drawn++ >= MAX_HIGHLIGHTS) {
536
                    break;
537
                }
538
                blockStyle.drawFading(event.getBatch(), DrawBatch.blockBox(candidate), strength, false);
539
            }
540
        }
541
        BlockPos pos = speed.is(Speed.LEGIT) ? current : slowPending;
542
        if (pos == null || interact.isOn() || !inGame() || BlockUtil.state(pos).isAir()) {
543
            return;
544
        }
545
        blockStyle.draw(event.getBatch(), DrawBatch.blockBox(pos), false);
546
    }
547
}
548
LiquidBounce (Kotlin)WORLDsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/nuker/ModuleNuker.ktKotlin · 88 lines · 3.3 KB

Automatically destroys all blocks in your area. Be careful!

SettingsFilterBlocksSwingIgnoreOpenInventory
ModuleNuker.ktKotlin · Minecraft 26.2 · 88 lines · 3.3 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.world.nuker
20
21
import net.ccbluex.liquidbounce.features.module.ClientModule
22
import net.ccbluex.liquidbounce.features.module.ModuleCategories
23
import net.ccbluex.liquidbounce.features.module.modules.world.nuker.area.FloorNukerArea
24
import net.ccbluex.liquidbounce.features.module.modules.world.nuker.area.SphereNukerArea
25
import net.ccbluex.liquidbounce.features.module.modules.world.nuker.mode.InstantNukerMode
26
import net.ccbluex.liquidbounce.features.module.modules.world.nuker.mode.LegitNukerMode
27
import net.ccbluex.liquidbounce.utils.block.SwingMode
28
import net.ccbluex.liquidbounce.utils.collection.Filter
29
import net.ccbluex.liquidbounce.utils.collection.blockSortedSetOf
30
import net.ccbluex.liquidbounce.utils.render.BreakingProgress
31
import net.ccbluex.liquidbounce.utils.render.BreakingProgressRenderer
32
import net.ccbluex.liquidbounce.utils.render.placement.PlacementRenderer
33
import net.minecraft.core.BlockPos
34
import net.minecraft.world.level.block.state.BlockState
35
36
/**
37
 * Nuker module
38
 *
39
 * Destroys blocks around you.
40
 */
41
object ModuleNuker : ClientModule("Nuker", ModuleCategories.WORLD, disableOnQuit = true), BreakingProgress.Provider {
42
43
    val mode =
44
        choices("Mode", LegitNukerMode, arrayOf(LegitNukerMode, InstantNukerMode))
45
    val areaMode = choices(
46
        "AreaMode",
47
        SphereNukerArea,
48
        arrayOf(SphereNukerArea, FloorNukerArea)
49
    )
50
    private val filter by enumChoice("Filter", Filter.BLACKLIST)
51
    private val blocks by blocks("Blocks", blockSortedSetOf())
52
53
    val swingMode by enumChoice("Swing", SwingMode.DO_NOT_HIDE)
54
    val ignoreOpenInventory by boolean("IgnoreOpenInventory", true)
55
56
    private val targetRenderer = tree(
57
        PlacementRenderer("TargetRendering", true, this, keep = false)
58
    )
59
    private val progressRenderer = targetRenderer.tree(
60
        BreakingProgressRenderer(targetRenderer, this)
61
    )
62
63
    override fun breakingProgress(): BreakingProgress? = when (mode.activeMode) {
64
        LegitNukerMode -> LegitNukerMode.breakingProgress()
65
        InstantNukerMode -> wasTarget?.let { BreakingProgress(it, 1f) }
66
        else -> null
67
    }
68
69
    /**
70
     * The last target block that was hit. Does not mean it was destroyed.
71
     */
72
    var wasTarget: BlockPos? = null
73
        set(value) {
74
            field = value
75
            targetRenderer.addBlock(value ?: return)
76
        }
77
78
    fun isValid(blockState: BlockState): Boolean {
79
        return filter.invoke(blockState.block, blocks)
80
    }
81
82
    override fun onDisabled() {
83
        wasTarget = null
84
        targetRenderer.clearSilently()
85
    }
86
87
}
88