tunnel-esp module

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

1 implementationRender

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

Meteor ClientRendersrc/main/java/meteordevelopment/meteorclient/systems/modules/render/TunnelESP.javaJava · 335 lines · 11.5 KB

Highlights tunnels.

Settingsheightconnectedshape-modeside-colorline-color
TunnelESP.javaJava · Minecraft 26.2 · 335 lines · 11.5 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.render;
7
8
import it.unimi.dsi.fastutil.ints.IntIterator;
9
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
10
import it.unimi.dsi.fastutil.ints.IntSet;
11
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
12
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
13
import meteordevelopment.meteorclient.MeteorClient;
14
import meteordevelopment.meteorclient.events.render.Render3DEvent;
15
import meteordevelopment.meteorclient.events.world.TickEvent;
16
import meteordevelopment.meteorclient.renderer.Renderer3D;
17
import meteordevelopment.meteorclient.renderer.ShapeMode;
18
import meteordevelopment.meteorclient.settings.*;
19
import meteordevelopment.meteorclient.systems.modules.Categories;
20
import meteordevelopment.meteorclient.systems.modules.Module;
21
import meteordevelopment.meteorclient.utils.Utils;
22
import meteordevelopment.meteorclient.utils.network.MeteorExecutor;
23
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
24
import meteordevelopment.meteorclient.utils.world.Dir;
25
import meteordevelopment.orbit.EventHandler;
26
import net.minecraft.core.BlockPos;
27
import net.minecraft.core.Direction;
28
import net.minecraft.world.level.ChunkPos;
29
import net.minecraft.world.level.Level;
30
import net.minecraft.world.level.block.Blocks;
31
import net.minecraft.world.level.block.state.BlockState;
32
import net.minecraft.world.level.chunk.ChunkAccess;
33
import net.minecraft.world.level.chunk.LevelChunkSection;
34
import net.minecraft.world.level.chunk.status.ChunkStatus;
35
import net.minecraft.world.level.levelgen.Heightmap;
36
37
public class TunnelESP extends Module {
38
    private static final BlockPos.MutableBlockPos BP = new BlockPos.MutableBlockPos();
39
    private static final Direction[] DIRECTIONS = {Direction.EAST, Direction.NORTH, Direction.SOUTH, Direction.WEST};
40
41
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
42
43
    private final Setting<Double> height = sgGeneral.add(new DoubleSetting.Builder()
44
        .name("height")
45
        .description("Height of the rendered box.")
46
        .defaultValue(0.1)
47
        .sliderMax(2)
48
        .build()
49
    );
50
51
    private final Setting<Boolean> connected = sgGeneral.add(new BoolSetting.Builder()
52
        .name("connected")
53
        .description("If neighbouring holes should be connected.")
54
        .defaultValue(true)
55
        .build()
56
    );
57
58
    private final Setting<ShapeMode> shapeMode = sgGeneral.add(new EnumSetting.Builder<ShapeMode>()
59
        .name("shape-mode")
60
        .description("How the shapes are rendered.")
61
        .defaultValue(ShapeMode.Both)
62
        .build()
63
    );
64
65
    private final Setting<SettingColor> sideColor = sgGeneral.add(new ColorSetting.Builder()
66
        .name("side-color")
67
        .description("The side color.")
68
        .defaultValue(new SettingColor(255, 175, 25, 50))
69
        .build()
70
    );
71
72
    private final Setting<SettingColor> lineColor = sgGeneral.add(new ColorSetting.Builder()
73
        .name("line-color")
74
        .description("The line color.")
75
        .defaultValue(new SettingColor(255, 175, 25, 255))
76
        .build()
77
    );
78
79
    private final Long2ObjectMap<TChunk> chunks = new Long2ObjectOpenHashMap<>();
80
81
    public TunnelESP() {
82
        super(Categories.Render, "tunnel-esp", "Highlights tunnels.");
83
    }
84
85
    @Override
86
    public void onDeactivate() {
87
        chunks.clear();
88
    }
89
90
    private static int pack(int x, int y, int z) {
91
        return ((x & 0xFF) << 24) | ((y & 0xFFFF) << 8) | (z & 0xFF);
92
    }
93
94
    private static byte getPackedX(int p) {
95
        return (byte) (p >> 24 & 0xFF);
96
    }
97
98
    private static short getPackedY(int p) {
99
        return (short) (p >> 8 & 0xFFFF);
100
    }
101
102
    private static byte getPackedZ(int p) {
103
        return (byte) (p & 0xFF);
104
    }
105
106
    private void searchChunk(ChunkAccess chunk, TChunk tChunk) {
107
        // Prepare variables
108
        Context ctx = new Context();
109
        IntSet set = new IntOpenHashSet();
110
111
        int startX = chunk.getPos().getMinBlockX();
112
        int startZ = chunk.getPos().getMinBlockZ();
113
114
        int endX = chunk.getPos().getMaxBlockX();
115
        int endZ = chunk.getPos().getMaxBlockZ();
116
117
        // Search for first set of tunnels
118
        for (int x = startX; x <= endX; x++) {
119
            for (int z = startZ; z <= endZ; z++) {
120
                int height = chunk.getOrCreateHeightmapUnprimed(Heightmap.Types.WORLD_SURFACE).getFirstAvailable(x - startX, z - startZ);
121
122
                for (short y = (short) mc.level.getMinY(); y < height; y++) {
123
                    if (isTunnel(ctx, x, y, z)) set.add(pack(x - startX, y, z - startZ));
124
                }
125
            }
126
        }
127
128
        // Remove tunnels which are 1 block long
129
        IntSet positions = new IntOpenHashSet();
130
131
        for (IntIterator it = set.iterator(); it.hasNext(); ) {
132
            int packed = it.nextInt();
133
134
            byte x = getPackedX(packed);
135
            short y = getPackedY(packed);
136
            byte z = getPackedZ(packed);
137
138
            if (x == 0 || x == 15 || z == 0 || z == 15) positions.add(packed);
139
            else {
140
                boolean has = false;
141
142
                for (Direction dir : DIRECTIONS) {
143
                    if (set.contains(pack(x + dir.getStepX(), y, z + dir.getStepZ()))) {
144
                        has = true;
145
                        break;
146
                    }
147
                }
148
149
                if (has) positions.add(packed);
150
            }
151
        }
152
153
        tChunk.positions = positions;
154
    }
155
156
    private boolean isTunnel(Context ctx, int x, int y, int z) {
157
        if (!canWalkIn(ctx, x, y, z)) return false;
158
159
        TunnelSide s1 = getTunnelSide(ctx, x + 1, y, z);
160
        if (s1 == TunnelSide.PartiallyBlocked) return false;
161
162
        TunnelSide s2 = getTunnelSide(ctx, x - 1, y, z);
163
        if (s2 == TunnelSide.PartiallyBlocked) return false;
164
165
        TunnelSide s3 = getTunnelSide(ctx, x, y, z + 1);
166
        if (s3 == TunnelSide.PartiallyBlocked) return false;
167
168
        TunnelSide s4 = getTunnelSide(ctx, x, y, z - 1);
169
        if (s4 == TunnelSide.PartiallyBlocked) return false;
170
171
        return (s1 == TunnelSide.Walkable && s2 == TunnelSide.Walkable && s3 == TunnelSide.FullyBlocked && s4 == TunnelSide.FullyBlocked) || (s1 == TunnelSide.FullyBlocked && s2 == TunnelSide.FullyBlocked && s3 == TunnelSide.Walkable && s4 == TunnelSide.Walkable);
172
    }
173
174
    private TunnelSide getTunnelSide(Context ctx, int x, int y, int z) {
175
        if (canWalkIn(ctx, x, y, z)) return TunnelSide.Walkable;
176
        if (!canWalkThrough(ctx, x, y, z) && !canWalkThrough(ctx, x, y + 1, z)) return TunnelSide.FullyBlocked;
177
        return TunnelSide.PartiallyBlocked;
178
    }
179
180
    private boolean canWalkOn(Context ctx, int x, int y, int z) {
181
        BlockState state = ctx.get(x, y, z);
182
183
        if (state.isAir()) return false;
184
        if (!state.getFluidState().isEmpty()) return false;
185
186
        return !state.getCollisionShape(mc.level, BP.set(x, y, z)).isEmpty();
187
    }
188
189
    private boolean canWalkThrough(Context ctx, int x, int y, int z) {
190
        BlockState state = ctx.get(x, y, z);
191
192
        if (state.isAir()) return true;
193
        if (!state.getFluidState().isEmpty()) return false;
194
195
        return state.getCollisionShape(mc.level, BP.set(x, y, z)).isEmpty();
196
    }
197
198
    private boolean canWalkIn(Context ctx, int x, int y, int z) {
199
        if (!canWalkOn(ctx, x, y - 1, z)) return false;
200
        if (!canWalkThrough(ctx, x, y, z)) return false;
201
        if (canWalkThrough(ctx, x, y + 2, z)) return false;
202
        return canWalkThrough(ctx, x, y + 1, z);
203
    }
204
205
    @EventHandler
206
    private void onTick(TickEvent.Post event) {
207
        synchronized (chunks) {
208
            for (TChunk tChunk : chunks.values()) tChunk.marked = false;
209
            int added = 0;
210
211
            for (ChunkAccess chunk : Utils.chunks(true)) {
212
                long key = ChunkPos.pack(chunk.getPos().x(), chunk.getPos().z());
213
214
                if (chunks.containsKey(key)) chunks.get(key).marked = true;
215
                else if (added < 48) {
216
                    TChunk tChunk = new TChunk(chunk.getPos().x(), chunk.getPos().z());
217
                    chunks.put(tChunk.getKey(), tChunk);
218
219
                    MeteorExecutor.execute(() -> searchChunk(chunk, tChunk));
220
                    added++;
221
                }
222
            }
223
224
            chunks.values().removeIf(tChunk -> !tChunk.marked);
225
        }
226
    }
227
228
    @EventHandler
229
    private void onRender3D(Render3DEvent event) {
230
        synchronized (chunks) {
231
            for (TChunk chunk : chunks.values()) chunk.render(event.renderer);
232
        }
233
    }
234
235
    private boolean chunkContains(TChunk chunk, int x, int y, int z) {
236
        int key;
237
238
        if (x == -1) {
239
            chunk = chunks.get(ChunkPos.pack(chunk.x - 1, chunk.z));
240
            key = pack(15, y, z);
241
        } else if (x == 16) {
242
            chunk = chunks.get(ChunkPos.pack(chunk.x + 1, chunk.z));
243
            key = pack(0, y, z);
244
        } else if (z == -1) {
245
            chunk = chunks.get(ChunkPos.pack(chunk.x, chunk.z - 1));
246
            key = pack(x, y, 15);
247
        } else if (z == 16) {
248
            chunk = chunks.get(ChunkPos.pack(chunk.x, chunk.z + 1));
249
            key = pack(x, y, 0);
250
        } else key = pack(x, y, z);
251
252
        return chunk != null && chunk.positions != null && chunk.positions.contains(key);
253
    }
254
255
    private class TChunk {
256
        private final int x, z;
257
        public IntSet positions;
258
259
        public boolean marked;
260
261
        public TChunk(int x, int z) {
262
            this.x = x;
263
            this.z = z;
264
            this.marked = true;
265
        }
266
267
        public void render(Renderer3D renderer) {
268
            if (positions == null) return;
269
270
            // Manual iteration to avoid boxing
271
            for (IntIterator it = positions.iterator(); it.hasNext(); ) {
272
                int pos = it.nextInt();
273
274
                int x = getPackedX(pos);
275
                int y = getPackedY(pos);
276
                int z = getPackedZ(pos);
277
278
                int excludeDir = 0;
279
280
                if (connected.get()) {
281
                    for (Direction dir : DIRECTIONS) {
282
                        if (chunkContains(this, x + dir.getStepX(), y, z + dir.getStepZ()))
283
                            excludeDir |= Dir.get(dir);
284
                    }
285
                }
286
287
                x += this.x * 16;
288
                z += this.z * 16;
289
290
                renderer.box(x, y, z, x + 1, y + height.get(), z + 1, sideColor.get(), lineColor.get(), shapeMode.get(), excludeDir);
291
            }
292
        }
293
294
        public long getKey() {
295
            return ChunkPos.pack(x, z);
296
        }
297
    }
298
299
    private static class Context {
300
        private final Level world;
301
302
        private ChunkAccess lastChunk;
303
304
        public Context() {
305
            this.world = MeteorClient.mc.level;
306
        }
307
308
        public BlockState get(int x, int y, int z) {
309
            if (world.isOutsideBuildHeight(y)) return Blocks.VOID_AIR.defaultBlockState();
310
311
            int cx = x >> 4;
312
            int cz = z >> 4;
313
314
            ChunkAccess chunk;
315
316
            if (lastChunk != null && lastChunk.getPos().x() == cx && lastChunk.getPos().z() == cz) chunk = lastChunk;
317
            else chunk = world.getChunk(cx, cz, ChunkStatus.FULL, false);
318
319
            if (chunk == null) return Blocks.VOID_AIR.defaultBlockState();
320
321
            LevelChunkSection section = chunk.getSections()[chunk.getSectionIndex(y)];
322
            if (section == null) return Blocks.VOID_AIR.defaultBlockState();
323
324
            lastChunk = chunk;
325
            return section.getBlockState(x & 15, y & 15, z & 15);
326
        }
327
    }
328
329
    private enum TunnelSide {
330
        Walkable,
331
        PartiallyBlocked,
332
        FullyBlocked
333
    }
334
}
335