StorageEsp module

StorageEsp: Minecraft 26.3 cheat module, full source for every implementation (3 clients: MelaHack (ThunderHack fork), KiwiClient, LiquidBounce (Kotlin)).

3 implementationsRENDER

Full module source: 3 implementations

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

MelaHack (ThunderHack fork)RENDERsrc/main/java/thunder/hack/features/modules/render/StorageEsp.javaJava · 163 lines · 8.3 KB

Highlights selected storages.

SettingsOutlineFillChestTrapped ChestDispenserShulkerEnder ChestFurnaceHopperBarrelMinecartItemFrameChestColorTrappedChestColorShulkerColorEChestColorFrameColorShulkFrameColorFurnaceColorHopperColorDispenserColorBarrelColorMinecartColor
StorageEsp.javaJava · Minecraft 26.2 · 163 lines · 8.3 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import net.minecraft.world.entity.Entity;
4
import net.minecraft.world.entity.decoration.ItemFrame;
5
import net.minecraft.world.entity.vehicle.minecart.MinecartChest;
6
import net.minecraft.world.item.BlockItem;
7
import net.minecraft.world.level.block.ShulkerBoxBlock;
8
import net.minecraft.world.level.block.entity.*;
9
import net.minecraft.world.level.chunk.LevelChunk;
10
import net.minecraft.world.phys.AABB;
11
import org.jetbrains.annotations.Nullable;
12
import thunder.hack.core.Managers;
13
import thunder.hack.features.modules.Module;
14
import thunder.hack.setting.Setting;
15
import thunder.hack.setting.impl.ColorSetting;
16
import thunder.hack.utility.render.Render2DEngine;
17
import thunder.hack.utility.render.Render3DEngine;
18
import thunder.hack.utility.render.Render3DEngine.FillAction;
19
import thunder.hack.utility.render.Render3DEngine.OutlineAction;
20
21
import static thunder.hack.utility.render.Render3DEngine.FILLED_QUEUE;
22
import static thunder.hack.utility.render.Render3DEngine.FillAction;
23
import static thunder.hack.utility.render.Render3DEngine.OUTLINE_QUEUE;
24
import static thunder.hack.utility.render.Render3DEngine.OutlineAction;
25
26
import com.mojang.blaze3d.vertex.PoseStack;
27
import java.awt.*;
28
import java.util.ArrayList;
29
import java.util.List;
30
31
public class StorageEsp extends Module {
32
    public StorageEsp() {
33
        super("StorageEsp", Category.RENDER);
34
    }
35
36
    public final Setting<Boolean> outline = new Setting<>("Outline", true);
37
    public final Setting<Boolean> fill = new Setting<>("Fill", true);
38
39
    public final Setting<Boolean> chest = new Setting<>("Chest", true);
40
    public final Setting<Boolean> trappedChest = new Setting<>("Trapped Chest", true);
41
    public final Setting<Boolean> dispenser = new Setting<>("Dispenser", false);
42
    public final Setting<Boolean> shulker = new Setting<>("Shulker", true);
43
    public final Setting<Boolean> echest = new Setting<>("Ender Chest", true);
44
    public final Setting<Boolean> furnace = new Setting<>("Furnace", false);
45
    public final Setting<Boolean> hopper = new Setting<>("Hopper", false);
46
    public final Setting<Boolean> barrels = new Setting<>("Barrel", false);
47
48
    public final Setting<Boolean> cart = new Setting<>("Minecart", false);
49
    public final Setting<Boolean> frame = new Setting<>("ItemFrame", false);
50
    private final Setting<ColorSetting> chestColor = new Setting<>("ChestColor", new ColorSetting(0x8800FF00));
51
    private final Setting<ColorSetting> trappedChestColor = new Setting<>("TrappedChestColor", new ColorSetting(0x8800FF00));
52
    private final Setting<ColorSetting> shulkColor = new Setting<>("ShulkerColor", new ColorSetting(0x8800FF00));
53
    private final Setting<ColorSetting> echestColor = new Setting<>("EChestColor", new ColorSetting(0x8800FF00));
54
    private final Setting<ColorSetting> frameColor = new Setting<>("FrameColor", new ColorSetting(0x8800FF00));
55
    private final Setting<ColorSetting> shulkerframeColor = new Setting<>("ShulkFrameColor", new ColorSetting(0x8800FF00));
56
    private final Setting<ColorSetting> furnaceColor = new Setting<>("FurnaceColor", new ColorSetting(0x8800FF00));
57
    private final Setting<ColorSetting> hopperColor = new Setting<>("HopperColor", new ColorSetting(0x8800FF00));
58
    private final Setting<ColorSetting> dispenserColor = new Setting<>("DispenserColor", new ColorSetting(0x8800FF00));
59
    private final Setting<ColorSetting> barrelColor = new Setting<>("BarrelColor", new ColorSetting(0x8800FF00));
60
    private final Setting<ColorSetting> minecartColor = new Setting<>("MinecartColor", new ColorSetting(0x8800FF00));
61
62
    public void onRender3D(PoseStack stack) {
63
        if (false) return;
64
        for (BlockEntity blockEntity : getBlockEntities()) {
65
            Color color = getColor(blockEntity);
66
67
            if (color == null) continue;
68
69
            AABB chestbox = new AABB(
70
                    blockEntity.getBlockPos().getX() + 0.06,
71
                    blockEntity.getBlockPos().getY(),
72
                    blockEntity.getBlockPos().getZ() + 0.06,
73
                    (blockEntity.getBlockPos().getX() + 0.94),
74
                    (blockEntity.getBlockPos().getY() - 0.125 + 1),
75
                    (blockEntity.getBlockPos().getZ() + 0.94)
76
            );
77
78
            if (fill.getValue()) {
79
                if (blockEntity instanceof ChestBlockEntity) {
80
                    FILLED_QUEUE.add(new FillAction(chestbox, color));
81
                } else if (blockEntity instanceof EnderChestBlockEntity) {
82
                    FILLED_QUEUE.add(new FillAction(chestbox, color));
83
                } else FILLED_QUEUE.add(new FillAction(new AABB(blockEntity.getBlockPos()), color));
84
            }
85
            if (outline.getValue()) {
86
                if (blockEntity instanceof ChestBlockEntity) {
87
                    OUTLINE_QUEUE.add(new OutlineAction(chestbox, Render2DEngine.injectAlpha(color, 255), 1f));
88
                } else if (blockEntity instanceof EnderChestBlockEntity) {
89
                    OUTLINE_QUEUE.add(new OutlineAction(chestbox, Render2DEngine.injectAlpha(color, 255), 1f));
90
                } else
91
                    OUTLINE_QUEUE.add(new OutlineAction(new AABB(blockEntity.getBlockPos()), Render2DEngine.injectAlpha(color, 255), 1f));
92
            }
93
        }
94
95
        for (Entity ent : Managers.ASYNC.getAsyncEntities()) {
96
            if (ent instanceof ItemFrame iframe && frame.getValue()) {
97
                Color frameColor1 = frameColor.getValue().getColorObject();
98
                if (iframe.getItem().getItem() instanceof BlockItem bitem && bitem.getBlock() instanceof ShulkerBoxBlock)
99
                    frameColor1 = shulkerframeColor.getValue().getColorObject();
100
101
                if (fill.getValue())
102
                    FILLED_QUEUE.add(new FillAction(iframe.getBoundingBox(), frameColor1));
103
104
                if (outline.getValue())
105
                    OUTLINE_QUEUE.add(new OutlineAction(iframe.getBoundingBox(), Render2DEngine.injectAlpha(frameColor1, 255), 1f));
106
            }
107
108
            if (ent instanceof MinecartChest mcart && cart.getValue()) {
109
                if (fill.getValue())
110
                    FILLED_QUEUE.add(new FillAction(mcart.getBoundingBox(), minecartColor.getValue().getColorObject()));
111
112
                if (outline.getValue())
113
                    OUTLINE_QUEUE.add(new OutlineAction(mcart.getBoundingBox(), Render2DEngine.injectAlpha(minecartColor.getValue().getColorObject(), 255), 1f));
114
            }
115
        }
116
    }
117
118
    @Nullable
119
    private Color getColor(BlockEntity bEnt) {
120
        Color color = null;
121
122
        if (bEnt instanceof TrappedChestBlockEntity && trappedChest.getValue())
123
            color = trappedChestColor.getValue().getColorObject();
124
        else if (bEnt instanceof ChestBlockEntity && chest.getValue() && bEnt.getType() != BlockEntityTypes.TRAPPED_CHEST)
125
            color = chestColor.getValue().getColorObject();
126
        else if (bEnt instanceof EnderChestBlockEntity && echest.getValue())
127
            color = echestColor.getValue().getColorObject();
128
        else if (bEnt instanceof BarrelBlockEntity && barrels.getValue())
129
            color = barrelColor.getValue().getColorObject();
130
        else if (bEnt instanceof ShulkerBoxBlockEntity && shulker.getValue())
131
            color = shulkColor.getValue().getColorObject();
132
        else if (bEnt instanceof AbstractFurnaceBlockEntity && furnace.getValue())
133
            color = furnaceColor.getValue().getColorObject();
134
        else if (bEnt instanceof DispenserBlockEntity && dispenser.getValue())
135
            color = dispenserColor.getValue().getColorObject();
136
        else if (bEnt instanceof HopperBlockEntity && hopper.getValue())
137
            color = hopperColor.getValue().getColorObject();
138
139
        return color;
140
    }
141
142
    public static List<BlockEntity> getBlockEntities() {
143
        List<BlockEntity> list = new ArrayList<>();
144
        for (LevelChunk chunk : getLoadedChunks())
145
            list.addAll(chunk.getBlockEntities().values());
146
147
        return list;
148
    }
149
150
    public static List<LevelChunk> getLoadedChunks() {
151
        List<LevelChunk> chunks = new ArrayList<>();
152
        int viewDist = mc.options.renderDistance().get();
153
        for (int x = -viewDist; x <= viewDist; x++) {
154
            for (int z = -viewDist; z <= viewDist; z++) {
155
                LevelChunk chunk = mc.level.getChunkSource().getChunkNow((int) mc.player.getX() / 16 + x, (int) mc.player.getZ() / 16 + z);
156
157
                if (chunk != null) chunks.add(chunk);
158
            }
159
        }
160
        return chunks;
161
    }
162
}
163
KiwiClientRENDERsrc/main/java/com/tangykiwi/kiwiclient/module/render/StorageESP.javaJava · 143 lines · 5.7 KB

