Tunneller module

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

Digs a straight tunnel the way you face.

SettingsWidthHeightLengthWall off liquidsTorchesTorch spacing
Tunneller.javaJava · Minecraft 26.2 · 272 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.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.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.NumberSetting;
11
import com.jellypudding.offlineclient.util.AxisWalker;
12
import com.jellypudding.offlineclient.util.BlockMiner;
13
import com.jellypudding.offlineclient.util.BlockUtil;
14
import com.jellypudding.offlineclient.util.ChatUtil;
15
import com.jellypudding.offlineclient.util.InputUtil;
16
import com.jellypudding.offlineclient.util.InventoryUtil.SlotSwap;
17
import net.minecraft.core.BlockPos;
18
import net.minecraft.core.Direction;
19
import net.minecraft.world.level.block.Blocks;
20
import net.minecraft.world.phys.AABB;
21
22
import java.util.ArrayList;
23
import java.util.List;
24
25
// Digs a straight tunnel and walks along it.
26
// The axis is taken from the facing when it starts.
27
public final class Tunneller extends Module {
28
29
    private static final int TUNNEL_COLOR = 0xFF40C0FF;
30
    private static final int CURRENT_COLOR = 0xFFFF5030;
31
32
    // Depths looked at in one tick. Keeps a long clear stretch cheap.
33
    private static final int SCAN_DEPTHS = 8;
34
35
    private final NumberSetting width = new NumberSetting("Width",
36
        "How wide the tunnel is.", 1, 1, 5, 1, " blocks").min(1).max(9);
37
    private final NumberSetting height = new NumberSetting("Height",
38
        "How tall the tunnel is.", 2, 1, 5, 1, " blocks").min(1).max(9);
39
    private final NumberSetting length = new NumberSetting("Length",
40
        "How far to dig before stopping.", 64, 8, 512, 8, " blocks").min(1);
41
    private final BoolSetting wallLiquids = new BoolSetting("Wall off liquids",
42
        "Covers water and lava the tunnel breaks into with a block from your hotbar.", true);
43
    private final BoolSetting torches = new BoolSetting("Torches",
44
        "Puts a torch on the floor as you go. Needs torches in your hotbar.", false);
45
    private final NumberSetting spacing = new NumberSetting("Torch spacing",
46
        "Blocks between one torch and the next.", 8, 2, 16, 1, " blocks")
47
        .min(1).under(torches);
48
49
    private final AxisWalker walker = new AxisWalker();
50
    private final SlotSwap slots = new SlotSwap();
51
    private int cleared;
52
    private int lastTorch;
53
    private BlockPos current;
54
55
    public Tunneller() {
56
        super("Tunneller", "Digs a straight tunnel the way you face.", Category.WORLD);
57
        addSettings(width, height, length, wallLiquids, torches, spacing);
58
        searchTags("tunnel", "mine", "dig", "strip mine");
59
    }
60
61
    @Override
62
    public String getSuffix() {
63
        if (!walker.isLocked()) {
64
            return null;
65
        }
66
        return Math.min(cleared, length.getInt()) + " of " + length.getInt();
67
    }
68
69
    // Bringing this back at launch would start digging at once.
70
    @Override
71
    public boolean savesEnabledState() {
72
        return false;
73
    }
74
75
    @Override
76
    public ExclusivityGroup getExclusivityGroup() {
77
        return ExclusivityGroup.MINING;
78
    }
79
80
    @Override
81
    protected void onEnable() {
82
        walker.clear();
83
        slots.forget();
84
        current = null;
85
        if (inGame()) {
86
            lockAxis();
87
        }
88
    }
89
90
    private void lockAxis() {
91
        walker.lock();
92
        cleared = 0;
93
        lastTorch = 0;
94
    }
95
96
    @Override
97
    protected void onDisable() {
98
        BlockMiner.release();
99
        slots.restoreIfMine();
100
        InputUtil.release(mc.options.keyUp);
101
        walker.clear();
102
        current = null;
103
    }
104
105
    @Subscribe
106
    private void onTick(TickEvent event) {
107
        current = null;
108
        if (!inGame()) {
109
            InputUtil.release(mc.options.keyUp);
110
            return;
111
        }
112
        if (!walker.isLocked()) {
113
            lockAxis();
114
        }
115
        if (mc.player.isSpectator() || mc.player.isPassenger()) {
116
            stop("Tunneller stopped because you cannot dig from there.");
117
            return;
118
        }
119
        if (Math.abs(mc.player.getY() - walker.floorY()) > 1.5) {
120
            stop("Tunneller stopped because you left the tunnel floor.");
121
            return;
122
        }
123
124
        walker.holdAxis();
125
        if (wallLiquids.isOn() && sealLiquid()) {
126
            return;
127
        }
128
        current = nextBlock();
129
130
        if (current != null) {
131
            InputUtil.release(mc.options.keyUp);
132
            if (!BlockMiner.mine(current, true)) {
133
                current = null;
134
            }
135
            return;
136
        }
137
        if (cleared >= length.getInt() && walker.travelled() >= length.getInt() - 1) {
138
            ChatUtil.message("§bTunneller §7finished §f" + length.getInt() + "§7 blocks.");
139
            setEnabled(false);
140
            return;
141
        }
142
        BlockMiner.release();
143
        mc.options.keyUp.setDown(true);
144
        placeTorch();
145
    }
146
147
    private BlockPos nextBlock() {
148
        double reach = mc.player.blockInteractionRange();
149
        for (int scanned = 0; scanned < SCAN_DEPTHS && cleared < length.getInt(); scanned++) {
150
            BlockPos best = null;
151
            double bestDistance = Double.MAX_VALUE;
152
            boolean anyLeft = false;
153
            for (BlockPos pos : slice(cleared + 1)) {
154
                if (!BlockUtil.diggable(pos)) {
155
                    continue;
156
                }
157
                anyLeft = true;
158
                double distance = BlockUtil.distanceTo(pos);
159
                if (distance <= reach && distance < bestDistance) {
160
                    bestDistance = distance;
161
                    best = pos;
162
                }
163
            }
164
            if (!anyLeft) {
165
                cleared++;
166
                continue;
167
            }
168
            return best;
169
        }
170
        return null;
171
    }
172
173
    // A liquid touching the stretch just dug or about to be dug gets a block over it.
174
    // True when a block went down this tick.
175
    private boolean sealLiquid() {
176
        double reach = mc.player.blockInteractionRange();
177
        for (int depth = Math.max(1, cleared); depth <= cleared + 1; depth++) {
178
            for (int lane = leftLane() - 1; lane <= rightLane() + 1; lane++) {
179
                for (int up = -1; up <= height.getInt(); up++) {
180
                    boolean inside = lane >= leftLane() && lane <= rightLane()
181
                        && up >= 0 && up < height.getInt();
182
                    BlockPos pos = walker.blockAt(depth, lane, up);
183
                    if (inside || mc.level.getFluidState(pos).isEmpty()
184
                        || BlockUtil.distanceTo(pos) > reach) {
185
                        continue;
186
                    }
187
                    int slot = BlockUtil.findBlockSlot();
188
                    if (slot == -1) {
189
                        return false;
190
                    }
191
                    slots.select(slot);
192
                    boolean placed = BlockUtil.placeAny(pos, true, true);
193
                    slots.restoreIfMine();
194
                    if (placed) {
195
                        return true;
196
                    }
197
                }
198
            }
199
        }
200
        return false;
201
    }
202
203
    private List<BlockPos> slice(int depth) {
204
        List<BlockPos> result = new ArrayList<>(width.getInt() * height.getInt());
205
        for (int lane = leftLane(); lane <= rightLane(); lane++) {
206
            for (int up = 0; up < height.getInt(); up++) {
207
                result.add(walker.blockAt(depth, lane, up));
208
            }
209
        }
210
        return result;
211
    }
212
213
    private int leftLane() {
214
        return -((width.getInt() - 1) / 2);
215
    }
216
217
    private int rightLane() {
218
        return width.getInt() - 1 + leftLane();
219
    }
220
221
    // Puts a torch against the left wall at a set spacing.
222
    private void placeTorch() {
223
        if (!torches.isOn()) {
224
            return;
225
        }
226
        int depth = (int) Math.floor(walker.travelled());
227
        if (depth < 1 || depth - lastTorch < spacing.getInt()) {
228
            return;
229
        }
230
        BlockPos target = walker.blockAt(depth, leftLane(), 0);
231
        if (!BlockUtil.isReplaceable(target) || !BlockUtil.isSolid(target.below())) {
232
            return;
233
        }
234
        int slot = BlockUtil.findBlockSlot(block -> block == Blocks.TORCH || block == Blocks.SOUL_TORCH);
235
        if (slot == -1) {
236
            return;
237
        }
238
        slots.select(slot);
239
        if (BlockUtil.place(target, Direction.DOWN, true, true)) {
240
            lastTorch = depth;
241
        }
242
        slots.restoreIfMine();
243
    }
244
245
    private void stop(String reason) {
246
        ChatUtil.error(reason);
247
        setEnabled(false);
248
    }
249
250
    @Subscribe
251
    private void onRender3D(Render3DEvent event) {
252
        if (!walker.isLocked() || !inGame()) {
253
            return;
254
        }
255
        int end = Math.min(cleared + 1, length.getInt());
256
        if (end >= 1) {
257
            AABB near = box(1);
258
            AABB far = box(end);
259
            event.getBatch().outlineBox(near.minmax(far).inflate(0.005), TUNNEL_COLOR, true);
260
        }
261
        if (current != null) {
262
            event.getBatch().outlineBlock(current, CURRENT_COLOR, false);
263
        }
264
    }
265
266
    private AABB box(int depth) {
267
        AABB first = new AABB(walker.blockAt(depth, leftLane(), 0));
268
        AABB last = new AABB(walker.blockAt(depth, rightLane(), height.getInt() - 1));
269
        return first.minmax(last);
270
    }
271
}
272