block-esp module

block-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/blockesp/BlockESP.javaJava · 266 lines · 8.8 KB

Renders specified blocks through walls.

Settingsblocksdefault-block-configblock-configstracers
BlockESP.javaJava · Minecraft 26.2 · 266 lines · 8.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.render.blockesp;
7
8
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
9
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
10
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
11
import meteordevelopment.meteorclient.events.render.Render3DEvent;
12
import meteordevelopment.meteorclient.events.world.BlockUpdateEvent;
13
import meteordevelopment.meteorclient.events.world.ChunkDataEvent;
14
import meteordevelopment.meteorclient.events.world.TickEvent;
15
import meteordevelopment.meteorclient.renderer.ShapeMode;
16
import meteordevelopment.meteorclient.settings.*;
17
import meteordevelopment.meteorclient.systems.modules.Categories;
18
import meteordevelopment.meteorclient.systems.modules.Module;
19
import meteordevelopment.meteorclient.utils.Utils;
20
import meteordevelopment.meteorclient.utils.render.color.RainbowColors;
21
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
22
import meteordevelopment.orbit.EventHandler;
23
import net.minecraft.core.BlockPos;
24
import net.minecraft.world.level.ChunkPos;
25
import net.minecraft.world.level.block.Block;
26
import net.minecraft.world.level.chunk.ChunkAccess;
27
import net.minecraft.world.level.dimension.DimensionType;
28
29
import java.util.Iterator;
30
import java.util.List;
31
import java.util.Map;
32
import java.util.Set;
33
import java.util.concurrent.ExecutorService;
34
import java.util.concurrent.Executors;
35
36
public class BlockESP extends Module {
37
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
38
39
    // General
40
41
    private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
42
        .name("blocks")
43
        .description("Blocks to search for.")
44
        .onChanged(_ -> {
45
            if (isActive() && Utils.canUpdate()) onActivate();
46
        })
47
        .build()
48
    );
49
50
    private final Setting<ESPBlockData> defaultBlockConfig = sgGeneral.add(new GenericSetting.Builder<ESPBlockData>()
51
        .name("default-block-config")
52
        .description("Default block config.")
53
        .defaultValue(
54
            new ESPBlockData(
55
                ShapeMode.Lines,
56
                new SettingColor(0, 255, 200),
57
                new SettingColor(0, 255, 200, 25),
58
                true,
59
                new SettingColor(0, 255, 200, 125)
60
            )
61
        )
62
        .build()
63
    );
64
65
    private final Setting<Map<Block, ESPBlockData>> blockConfigs = sgGeneral.add(new BlockDataSetting.Builder<ESPBlockData>()
66
        .name("block-configs")
67
        .description("Config for each block.")
68
        .defaultData(defaultBlockConfig)
69
        .build()
70
    );
71
72
    private final Setting<Boolean> tracers = sgGeneral.add(new BoolSetting.Builder()
73
        .name("tracers")
74
        .description("Render tracer lines.")
75
        .defaultValue(false)
76
        .build()
77
    );
78
79
    private final BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos();
80
81
    private final Long2ObjectMap<ESPChunk> chunks = new Long2ObjectOpenHashMap<>();
82
    private final Set<ESPGroup> groups = new ReferenceOpenHashSet<>();
83
    private final ExecutorService workerThread = Executors.newSingleThreadExecutor();
84
85
    private DimensionType lastDimension;
86
87
    public BlockESP() {
88
        super(Categories.Render, "block-esp", "Renders specified blocks through walls.", "search");
89
90
        RainbowColors.register(this::onTickRainbow);
91
    }
92
93
    @Override
94
    public void onActivate() {
95
        synchronized (chunks) {
96
            chunks.clear();
97
            groups.clear();
98
        }
99
100
        for (ChunkAccess chunk : Utils.chunks()) {
101
            searchChunk(chunk);
102
        }
103
104
        lastDimension = mc.level.dimensionType();
105
    }
106
107
    @Override
108
    public void onDeactivate() {
109
        synchronized (chunks) {
110
            chunks.clear();
111
            groups.clear();
112
        }
113
    }
114
115
    private void onTickRainbow() {
116
        if (!isActive()) return;
117
118
        defaultBlockConfig.get().tickRainbow();
119
        for (ESPBlockData blockData : blockConfigs.get().values()) blockData.tickRainbow();
120
    }
121
122
    ESPBlockData getBlockData(Block block) {
123
        ESPBlockData blockData = blockConfigs.get().get(block);
124
        return blockData == null ? defaultBlockConfig.get() : blockData;
125
    }
126
127
    private void updateChunk(int x, int z) {
128
        ESPChunk chunk = chunks.get(ChunkPos.pack(x, z));
129
        if (chunk != null) chunk.update();
130
    }