Highlights storage containers

SettingsModeBoxFill
StorageESP.javaJava · Minecraft 26.2 · 143 lines · 5.7 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.render;
2
3
import com.google.common.eventbus.AllowConcurrentEvents;
4
import com.google.common.eventbus.Subscribe;
5
import com.tangykiwi.kiwiclient.event.LevelRenderEvent;
6
import com.tangykiwi.kiwiclient.event.TickEvent;
7
import com.tangykiwi.kiwiclient.module.Category;
8
import com.tangykiwi.kiwiclient.module.Module;
9
import com.tangykiwi.kiwiclient.module.setting.ModeSetting;
10
import com.tangykiwi.kiwiclient.module.setting.SliderSetting;
11
import com.tangykiwi.kiwiclient.util.WorldUtils;
12
import com.tangykiwi.kiwiclient.util.render.RenderUtils;
13
14
import net.minecraft.core.BlockPos;
15
import net.minecraft.core.Direction;
16
import net.minecraft.world.level.block.Block;
17
import net.minecraft.world.level.block.Blocks;
18
import net.minecraft.world.level.block.ChestBlock;
19
import net.minecraft.world.level.block.entity.BarrelBlockEntity;
20
import net.minecraft.world.level.block.entity.BlockEntity;
21
import net.minecraft.world.level.block.entity.ChestBlockEntity;
22
import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
23
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
24
import net.minecraft.world.level.block.entity.TrappedChestBlockEntity;
25
import net.minecraft.world.level.block.state.BlockState;
26
import net.minecraft.world.level.block.state.properties.ChestType;
27
import net.minecraft.world.phys.AABB;
28
29
import org.lwjgl.glfw.GLFW;
30
31
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
32
33
import java.util.HashMap;
34
import java.util.HashSet;
35
import java.util.Map;
36
import java.util.Set;
37
38
public class StorageESP extends Module {
39
    private Map<BlockEntity, Integer> blockEntities = new HashMap<>();
40
41
    private Set<BlockPos> blacklist = new HashSet<>();
42
43
    public StorageESP() {
44
        super("StorageESP","Highlights storage containers", GLFW.GLFW_KEY_R, Category.RENDER,
45
            new ModeSetting("Mode", "ESP mode", "Box+Fill", "Box", "Fill"),
46
            new SliderSetting("Box", "Box line thickness", 0.1, 4, 2, 1),
47
            new SliderSetting("Fill", "Fill opacity", 0, 1, 0.3, 2));
48
    }
49
50
    @Override
51
    public void onDisable() {
52
        blockEntities.clear();
53
54
        super.onDisable();
55
    }
56
57
    @Subscribe
58
    @AllowConcurrentEvents
59
    public void onTick(TickEvent event) {
60
        blockEntities.clear();
61
62
        for (BlockEntity be: WorldUtils.getBlockEntities()) {
63
            int color = getColorForBlock(be);
64
65
            if (color != -1) {
66
                blockEntities.put(be, color);
67
            }
68
        }
69
    }
70
71
    @Subscribe
72
    @AllowConcurrentEvents
73
    public void onRender(LevelRenderEvent event) {
74
        for (Map.Entry<BlockEntity, Integer> e: blockEntities.entrySet()) {
75
            if (blacklist.contains(e.getKey().getBlockPos())) {
76
                continue;
77
            }
78
79
            AABB box = new AABB(e.getKey().getBlockPos());
80
81
            Block block = e.getKey().getBlockState().getBlock();
82
83
            if (block == Blocks.CHEST || block == Blocks.TRAPPED_CHEST || block == Blocks.ENDER_CHEST) {
84
                box = box.inflate(-0.06, -0.06, -0.06);
85
                box = box.move(0, -0.06, 0);
86
87
                Direction dir = getChestDirection(e.getKey().getBlockPos());
88
                if (dir != null) {
89
                    box = box.inflate(Math.abs(dir.getStepX()) / 2d, 0, Math.abs(dir.getStepZ()) / 2d);
90
                    box = box.move(dir.getStepX() / 2d, 0, dir.getStepZ() / 2d);
91
                    blacklist.add(e.getKey().getBlockPos().offset(dir.getUnitVec3i()));
92
                }
93
            }
94
95
            float opacity = getSetting(2).asSlider().getValueFloat();
96
            if (getSetting(0).asMode().asMode().getValue() == 0 || getSetting(0).asMode().asMode().getValue() == 2) {
97
                RenderUtils.drawBoxFilled(event.getSubmitNodeStorage(), box, (int)(opacity * 255) << 24 | e.getValue());
98
            }
99
100
            if (getSetting(0).asMode().asMode().getValue() == 0 || getSetting(0).asMode().asMode().getValue() == 1) {
101
                RenderUtils.drawBoxOutline(event.getSubmitNodeStorage(), box, (int)(opacity * 255) << 24 | e.getValue(), getSetting(1).asSlider().getValueFloat());
102
            }
103
        }
104
105
        blacklist.clear();
106
    }
107
108
    private int getColorForBlock(BlockEntity be) {
109
        if (be instanceof TrappedChestBlockEntity) {
110
            return ((int)(0.75F * 255) << 16 | 0 << 8 | 0);
111
        } else if (be instanceof ChestBlockEntity) {
112
            return (255 << 16 | (int)(0.6F * 255) << 8 | (int)(0.3F * 255));
113
        } else if (be instanceof BarrelBlockEntity) {
114
            return ((int)(0.5F * 255) << 16 | (int)(0.5F * 255) << 8 | (int)(0.5F * 255));
115
        } else if (be instanceof EnderChestBlockEntity) {
116
            return ((int)(0.5F * 255) << 16 | (int)(0.2F * 255) << 8 | 255);
117
//        } else if (be instanceof AbstractFurnaceBlockEntity) {
118
//            return new float[] { 0.5F, 0.5F, 0.5F };
119
//        } else if (be instanceof DispenserBlockEntity) {
120
//            return new float[] { 0.55F, 0.55F, 0.7F };
121
//        } else if (be instanceof HopperBlockEntity) {
122
//            return new float[] { 0.45F, 0.45F, 0.6F };
123
        } else if (be instanceof ShulkerBoxBlockEntity) {
124
            return (255 << 16 | (int)(0.05F * 255) << 8 | 255);
125
//        } else if (be instanceof BrewingStandBlockEntity) {
126
//            return new float[] { 0.5F, 0.4F, 0.2F };
127
        }
128
129
        return -1;
130
    }
131
132
    /** returns the direction of the other chest if its linked, otherwise null **/
133
    private Direction getChestDirection(BlockPos pos) {
134
        BlockState state = mc.level.getBlockState(pos);
135
136
        if (state.getBlock() instanceof ChestBlock && state.getValue(ChestBlock.TYPE) != ChestType.SINGLE) {
137
            return ChestBlock.getConnectedDirection(state);
138
        }
139
140
        return null;
141
    }
142
}
143
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleStorageESP.ktKotlin · 487 lines · 18.6 KB

