ChestESP module

ChestESP: Minecraft 26.3 cheat module, full source for every implementation (1 client: OfflineClient).

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.

OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/ChestEsp.javaJava · 412 lines · 19.1 KB

See containers through walls.

SettingsModeChestsChest colourTrapped chestsTrapped chest colourEnder chestsEnder chest colourShulkersShulker colourBarrelsBarrel colourFurnacesFurnace colourHoppersHopper colourDispensersDispenser colourDroppersDropper colourCraftersCrafter colourBrewing standsBrewing stand colourChiseled bookshelvesBookshelf colourDecorated potsPot colourChest minecartsChest minecart colourHopper minecartsHopper minecart colourChest boatsChest boat colourTracersFade distanceHide openedRecolour openedOpened colourForget keyRadius
ChestEsp.javaJava · Minecraft 26.2 · 412 lines · 19.1 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.KeyPressEvent;
5
import com.jellypudding.offlineclient.event.events.PacketSendEvent;
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.Module;
10
import com.jellypudding.offlineclient.render.BoxStyle;
11
import com.jellypudding.offlineclient.render.DrawBatch;
12
import com.jellypudding.offlineclient.setting.BoolSetting;
13
import com.jellypudding.offlineclient.setting.ColorSetting;
14
import com.jellypudding.offlineclient.setting.EnumSetting;
15
import com.jellypudding.offlineclient.setting.KeybindSetting;
16
import com.jellypudding.offlineclient.setting.NumberSetting;
17
import com.jellypudding.offlineclient.util.ColorUtil;
18
import net.minecraft.core.BlockPos;
19
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
20
import net.minecraft.world.entity.Entity;
21
import net.minecraft.world.level.Level;
22
import net.minecraft.world.level.block.ChestBlock;
23
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
24
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
25
import net.minecraft.world.level.block.entity.BlockEntity;
26
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
27
import net.minecraft.world.level.block.entity.ChestBlockEntity;
28
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
29
import net.minecraft.world.level.block.entity.CrafterBlockEntity;
30
import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity;
31
import net.minecraft.world.entity.vehicle.boat.AbstractChestBoat;
32
import net.minecraft.world.entity.vehicle.minecart.MinecartChest;
33
import net.minecraft.world.entity.vehicle.minecart.MinecartHopper;
34
import net.minecraft.world.level.block.entity.DispenserBlockEntity;
35
import net.minecraft.world.level.block.entity.DropperBlockEntity;
36
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
37
import net.minecraft.world.level.block.entity.HopperBlockEntity;
38
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
39
import net.minecraft.world.level.block.entity.TrappedChestBlockEntity;
40
import net.minecraft.world.level.block.state.BlockState;
41
import net.minecraft.world.level.block.state.properties.ChestType;
42
import net.minecraft.world.level.chunk.LevelChunk;
43
import net.minecraft.world.level.chunk.status.ChunkStatus;
44
import net.minecraft.world.phys.AABB;
45
import org.lwjgl.glfw.GLFW;
46
47
import java.lang.ref.WeakReference;
48
import java.util.ArrayList;
49
import java.util.HashMap;
50
import java.util.List;
51
import java.util.Map;
52
import java.util.Set;
53
import java.util.concurrent.ConcurrentHashMap;
54
55
public final class ChestEsp extends Module {
56
57
    public enum Mode { BOX, GLOW }
58
59
    // The box of a container with the colour it gets and whether it has a fancy renderer.
60
    private record Target(BlockPos pos, AABB box, int color, boolean modelled) {
61
    }
62
63
    // One sixteenth of a block. Chest models sit this far in from the block edge.
64
    private static final double PIXEL = 1.0 / 16;
65
    // Below this share of full strength a faded box is not worth drawing.
66
    private static final float FAINT = 0.075f;
67
68
    private final EnumSetting<Mode> mode = new EnumSetting<>("Mode", "How containers are marked.", Mode.BOX)
69
        .describe(Mode.BOX, "A box around each container.")
70
        .describe(Mode.GLOW, "A glowing outline around the true shape of chests and shulkers. The rest keep a box.");
71
    private final BoxStyle style = BoxStyle.shapeOnly(BoxStyle.Shape.BOTH);
72
    private final BoolSetting chests = new BoolSetting("Chests",
73
        "Highlight chests.", true);
74
    private final ColorSetting chestColor = new ColorSetting("Chest colour",
75
        "Colour of chests.", 38, 1f, 1f, false).under(chests);
76
    private final BoolSetting trappedChests = new BoolSetting("Trapped chests",
77
        "Highlight trapped chests in their own colour.", true);
78
    private final ColorSetting trappedColor = new ColorSetting("Trapped chest colour",
79
        "Colour of trapped chests.", 0, 1f, 1f, false).under(trappedChests);
80
    private final BoolSetting enderChests = new BoolSetting("Ender chests",
81
        "Highlight ender chests.", true);
82
    private final ColorSetting enderColor = new ColorSetting("Ender chest colour",
83
        "Colour of ender chests.", 268, 1f, 1f, false).under(enderChests);
84
    private final BoolSetting shulkers = new BoolSetting("Shulkers",
85
        "Highlight shulker boxes.", true);
86
    private final ColorSetting shulkerColor = new ColorSetting("Shulker colour",
87
        "Colour of shulker boxes.", 38, 1f, 1f, false).under(shulkers);
88
    private final BoolSetting barrels = new BoolSetting("Barrels",
89
        "Highlight barrels.", true);
90
    private final ColorSetting barrelColor = new ColorSetting("Barrel colour",
91
        "Colour of barrels.", 38, 1f, 1f, false).under(barrels);
92
    private final BoolSetting furnaces = new BoolSetting("Furnaces",
93
        "Also mark furnaces and smokers and blast furnaces.", true);
94
    private final ColorSetting furnaceColor = new ColorSetting("Furnace colour",
95
        "Colour of furnaces.", 24, 0.55f, 0.75f, false).under(furnaces);
96
    private final BoolSetting hoppers = new BoolSetting("Hoppers",
97
        "Also mark hoppers.", true);
98
    private final ColorSetting hopperColor = new ColorSetting("Hopper colour",
99
        "Colour of hoppers.", 0, 0f, 0.7f, false).under(hoppers);
100
    private final BoolSetting dispensers = new BoolSetting("Dispensers",
101
        "Also mark dispensers.", true);
102
    private final ColorSetting dispenserColor = new ColorSetting("Dispenser colour",
103
        "Colour of dispensers.", 0, 0f, 0.55f, false).under(dispensers);
104
    private final BoolSetting droppers = new BoolSetting("Droppers",
105
        "Also mark droppers.", true);
106
    private final ColorSetting dropperColor = new ColorSetting("Dropper colour",
107
        "Colour of droppers.", 0, 0f, 0.45f, false).under(droppers);
108
    private final BoolSetting crafters = new BoolSetting("Crafters",
109
        "Also mark crafters.", true);
110
    private final ColorSetting crafterColor = new ColorSetting("Crafter colour",
111
        "Colour of crafters.", 190, 0.45f, 0.8f, false).under(crafters);
112
    private final BoolSetting brewingStands = new BoolSetting("Brewing stands",
113
        "Also mark brewing stands.", true);
114
    private final ColorSetting brewingColor = new ColorSetting("Brewing stand colour",
115
        "Colour of brewing stands.", 300, 0.5f, 0.85f, false).under(brewingStands);
116
    private final BoolSetting bookshelves = new BoolSetting("Chiseled bookshelves",
117
        "Also mark chiselled bookshelves.", true);
118
    private final ColorSetting bookshelfColor = new ColorSetting("Bookshelf colour",
119
        "Colour of chiselled bookshelves.", 34, 0.6f, 0.7f, false).under(bookshelves);
120
    private final BoolSetting pots = new BoolSetting("Decorated pots",
121
        "Also mark decorated pots.", true);
122
    private final ColorSetting potColor = new ColorSetting("Pot colour",
123
        "Colour of decorated pots.", 14, 0.5f, 0.8f, false).under(pots);
124
    private final BoolSetting chestCarts = new BoolSetting("Chest minecarts",
125
        "Also mark minecarts with a chest.", true);
126
    private final ColorSetting chestCartColor = new ColorSetting("Chest minecart colour",
127
        "Colour of chest minecarts.", 45, 0.7f, 0.9f, false).under(chestCarts);
128
    private final BoolSetting hopperCarts = new BoolSetting("Hopper minecarts",
129
        "Also mark minecarts with a hopper.", true);
130
    private final ColorSetting hopperCartColor = new ColorSetting("Hopper minecart colour",
131
        "Colour of hopper minecarts.", 0, 0f, 0.7f, false).under(hopperCarts);
132
    private final BoolSetting chestBoats = new BoolSetting("Chest boats",
133
        "Also mark boats with a chest.", true);
134
    private final ColorSetting chestBoatColor = new ColorSetting("Chest boat colour",
135
        "Colour of chest boats.", 34, 0.65f, 0.85f, false).under(chestBoats);
136
    private final BoolSetting tracers = new BoolSetting("Tracers",
137
        "Draw a line from you to each container.", false);
138
    private final NumberSetting fadeDistance = new NumberSetting("Fade distance",
139
        "Containers closer than this fade out so they do not fill your view.", 6, 0, 12, 0.5, " blocks");
140
    private final BoolSetting hideOpened = new BoolSetting("Hide opened",
141
        "Containers you have opened are no longer drawn.", false);
142
    private final BoolSetting recolourOpened = new BoolSetting("Recolour opened",
143
        "Containers you have opened take the colour below.", false).unless(hideOpened);
144
    private final ColorSetting openedColor = new ColorSetting("Opened colour",
145
        "Colour of containers you have opened.", 300, 0.55f, 0.8f, false)
146
        .under(recolourOpened, () -> !hideOpened.isOn() && recolourOpened.isOn());
147
    private final KeybindSetting forgetKey = new KeybindSetting("Forget key",
148
        "Press to forget which containers you have opened.", KeybindSetting.UNBOUND);
149
    private final NumberSetting radius = new NumberSetting("Radius",
150
        "Chunk radius to scan around you.", 4, 1, 8, 1, " chunks");
151
152
    private final List<Target> targets = new ArrayList<>();
153
    // Positions you have right clicked. Written from the network thread.
154
    private final Set<BlockPos> opened = ConcurrentHashMap.newKeySet();
155
    // Glow colour by position for the block entity renderer mixin. Replaced whole each tick.
156
    private volatile Map<BlockPos, Integer> glows = Map.of();
157
    private WeakReference<Level> world = new WeakReference<>(null);
158
159
    // The colour the block entity being drawn right now should glow in. Zero for none.
160
    private static int currentGlow;
161
162
    public ChestEsp() {
163
        super("ChestESP", "See containers through walls.", Category.RENDER);
164
        addSettings(mode);
165
        addSettings(style.settings());
166
        addSettings(chests, chestColor, trappedChests, trappedColor, enderChests, enderColor,
167
            shulkers, shulkerColor, barrels, barrelColor,
168
            furnaces, furnaceColor, hoppers, hopperColor, dispensers, dispenserColor,
169
            droppers, dropperColor, crafters, crafterColor, brewingStands, brewingColor,
170
            bookshelves, bookshelfColor, pots, potColor,
171
            chestCarts, chestCartColor, hopperCarts, hopperCartColor, chestBoats, chestBoatColor,
172
            tracers, fadeDistance, hideOpened, recolourOpened,
173
            openedColor, forgetKey, radius);
174
        searchTags("storage esp", "container esp");
175
    }
176
177
    @Override
178
    public String getSuffix() {
179
        return count(targets.size());
180
    }
181
182
    @Override
183
    protected void onDisable() {
184
        targets.clear();
185
        opened.clear();
186
        glows = Map.of();
187
    }
188
189
    // Set by the block entity renderer mixin around each submit.
190
    public static void setCurrentGlow(int color) {
191
        currentGlow = color;
192
    }
193
194
    public static int currentGlow() {
195
        return currentGlow;
196
    }
197
198
    // The glow colour for a block entity at a position. Zero when it gets none.
199
    public int glowFor(BlockPos pos) {
200
        if (!isEnabled() || !mode.is(Mode.GLOW)) {
201
            return 0;
202
        }
203
        return glows.getOrDefault(pos, 0);
204
    }
205
206
    @Subscribe
207
    private void onPacketSend(PacketSendEvent event) {
208
        if (event.getPacket() instanceof ServerboundUseItemOnPacket packet && mc.level != null) {
209
            noteOpened(packet.getHitResult().getBlockPos());
210
        }
211
    }
212
213
    // Both halves of a double chest count as opened together.
214
    private void noteOpened(BlockPos pos) {
215
        BlockEntity blockEntity = mc.level.getBlockEntity(pos);
216
        if (blockEntity == null || colorFor(blockEntity) == 0) {
217
            return;
218
        }
219
        opened.add(pos);
220
        BlockState state = blockEntity.getBlockState();
221
        if (blockEntity instanceof ChestBlockEntity && state.hasProperty(ChestBlock.TYPE)
222
            && state.getValue(ChestBlock.TYPE) != ChestType.SINGLE) {
223
            opened.add(pos.relative(ChestBlock.getConnectedDirection(state)));
224
        }
225
    }
226
227
    @Subscribe
228
    private void onKeyPress(KeyPressEvent event) {
229
        if (event.getAction() == GLFW.GLFW_PRESS && mc.gui.screen() == null
230
            && forgetKey.isBound() && event.getKey() == forgetKey.getValue()) {
231
            opened.clear();
232
        }
233
    }
234
235
    @Subscribe
236
    private void onTick(TickEvent event) {
237
        targets.clear();
238
        if (!inGame()) {
239
            return;
240
        }
241
        if (mc.level != world.get()) {
242
            world = new WeakReference<>(mc.level);
243
            opened.clear();
244
        }
245
        int r = radius.getInt();
246
        int centerX = mc.player.chunkPosition().x();
247
        int centerZ = mc.player.chunkPosition().z();
248
        for (int dx = -r; dx <= r; dx++) {
249
            for (int dz = -r; dz <= r; dz++) {
250
                LevelChunk chunk = mc.level.getChunkSource()
251
                    .getChunk(centerX + dx, centerZ + dz, ChunkStatus.FULL, false);
252
                if (chunk != null) {
253
                    collectBlocks(chunk);
254
                }
255
            }
256
        }
257
        if (chestCarts.isOn() || hopperCarts.isOn() || chestBoats.isOn()) {
258
            collectVehicles();
259
        }
260
        glows = mode.is(Mode.GLOW) ? glowMap() : Map.of();
261
    }
262
263
    private Map<BlockPos, Integer> glowMap() {
264
        Map<BlockPos, Integer> map = new HashMap<>();
265
        for (Target target : targets) {
266
            if (target.pos() != null && target.modelled()) {
267
                map.put(target.pos(), target.color());
268
            }
269
        }
270
        return map;
271
    }
272
273
    private void collectBlocks(LevelChunk chunk) {
274
        for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
275
            int color = colorFor(blockEntity);
276
            if (color == 0) {
277
                continue;
278
            }
279
            BlockPos pos = blockEntity.getBlockPos();
280
            boolean wasOpened = opened.contains(pos);
281
            if (wasOpened && hideOpened.isOn()) {
282
                continue;
283
            }
284
            if (wasOpened && recolourOpened.isOn()) {
285
                color = openedColor.getColor();
286
            }
287
            boolean chestShape = blockEntity instanceof ChestBlockEntity
288
                || blockEntity instanceof EnderChestBlockEntity;
289
            AABB box = chestShape ? chestBox(pos) : DrawBatch.blockBox(pos);
290
            // A double chest is one container drawn from its right half.
291
            if (blockEntity instanceof ChestBlockEntity) {
292
                BlockState state = blockEntity.getBlockState();
293
                if (state.hasProperty(ChestBlock.TYPE)) {
294
                    ChestType type = state.getValue(ChestBlock.TYPE);
295
                    if (type == ChestType.LEFT) {
296
                        continue;
297
                    }
298
                    if (type == ChestType.RIGHT) {
299
                        box = box.minmax(chestBox(pos.relative(ChestBlock.getConnectedDirection(state))));
300
                    }
301
                }
302
            }
303
            boolean modelled = chestShape || blockEntity instanceof ShulkerBoxBlockEntity;
304
            targets.add(new Target(pos, box, color, modelled));
305
        }
306
    }