131
132
    private void updateBlock(int x, int y, int z) {
133
        ESPChunk chunk = chunks.get(ChunkPos.pack(x >> 4, z >> 4));
134
        if (chunk != null) chunk.update(x, y, z);
135
    }
136
137
    public ESPBlock getBlock(int x, int y, int z) {
138
        ESPChunk chunk = chunks.get(ChunkPos.pack(x >> 4, z >> 4));
139
        return chunk == null ? null : chunk.get(x, y, z);
140
    }
141
142
    public ESPGroup newGroup(Block block) {
143
        synchronized (chunks) {
144
            ESPGroup group = new ESPGroup(block);
145
            groups.add(group);
146
            return group;
147
        }
148
    }
149
150
    public void removeGroup(ESPGroup group) {
151
        synchronized (chunks) {
152
            groups.remove(group);
153
        }
154
    }
155
156
    @EventHandler
157
    private void onChunkData(ChunkDataEvent event) {
158
        searchChunk(event.chunk());
159
    }
160
161
    private void searchChunk(ChunkAccess chunk) {
162
        workerThread.submit(() -> {
163
            if (!isActive()) return;
164
            ESPChunk schunk = ESPChunk.searchChunk(chunk, blocks.get());
165
166
            if (schunk.size() > 0) {
167
                synchronized (chunks) {
168
                    chunks.put(chunk.getPos().pack(), schunk);
169
                    schunk.update();
170
171
                    // Update neighbour chunks
172
                    updateChunk(chunk.getPos().x() - 1, chunk.getPos().z());
173
                    updateChunk(chunk.getPos().x() + 1, chunk.getPos().z());
174
                    updateChunk(chunk.getPos().x(), chunk.getPos().z() - 1);
175
                    updateChunk(chunk.getPos().x(), chunk.getPos().z() + 1);
176
                }
177
            }
178
        });
179
    }
180
181
    @EventHandler
182
    private void onBlockUpdate(BlockUpdateEvent event) {
183
        // Minecraft probably reuses the event.pos BlockPos instance because it causes problems when trying to use it inside another thread
184
        int bx = event.pos.getX();
185
        int by = event.pos.getY();
186
        int bz = event.pos.getZ();
187
188
        int chunkX = bx >> 4;
189
        int chunkZ = bz >> 4;
190
        long key = ChunkPos.pack(chunkX, chunkZ);
191
192
        boolean added = blocks.get().contains(event.newState.getBlock()) && !blocks.get().contains(event.oldState.getBlock());
193
        boolean removed = !added && !blocks.get().contains(event.newState.getBlock()) && blocks.get().contains(event.oldState.getBlock());
194
195
        if (added || removed) {
196
            workerThread.submit(() -> {
197
                synchronized (chunks) {
198
                    ESPChunk chunk = chunks.get(key);
199
200
                    if (chunk == null) {
201
                        chunk = new ESPChunk(chunkX, chunkZ);
202
                        if (chunk.shouldBeDeleted()) return;
203
204
                        chunks.put(key, chunk);
205
                    }
206
207
                    blockPos.set(bx, by, bz);
208
209
                    if (added) chunk.add(blockPos);
210
                    else chunk.remove(blockPos);
211
212
                    // Update neighbour blocks
213
                    for (int x = -1; x < 2; x++) {
214
                        for (int z = -1; z < 2; z++) {
215
                            for (int y = -1; y < 2; y++) {
216
                                if (x == 0 && y == 0 && z == 0) continue;
217
218
                                updateBlock(bx + x, by + y, bz + z);
219
                            }
220
                        }
221
                    }
222
                }
223
            });
224
        }
225
    }
226
227
    @EventHandler
228
    private void onPostTick(TickEvent.Post event) {
229
        DimensionType dimension = mc.level.dimensionType();
230
231
        if (lastDimension != dimension) onActivate();
232
        lastDimension = dimension;
233
    }
234
235
    @EventHandler
236
    private void onRender(Render3DEvent event) {
237
        synchronized (chunks) {
238
            for (Iterator<ESPChunk> it = chunks.values().iterator(); it.hasNext(); ) {
239
                ESPChunk chunk = it.next();
240
241
                if (chunk.shouldBeDeleted()) {
242
                    workerThread.submit(() -> {
243
                        for (ESPBlock block : chunk.blocks.values()) {
244
                            block.group.remove(block, false);
245
                            block.loaded = false;
246
                        }
247
                    });
248
249
                    it.remove();
250
                } else chunk.render(event);
251
            }
252
253
            if (tracers.get()) {
254
                for (ESPGroup group : groups) {
255
                    group.render(event);
256
                }
257
            }
258
        }
259
    }
260
261
    @Override
262
    public String getInfoString() {
263
        return "%s groups".formatted(groups.size());
264
    }
265
}
266