Highlights all blocks that can contain items allowing you to see them rough walls.

SettingsColorTracersRequiresChestStealerMergeAdjacentOutline
ModuleStorageESP.ktKotlin · Minecraft 26.2 · 487 lines · 18.6 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.render
20
21
import kotlinx.atomicfu.atomic
22
import net.ccbluex.liquidbounce.config.types.group.Mode
23
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
24
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
25
import net.ccbluex.liquidbounce.event.events.DrawOutlinesEvent
26
import net.ccbluex.liquidbounce.event.events.GameTickEvent
27
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
28
import net.ccbluex.liquidbounce.event.handler
29
import net.ccbluex.liquidbounce.features.module.ClientModule
30
import net.ccbluex.liquidbounce.features.module.ModuleCategories
31
import net.ccbluex.liquidbounce.features.module.modules.player.cheststealer.ModuleChestStealer
32
import net.ccbluex.liquidbounce.features.module.modules.player.cheststealer.features.FeatureChestAura
33
import net.ccbluex.liquidbounce.render.CachedMeshStorage
34
import net.ccbluex.liquidbounce.render.ClientRenderPipelines
35
import net.ccbluex.liquidbounce.render.addShapeFaces
36
import net.ccbluex.liquidbounce.render.addShapeOutlines
37
import net.ccbluex.liquidbounce.render.buildMesh
38
import net.ccbluex.liquidbounce.render.drawBox
39
import net.ccbluex.liquidbounce.render.drawGenericBlockESP
40
import net.ccbluex.liquidbounce.render.drawLine
41
import net.ccbluex.liquidbounce.render.drawLines
42
import net.ccbluex.liquidbounce.render.engine.type.Color4b
43
import net.ccbluex.liquidbounce.render.engine.type.Vec3f
44
import net.ccbluex.liquidbounce.render.getDynamicTransformsUniform
45
import net.ccbluex.liquidbounce.render.renderEnvironment
46
import net.ccbluex.liquidbounce.render.translate
47
import net.ccbluex.liquidbounce.render.utils.DistanceFadeUniformValueGroup
48
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
49
import net.ccbluex.liquidbounce.render.withPush
50
import net.ccbluex.liquidbounce.utils.block.AbstractBlockLocationTracker
51
import net.ccbluex.liquidbounce.utils.block.ChunkScanner
52
import net.ccbluex.liquidbounce.utils.entity.cameraDistanceSq
53
import net.ccbluex.liquidbounce.utils.entity.interpolateCurrentPosition
54
import net.ccbluex.liquidbounce.utils.math.PositionedVoxelShape
55
import net.ccbluex.liquidbounce.utils.math.center
56
import net.ccbluex.liquidbounce.utils.math.mergeAdjacentVoxelShapes
57
import net.ccbluex.liquidbounce.utils.math.sq
58
import net.ccbluex.liquidbounce.utils.math.toVec3f
59
import net.minecraft.core.BlockPos
60
import net.minecraft.world.entity.Entity
61
import net.minecraft.world.entity.animal.equine.AbstractChestedHorse
62
import net.minecraft.world.entity.vehicle.boat.ChestBoat
63
import net.minecraft.world.entity.vehicle.boat.ChestRaft
64
import net.minecraft.world.entity.vehicle.minecart.AbstractMinecartContainer
65
import net.minecraft.world.entity.vehicle.minecart.MinecartHopper
66
import net.minecraft.world.level.block.RenderShape
67
import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity
68
import net.minecraft.world.level.block.entity.BarrelBlockEntity
69
import net.minecraft.world.level.block.entity.BlockEntity
70
import net.minecraft.world.level.block.entity.BrewingStandBlockEntity
71
import net.minecraft.world.level.block.entity.ChestBlockEntity
72
import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity
73
import net.minecraft.world.level.block.entity.CrafterBlockEntity
74
import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity
75
import net.minecraft.world.level.block.entity.DispenserBlockEntity
76
import net.minecraft.world.level.block.entity.EnderChestBlockEntity
77
import net.minecraft.world.level.block.entity.HopperBlockEntity
78
import net.minecraft.world.level.block.entity.ShelfBlockEntity
79
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity
80
import net.minecraft.world.level.block.state.BlockState
81
import net.minecraft.world.phys.AABB
82
import net.minecraft.world.phys.shapes.VoxelShape
83
import java.awt.Color
84
85
/**
86
 * StorageESP module
87
 *
88
 * Allows you to see chests, dispensers, etc. through walls.
89
 */