307
308
    private void collectVehicles() {
309
        for (Entity entity : mc.level.entitiesForRendering()) {
310
            int color = vehicleColorFor(entity);
311
            if (color != 0) {
312
                targets.add(new Target(null, entity.getBoundingBox(), color, false));
313
            }
314
        }
315
    }
316
317
    // Zero for a vehicle the settings leave out.
318
    private int vehicleColorFor(Entity entity) {
319
        if (entity instanceof MinecartChest) {
320
            return chestCarts.isOn() ? chestCartColor.getColor() : 0;
321
        }
322
        if (entity instanceof MinecartHopper) {
323
            return hopperCarts.isOn() ? hopperCartColor.getColor() : 0;
324
        }
325
        if (entity instanceof AbstractChestBoat) {
326
            return chestBoats.isOn() ? chestBoatColor.getColor() : 0;
327
        }
328
        return 0;
329
    }
330
331
    // The chest model is a pixel in from each side and two pixels short of the top.
332
    private static AABB chestBox(BlockPos pos) {
333
        return new AABB(pos.getX() + PIXEL, pos.getY(), pos.getZ() + PIXEL,
334
            pos.getX() + 1 - PIXEL, pos.getY() + 1 - 2 * PIXEL, pos.getZ() + 1 - PIXEL);
335
    }