90
91
object ModuleStorageESP : ClientModule("StorageESP", ModuleCategories.RENDER, aliases = listOf("ChestESP")) {
92
93
    private val modes = choices("Mode", GlowMode, arrayOf(BoxMode, GlowMode))
94
95
    sealed class ChestType(name: String, defaultColor: Color4b) : ToggleableValueGroup(this, name, enabled = true) {
96
        val color by color("Color", defaultColor)
97
        val tracers by boolean("Tracers", false)
98
99
        @JvmOverloads
100
        fun shouldRender(pos: BlockPos, ignoreDistance: Boolean = false): Boolean =
101
            this.running
102
                && pos !in FeatureChestAura.interactedBlocksSet
103
                && (ignoreDistance || pos.cameraDistanceSq() < distanceFade.farEnd.sq())
104
105
        @JvmOverloads
106
        fun shouldRender(entity: Entity, ignoreDistance: Boolean = false): Boolean =
107
            this.running
108
                && (ignoreDistance || entity.position().cameraDistanceSq() < distanceFade.farEnd.sq())
109
110
        object Chest : ChestType("Chest", Color4b(0, 100, 255))
111
        object Barrel : ChestType("Barrel", Color4b(0xf6, 0x82, 0x1f))
112
        object EnderChest : ChestType("EnderChest", Color4b(Color.MAGENTA))
113
        object Furnace : ChestType("Furnace", Color4b(79, 79, 79))
114
        object BrewingStand : ChestType("BrewingStand", Color4b(139, 69, 19))
115
        object Dispenser : ChestType("Dispenser", Color4b(Color.LIGHT_GRAY))
116
        object Hopper : ChestType("Hopper", Color4b(Color.GRAY))
117
        object ShulkerBox : ChestType("ShulkerBox", Color4b(Color(0x6e, 0x4d, 0x6e).brighter()))
118
        object Pot : ChestType("Pot", Color4b(209, 134, 0))
119
        object Bookshelf : ChestType("Bookshelf", Color4b(139, 90, 43))
120
        object Shelf : ChestType("Shelf", Color4b(160, 82, 45))
121
    }
122
123
    private val allTypes = arrayOf(
124
        ChestType.Chest,
125
        ChestType.Barrel,
126
        ChestType.EnderChest,
127
        ChestType.Furnace,
128
        ChestType.BrewingStand,
129
        ChestType.Dispenser,
130
        ChestType.Hopper,
131
        ChestType.ShulkerBox,
132
        ChestType.Pot,
133
        ChestType.Bookshelf,
134
        ChestType.Shelf,
135
    )
136
137
    init {
138
        allTypes.forEach { tree(it) }
139
    }
140
141
    private val requiresChestStealer by boolean("RequiresChestStealer", false)
142
    private val mergeAdjacent by boolean("MergeAdjacent", false).onChanged {
143
        markDirtyForModes()
144
    }
145
146
    private val distanceFade = tree(DistanceFadeUniformValueGroup())
147
148
    override fun onEnabled() {
149
        ChunkScanner.subscribe(StorageScanner)
150
    }
151
152
    override fun onDisabled() {
153
        ChunkScanner.unsubscribe(StorageScanner)
154
    }
155
156
    private object BoxMode : Mode("Box") {
157
        override val parent: ModeValueGroup<Mode>
158
            get() = modes
159
160
        private val dirtyFlag = atomic(true)
161
162
        private val blockFacesRenderState = CachedMeshStorage("${ModuleStorageESP.name} $name BlockFaces")
163
        private val blockOutlinesRenderState = CachedMeshStorage("${ModuleStorageESP.name} $name BlockOutlines")
164
165
        fun markDirty() {
166
            if (this.running) {
167
                dirtyFlag.value = true
168
            }
169
        }
170
171
        override fun enable() {
172
            dirtyFlag.value = true
173
            super.enable()
174
        }
175
176
        private val outline by boolean("Outline", true)
177
178
        private val entityBoxes = mutableListOf<EntityBox>()
179
180
        override fun disable() {
181
            blockFacesRenderState.clearStates()
182
            blockFacesRenderState.clearBuffers()
183
            blockOutlinesRenderState.clearStates()
184
            blockOutlinesRenderState.clearBuffers()
185
            entityBoxes.clear()
186
            super.disable()
187
        }
188
189
        @Suppress("unused")
190
        private val renderHandler = handler<WorldRenderEvent> { event ->
191
            if (outline) {
192
                mc.gameRenderer.mainRenderTarget().drawGenericBlockESP(
193
                    renderState = blockOutlinesRenderState,
194
                    pipeline = ClientRenderPipelines.relativeLines(useColor = true),
195
                    distanceFade = distanceFade,
196
                ) {
197
                    getDynamicTransformsUniform(
198
                        modelView = event.poseStack.last().pose(),
199
                    )
200
                }
201
            }
202
203
            mc.gameRenderer.mainRenderTarget().drawGenericBlockESP(
204
                renderState = blockFacesRenderState,
205
                pipeline = ClientRenderPipelines.relativeQuads(useColor = true),
206
                distanceFade = distanceFade,
207
            ) {
208
                getDynamicTransformsUniform(
209
                    modelView = event.poseStack.last().pose(),
210
                )
211
            }
212
213
            if (entityBoxes.isEmpty()) return@handler
214
215
            val matrixStack = event.poseStack
216
217
            event.renderEnvironment {
218
                for ((entity, box, color) in entityBoxes) {
219
                    val baseColor = color.with(a = 50)
220
                    val outlineColor = if (outline) color.with(a = 100) else null
221
222
                    val pos = entity.interpolateCurrentPosition(event.partialTicks)
223
                    withPositionRelativeToCamera(pos) {
224
                        drawBox(box, baseColor, outlineColor)
225
                    }
226
                }
227
            }
228
        }
229
230
        @JvmRecord
231
        private data class EntityBox(val entity: Entity, val box: AABB, val color: Color4b)
232
233
        @Suppress("unused")
234
        private val tickHandler = handler<GameTickEvent> {
235
            val level = mc.level ?: return@handler
236
237
            entityBoxes.clear()
238
239
            for (entity in level.entitiesForRendering()) {
240
                val type = entity.categorize()?.takeIf {
241
                    !it.color.isTransparent && it.shouldRender(entity)
242
                } ?: continue
243
244
                val dimensions = entity.getDimensions(entity.pose)
245
                val d = dimensions.width.toDouble() / 2.0
246
                val box = AABB(-d, 0.0, -d, d, dimensions.height.toDouble(), d).inflate(0.05)
247
248
                entityBoxes.add(EntityBox(entity, box, type.color))
249
            }
250
251
252
            if (StorageScanner.isEmpty()) {
253
                blockFacesRenderState.clearStates()
254
                blockOutlinesRenderState.clearStates()
255
                return@handler
256
            }
257
258
            if (!dirtyFlag.compareAndSet(expect = true, update = false)) {
259
                return@handler
260
            }
261
262
            val mergedShapes = collectTrackedBlockShapes()
263
264
            blockFacesRenderState.buildMesh(
265
                pipeline = ClientRenderPipelines.relativeQuads(useColor = true),
266
                origin = player.blockPosition(),
267
            ) { pose, origin ->
268
                for (mergedShape in mergedShapes) {
269
                    pose.withPush {
270
                        translate(mergedShape.blockPos, origin)
271
                        addShapeFaces(last().pose(), mergedShape.shape, mergedShape.key.color.alpha(50))
272
                    }
273
                }
274
            }
275
276
            if (outline) {
277
                blockOutlinesRenderState.buildMesh(
278
                    pipeline = ClientRenderPipelines.relativeLines(useColor = true),
279
                    origin = player.blockPosition(),
280
                ) { pose, origin ->
281
                    for (mergedShape in mergedShapes) {
282
                        pose.withPush {
283
                            translate(mergedShape.blockPos, origin)
284
                            addShapeOutlines(last().pose(), mergedShape.shape, mergedShape.key.color.alpha(100))
285
                        }
286
                    }
287
                }
288
            }
289
        }
290
291
    }
292
293
    object GlowMode : Mode("Glow") {
294
        private val dirtyFlag = atomic(true)
295
296
        private val renderState = CachedMeshStorage("${ModuleStorageESP.name} $name")
297
298
        internal fun markDirty() {
299
            if (this.running) {
300
                dirtyFlag.value = true
301
            }
302
        }
303
304
        override fun enable() {
305
            dirtyFlag.value = true
306
            super.enable()
307
        }
308
309
        override fun disable() {
310
            renderState.clearStates()
311
            renderState.clearBuffers()
312
            super.disable()
313
        }
314
315
        override val parent: ModeValueGroup<Mode>
316
            get() = modes
317
318
        @Suppress("unused")
319
        private val glowRenderHandler = handler<DrawOutlinesEvent> { event ->
320
            val dirty = event.renderTarget.drawGenericBlockESP(
321
                renderState = renderState,
322
                pipeline = ClientRenderPipelines.outlineQuads(useColor = true),
323
                distanceFade = distanceFade,
324
            )
325
326
            if (dirty) {
327
                event.markDirty()
328
            }
329
        }
330
331
        @Suppress("unused")
332
        private val tickHandler = handler<GameTickEvent> {
333
            if (StorageScanner.isEmpty()) {
334
                renderState.clearStates()
335
                return@handler
336
            }
337
338
            if (!dirtyFlag.compareAndSet(expect = true, update = false)) {
339
                return@handler
340
            }
341
342
            renderState.buildMesh(
343
                pipeline = ClientRenderPipelines.outlineQuads(useColor = true),
344
                origin = player.blockPosition(),
345
            ) { pose, origin ->
346
                // non-model blocks are already processed by WorldRenderer where we injected code which renders
347
                // their outline
348
                for (mergedShape in collectTrackedBlockShapes { it.renderShape != RenderShape.MODEL }) {
349
                    pose.withPush {
350
                        translate(mergedShape.blockPos, origin)
351
                        addShapeFaces(last().pose(), mergedShape.shape, mergedShape.key.color)
352
                    }
353
                }
354
            }
355
        }
356
    }
357
358
    @Suppress("unused")
359
    private val renderHandler = handler<WorldRenderEvent> { event ->
360
        val types = allTypes.filter { it.tracers && !it.color.isTransparent }
361
        if (types.isEmpty()) return@handler
362
363
        event.renderEnvironment {
364
            val eyeVector = Vec3f.eyeVector(camera)
365
366
            if (!StorageScanner.isEmpty()) {
367
                for (type in types) {
368
                    for (blockPos in StorageScanner.iterate(type)) {
369
                        if (!type.shouldRender(blockPos)) continue
370
                        val pos = blockPos.center.subtract(camera.position()).toVec3f()
371
372
                        drawLine(eyeVector, pos, type.color.argb)
373
                    }
374
                }
375
            }
376
377
            for (entity in mc.level?.entitiesForRendering() ?: return@handler) {
378
                val category = entity.categorize() ?: continue
379
                if (!category.shouldRender(entity) || !category.tracers) continue
380
381
                val pos = entity.interpolateCurrentPosition(event.partialTicks).subtract(camera.position()).toVec3f()
382
                val topPos = pos.add(0f, entity.bbHeight, 0f)
383
384
                drawLines(category.color.argb, eyeVector, pos, pos, topPos)
385
            }
386
        }
387
    }
388
389
    @JvmStatic
390
    fun Entity?.categorize(): ChestType? {
391
        return when (this) {
392
            // This includes any storage type minecart entity including ChestMinecartEntity
393
            is MinecartHopper -> ChestType.Hopper
394
            is AbstractMinecartContainer -> ChestType.Chest
395
            is ChestBoat -> ChestType.Chest
396
            is ChestRaft -> ChestType.Chest
397
            is AbstractChestedHorse -> ChestType.Chest.takeIf { hasChest() }
398
            else -> null
399
        }
400
    }
401
402
    @JvmStatic
403
    fun BlockEntity?.categorize(): ChestType? {
404
        return when (this) {
405
            is ChestBlockEntity -> ChestType.Chest
406
            is BarrelBlockEntity -> ChestType.Barrel
407
            is EnderChestBlockEntity -> ChestType.EnderChest
408
            is AbstractFurnaceBlockEntity -> ChestType.Furnace
409
            is BrewingStandBlockEntity -> ChestType.BrewingStand
410
            is DispenserBlockEntity -> ChestType.Dispenser
411
            is CrafterBlockEntity -> ChestType.Dispenser
412
            is HopperBlockEntity -> ChestType.Hopper
413
            is ShulkerBoxBlockEntity -> ChestType.ShulkerBox
414
            is DecoratedPotBlockEntity -> ChestType.Pot
415
            is ChiseledBookShelfBlockEntity -> ChestType.Bookshelf
416
            is ShelfBlockEntity -> ChestType.Shelf
417
            else -> null
418
        }
419
    }
420
421
    private inline fun forEachTrackedBlockShapes(
422
        skipWhen: (BlockState) -> Boolean = { false },
423
        block: (blockPos: BlockPos, type: ChestType, outlineShape: VoxelShape) -> Unit,
424
    ) {
425
        for ((blockPos, type) in StorageScanner.iterate()) {
426
            if (type.color.isTransparent || !type.shouldRender(blockPos, ignoreDistance = true)) continue
427
428
            val blockState = world.getBlockState(blockPos)
429
430
            if (blockState.isAir || skipWhen(blockState)) continue
431
432
            val outlineShape = blockState.getShape(world, blockPos)
433
434
            block(blockPos, type, outlineShape)
435
        }
436
    }
437
438
    private inline fun collectTrackedBlockShapes(
439
        skipWhen: (BlockState) -> Boolean = { false },
440
    ): List<PositionedVoxelShape<ChestType>> {
441
        val shapes = buildList {
442
            forEachTrackedBlockShapes(skipWhen) { blockPos, type, outlineShape ->
443
                add(
444
                    PositionedVoxelShape(
445
                        blockPos = blockPos.asLong(),
446
                        key = type,
447
                        shape = outlineShape,
448
                    )
449
                )
450
            }
451
        }
452
453
        return if (mergeAdjacent) shapes.mergeAdjacentVoxelShapes() else shapes
454
    }
455
456
    private fun markDirtyForModes() {
457
        GlowMode.markDirty()
458
        BoxMode.markDirty()
459
    }
460
461
    private object StorageScanner : AbstractBlockLocationTracker.State2BlockPos<ChestType>() {
462
        override fun getStateFor(pos: BlockPos, state: BlockState): ChestType? {
463
            if (!state.hasBlockEntity()) return null
464
465
            val chunk = mc.level?.getChunk(pos) ?: return null
466
            return chunk.getBlockEntity(pos)?.categorize()
467
        }
468
469
        override fun onUpdated() {
470
            markDirtyForModes()
471
        }
472
    }
473
474
    override val running: Boolean
475
        get() {
476
            if (requiresChestStealer && !ModuleChestStealer.running) {
477
                return false
478
            }
479
480
            return super.running
481
        }
482
483
    fun showTracers() : Boolean {
484
        return this.running && allTypes.any { it.tracers }
485
    }
486
}
487