336
337
    // Zero for a container the settings leave out. Subclasses are tested before their parents.
338
    private int colorFor(BlockEntity blockEntity) {
339
        if (blockEntity instanceof TrappedChestBlockEntity) {
340
            return trappedChests.isOn() ? trappedColor.getColor() : 0;
341
        }
342
        if (blockEntity instanceof ChestBlockEntity) {
343
            return chests.isOn() ? chestColor.getColor() : 0;
344
        }
345
        if (blockEntity instanceof EnderChestBlockEntity) {
346
            return enderChests.isOn() ? enderColor.getColor() : 0;
347
        }
348
        if (blockEntity instanceof ShulkerBoxBlockEntity) {
349
            return shulkers.isOn() ? shulkerColor.getColor() : 0;
350
        }
351
        if (blockEntity instanceof BarrelBlockEntity) {
352
            return barrels.isOn() ? barrelColor.getColor() : 0;
353
        }
354
        return otherColorFor(blockEntity);
355
    }
356
357
    // A dropper is a kind of dispenser. It has to be asked about first.
358
    private int otherColorFor(BlockEntity blockEntity) {
359
        if (blockEntity instanceof AbstractFurnaceBlockEntity) {
360
            return furnaces.isOn() ? furnaceColor.getColor() : 0;
361
        }
362
        if (blockEntity instanceof HopperBlockEntity) {
363
            return hoppers.isOn() ? hopperColor.getColor() : 0;
364
        }
365
        if (blockEntity instanceof DropperBlockEntity) {
366
            return droppers.isOn() ? dropperColor.getColor() : 0;
367
        }
368
        if (blockEntity instanceof DispenserBlockEntity) {
369
            return dispensers.isOn() ? dispenserColor.getColor() : 0;
370
        }
371
        if (blockEntity instanceof CrafterBlockEntity) {
372
            return crafters.isOn() ? crafterColor.getColor() : 0;
373
        }
374
        if (blockEntity instanceof BrewingStandBlockEntity) {
375
            return brewingStands.isOn() ? brewingColor.getColor() : 0;
376
        }
377
        if (blockEntity instanceof ChiseledBookShelfBlockEntity) {
378
            return bookshelves.isOn() ? bookshelfColor.getColor() : 0;
379
        }
380
        return blockEntity instanceof DecoratedPotBlockEntity && pots.isOn()
381
            ? potColor.getColor() : 0;
382
    }
383
384
    // Full strength beyond the fade distance and the square of the share inside it.
385
    private float strengthAt(AABB box) {
386
        double fade = fadeDistance.getValue();
387
        if (fade <= 0 || mc.player == null) {
388
            return 1;
389
        }
390
        double away = mc.player.distanceToSqr(box.getCenter());
391
        return away >= fade * fade ? 1 : (float) (away / (fade * fade));
392
    }
393
394
    @Subscribe
395
    private void onRender3D(Render3DEvent event) {
396
        DrawBatch batch = event.getBatch();
397
        for (Target target : targets) {
398
            float strength = strengthAt(target.box());
399
            if (strength < FAINT) {
400
                continue;
401
            }
402
            int color = ColorUtil.fade(target.color(), strength);
403
            if (!(mode.is(Mode.GLOW) && target.modelled())) {
404
                style.draw(batch, target.box(), color, true);
405
            }
406
            if (tracers.isOn()) {
407
                batch.tracer(target.box().getCenter(), color, true);
408
            }
409
        }
410
    }
411
}
412