ItemESP module

ItemESP: Minecraft 26.3 cheat module, full source for every implementation (3 clients: MelaHack (ThunderHack fork), OfflineClient, 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/ItemESP.javaJava · 186 lines · 10.1 KB

Highlights items on the ground.

SettingsShadowShadowColorTextColorModeRadiusUseHudColorColorOffsetCircleColorCirclePoints
ItemESP.javaJava · Minecraft 26.2 · 186 lines · 10.1 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import com.mojang.blaze3d.vertex.BufferBuilder;
4
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
5
import com.mojang.blaze3d.vertex.PoseStack;
6
import thunder.hack.utility.render.Tesselator;
7
import com.mojang.blaze3d.vertex.VertexFormat;
8
9
import thunder.hack.utility.render.compat.RenderSystem;
10
import thunder.hack.utility.render.ShaderProgramKeys;
11
import net.minecraft.client.gui.GuiGraphicsExtractor;
12
import thunder.hack.utility.render.BufferRenderer;
13
import net.minecraft.world.entity.Entity;
14
import net.minecraft.world.entity.item.ItemEntity;
15
import net.minecraft.world.phys.AABB;
16
import net.minecraft.world.phys.Vec3;
17
import org.jetbrains.annotations.NotNull;
18
import org.joml.Matrix4f;
19
import org.joml.Vector4d;
20
import thunder.hack.gui.font.FontRenderers;
21
import thunder.hack.features.modules.Module;
22
import thunder.hack.features.modules.client.HudEditor;
23
import thunder.hack.setting.Setting;
24
import thunder.hack.setting.impl.ColorSetting;
25
import thunder.hack.utility.render.Render2DEngine;
26
import thunder.hack.utility.render.Render3DEngine;
27
28
import java.awt.*;
29
30
public class ItemESP extends Module {
31
    public ItemESP() {
32
        super("ItemESP", Category.RENDER);
33
    }
34
35
    private final Setting<Boolean> shadow = new Setting<>("Shadow", true);
36
    private final Setting<ColorSetting> scolor = new Setting<>("ShadowColor", new ColorSetting(new Color(0x000000).getRGB()));
37
    private final Setting<ColorSetting> tcolor = new Setting<>("TextColor", new ColorSetting(new Color(-1).getRGB()));
38
39
    private final Setting<ESPMode> espMode = new Setting<>("Mode", ESPMode.Rect);
40
41
    private final Setting<Float> radius = new Setting<>("Radius", 1f, 0.1f, 5f, v -> espMode.getValue() == ESPMode.Circle);
42
    private final Setting<Boolean> useHudColor = new Setting<>("UseHudColor", true, v -> espMode.getValue() == ESPMode.Circle);
43
    private final Setting<Integer> cOffset = new Setting<>("ColorOffset", 2, 1, 50, v -> espMode.getValue() == ESPMode.Circle && useHudColor.getValue());
44
    private final Setting<ColorSetting> circleColor = new Setting<>("CircleColor", new ColorSetting(new Color(-1).getRGB()), v -> espMode.getValue() == ESPMode.Circle && !useHudColor.getValue());
45
    private final Setting<Integer> cPoints = new Setting<>("CirclePoints", 12, 3, 32, v -> espMode.getValue() == ESPMode.Circle);
46
47
    public void onRender2D(GuiGraphicsExtractor context) {
48
        for (Entity ent : mc.level.entitiesForRendering()) {
49
            if (!(ent instanceof ItemEntity)) continue;
50
            Vec3[] vectors = getPoints(ent);
51
52
            Vector4d position = null;
53
            for (Vec3 vector : vectors) {
54
                vector = Render3DEngine.worldSpaceToScreenSpace(new Vec3(vector.x, vector.y, vector.z));
55
                if (vector.z > 0 && vector.z < 1) {
56
                    if (position == null)
57
                        position = new Vector4d(vector.x, vector.y, vector.z, 0);
58
                    position.x = Math.min(vector.x, position.x);
59
                    position.y = Math.min(vector.y, position.y);
60
                    position.z = Math.max(vector.x, position.z);
61
                    position.w = Math.max(vector.y, position.w);
62
                }
63
            }
64
65
            if (position != null) {
66
                float posX = (float) position.x;
67
                float posY = (float) position.y;
68
                float endPosX = (float) position.z;
69
70
                float diff = (endPosX - posX) / 2f;
71
                float textWidth = (FontRenderers.source_han_sans_normal.getStringWidth(ent.getDisplayName().getString()) * 1);
72
                float tagX = (posX + diff - textWidth / 2f) * 1;
73
74
                if (shadow.getValue())
75
                    Render2DEngine.drawBlurredShadow(context.pose(), tagX - 2, posY - 13, FontRenderers.source_han_sans_normal.getStringWidth(ent.getDisplayName().getString()) + 4, 10, 14, scolor.getValue().getColorObject());
76
77
                FontRenderers.source_han_sans_normal.drawString(context.pose(), ent.getDisplayName().getString(), tagX, (float) posY - 10, tcolor.getValue().getColor());
78
            }
79
        }
80
81
        if (espMode.getValue() == ESPMode.Rect ) {
82
            boolean any = false;
83
84
            // TODO SHIT
85
            for (Entity ent : mc.level.entitiesForRendering()) {
86
                if (!(ent instanceof ItemEntity)) continue;
87
                Vec3[] vectors = getPoints(ent);
88
89
                Vector4d position = null;
90
                for (Vec3 vector : vectors) {
91
                    vector = Render3DEngine.worldSpaceToScreenSpace(new Vec3(vector.x, vector.y, vector.z));
92
                    if (vector.z > 0 && vector.z < 1) {
93
                        if (position == null)
94
                            position = new Vector4d(vector.x, vector.y, vector.z, 0);
95
                        position.x = Math.min(vector.x, position.x);
96
                        position.y = Math.min(vector.y, position.y);
97
                        position.z = Math.max(vector.x, position.z);
98
                        position.w = Math.max(vector.y, position.w);
99
                    }
100
                }
101
102
                if (position != null)
103
                    any = true;
104
            }
105
106
            if (!any)
107
                return;
108
109
            Matrix4f matrix = thunder.hack.utility.render.GuiMatrix.positionMatrix(context.pose());
110
            Render2DEngine.setupRender();
111
            RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
112
113
            BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
114
115
            for (Entity ent : mc.level.entitiesForRendering()) {
116
                if (!(ent instanceof ItemEntity)) continue;
117
                Vec3[] vectors = getPoints(ent);
118
119
                Vector4d position = null;
120
                for (Vec3 vector : vectors) {
121
                    vector = Render3DEngine.worldSpaceToScreenSpace(new Vec3(vector.x, vector.y, vector.z));
122
                    if (vector.z > 0 && vector.z < 1) {
123
                        if (position == null)
124
                            position = new Vector4d(vector.x, vector.y, vector.z, 0);
125
                        position.x = Math.min(vector.x, position.x);
126
                        position.y = Math.min(vector.y, position.y);
127
                        position.z = Math.max(vector.x, position.z);
128
                        position.w = Math.max(vector.y, position.w);
129
                    }
130
                }
131
132
                if (position != null) {
133
                    float posX = (float) position.x;
134
                    float posY = (float) position.y;
135
                    float endPosX = (float) position.z;
136
                    float endPosY = (float) position.w;
137
138
                    drawRect(bufferBuilder, matrix, posX, posY, endPosX, endPosY);
139
                }
140
            }
141
            Render2DEngine.endBuilding(bufferBuilder);
142
            Render2DEngine.endRender();
143
        }
144
    }
145
146
    public void onRender3D(PoseStack stack) {
147
        if (espMode.getValue() == ESPMode.Circle)
148
            for (Entity ent : mc.level.entitiesForRendering())
149
                if (ent instanceof ItemEntity)
150
                    Render3DEngine.drawCircle3D(stack, ent, radius.getValue(), circleColor.getValue().getColor(), cPoints.getValue(), useHudColor.getValue(), cOffset.getValue());
151
    }
152
153
    private void drawRect(BufferBuilder bufferBuilder, Matrix4f stack, float posX, float posY, float endPosX, float endPosY) {
154
        Color black = Color.BLACK;
155
        Render2DEngine.setRectPoints(bufferBuilder, stack, posX - 1F, posY, (posX + 0.5f), endPosY + 0.5f, black, black, black, black);
156
        Render2DEngine.setRectPoints(bufferBuilder, stack, posX - 1F, (posY - 0.5f), endPosX + 0.5f, posY + 1f, black, black, black, black);
157
        Render2DEngine.setRectPoints(bufferBuilder, stack, endPosX - 1f, posY, endPosX + 0.5f, endPosY + 0.5f, black, black, black, black);
158
        Render2DEngine.setRectPoints(bufferBuilder, stack, posX - 1, endPosY - 1f, endPosX + 0.5f, endPosY + 0.5f, black, black, black, black);
159
        Render2DEngine.setRectPoints(bufferBuilder, stack, posX - 0.5f, posY, posX, endPosY, HudEditor.getColor(270), HudEditor.getColor(0), HudEditor.getColor(0), HudEditor.getColor(270));
160
        Render2DEngine.setRectPoints(bufferBuilder, stack, posX, endPosY - 0.5f, endPosX, endPosY, HudEditor.getColor(0), HudEditor.getColor(180), HudEditor.getColor(180), HudEditor.getColor(0));
161
        Render2DEngine.setRectPoints(bufferBuilder, stack, posX - 0.5f, posY, endPosX, (posY + 0.5f), HudEditor.getColor(180), HudEditor.getColor(90), HudEditor.getColor(90), HudEditor.getColor(180));
162
        Render2DEngine.setRectPoints(bufferBuilder, stack, endPosX - 0.5f, posY, endPosX, endPosY, HudEditor.getColor(90), HudEditor.getColor(270), HudEditor.getColor(270), HudEditor.getColor(90));
163
    }
164
165
    @NotNull
166
    private static Vec3[] getPoints(Entity ent) {
167
        AABB axisAlignedBB = getBox(ent);
168
        Vec3[] vectors = new Vec3[]{new Vec3(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.minZ), new Vec3(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.minZ), new Vec3(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.minZ), new Vec3(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.minZ), new Vec3(axisAlignedBB.minX, axisAlignedBB.minY, axisAlignedBB.maxZ), new Vec3(axisAlignedBB.minX, axisAlignedBB.maxY, axisAlignedBB.maxZ), new Vec3(axisAlignedBB.maxX, axisAlignedBB.minY, axisAlignedBB.maxZ), new Vec3(axisAlignedBB.maxX, axisAlignedBB.maxY, axisAlignedBB.maxZ)};
169
        return vectors;
170
    }
171
172
    @NotNull
173
    private static AABB getBox(Entity ent) {
174
        double x = ent.xo + (ent.getX() - ent.xo) * Render3DEngine.getTickDelta();
175
        double y = ent.yo + (ent.getY() - ent.yo) * Render3DEngine.getTickDelta();
176
        double z = ent.zo + (ent.getZ() - ent.zo) * Render3DEngine.getTickDelta();
177
        AABB axisAlignedBB2 = ent.getBoundingBox();
178
        AABB axisAlignedBB = new AABB(axisAlignedBB2.minX - ent.getX() + x - 0.05, axisAlignedBB2.minY - ent.getY() + y, axisAlignedBB2.minZ - ent.getZ() + z - 0.05, axisAlignedBB2.maxX - ent.getX() + x + 0.05, axisAlignedBB2.maxY - ent.getY() + y + 0.15, axisAlignedBB2.maxZ - ent.getZ() + z + 0.05);
179
        return axisAlignedBB;
180
    }
181
182
    private enum ESPMode {
183
        Rect, Circle, None
184
    }
185
}
186
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/ItemEsp.javaJava · 120 lines · 4.8 KB

See dropped items through walls.

SettingsBoxesBox sizeTracersTracer colourSteady viewLimit rangeRangeEverythingItems
ItemEsp.javaJava · Minecraft 26.2 · 120 lines · 4.8 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.Render3DEvent;
5
import com.jellypudding.offlineclient.module.Category;
6
import com.jellypudding.offlineclient.module.Module;
7
import com.jellypudding.offlineclient.render.BoxStyle;
8
import com.jellypudding.offlineclient.render.DrawBatch;
9
import com.jellypudding.offlineclient.setting.BoolSetting;
10
import com.jellypudding.offlineclient.setting.ColorSetting;
11
import com.jellypudding.offlineclient.setting.EnumSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import com.jellypudding.offlineclient.setting.RegistryListSetting;
14
import com.jellypudding.offlineclient.util.EntityUtil;
15
import net.minecraft.core.registries.BuiltInRegistries;
16
import net.minecraft.world.entity.Entity;
17
import net.minecraft.world.entity.item.ItemEntity;
18
import net.minecraft.world.item.Item;
19
import net.minecraft.world.item.Items;
20
import net.minecraft.world.phys.AABB;
21
22
import java.util.List;
23
24
public final class ItemEsp extends Module {
25
26
    public enum Size { ACCURATE, FANCY }
27
28
    // How much a fancy box grows and how far it lifts off the ground.
29
    private static final double FANCY_GROW = 0.1;
30
    private static final double FANCY_LIFT = 0.05;
31
32
    private final BoolSetting boxes = new BoolSetting("Boxes",
33
        "Draw a box around every item.", true);
34
    private final BoxStyle style = new BoxStyle(BoxStyle.Shape.LINES, 48).under(boxes);
35
    private final EnumSetting<Size> size = new EnumSetting<>("Box size",
36
        "How big the box around an item is.", Size.FANCY)
37
        .describe(Size.ACCURATE, "The hitbox of the item itself.")
38
        .describe(Size.FANCY, "A little larger and lifted off the floor so it is easier to see.")
39
        .under(boxes);
40
    private final BoolSetting tracers = new BoolSetting("Tracers",
41
        "Draw a line to every item.", false);
42
    private final ColorSetting tracerColor = new ColorSetting("Tracer colour",
43
        "Colour of the lines.", 48, false).under(tracers);
44
    private final BoolSetting steadyView = new BoolSetting("Steady view",
45
        "Stops the view bobbing whilst the tracers are on so the lines do not wobble.", true)
46
        .under(tracers);
47
    private final BoolSetting limitRange = new BoolSetting("Limit range",
48
        "Only shows items within a set distance.", false);
49
    private final NumberSetting range = new NumberSetting("Range",
50
        "Furthest an item can be and still show.", 64, 8, 256, 8, " blocks").min(1)
51
        .under(limitRange);
52
    private final BoolSetting everything = new BoolSetting("Everything",
53
        "Show every dropped item.", true);
54
    private final RegistryListSetting<Item> items = new RegistryListSetting<>("Items",
55
        "The items to show.", BuiltInRegistries.ITEM,
56
        List.of(Items.DIAMOND, Items.NETHERITE_INGOT, Items.ENCHANTED_GOLDEN_APPLE,
57
            Items.ELYTRA, Items.TOTEM_OF_UNDYING, Items.SHULKER_BOX))
58
        .unless(everything);
59
60
    private int count;
61
62
    public ItemEsp() {
63
        super("ItemESP", "See dropped items through walls.", Category.RENDER);
64
        addSettings(boxes);
65
        addSettings(style.settings());
66
        addSettings(size, tracers, tracerColor, steadyView, limitRange, range, everything, items);
67
        searchTags("item tracers", "drops");
68
    }
69
70
    @Override
71
    public String getSuffix() {
72
        return count == 0 ? null : String.valueOf(count);
73
    }
74
75
    @Override
76
    protected void onDisable() {
77
        count = 0;
78
    }
79
80
    // Read by GameRendererMixin.
81
    public boolean holdsViewStill() {
82
        return isEnabled() && tracers.isOn() && steadyView.isOn();
83
    }
84
85
    @Subscribe
86
    private void onRender3D(Render3DEvent event) {
87
        if (!inGame()) {
88
            return;
89
        }
90
        DrawBatch batch = event.getBatch();
91
        boolean filter = !everything.isOn();
92
        int found = 0;
93
        for (Entity entity : mc.level.entitiesForRendering()) {
94
            if (!(entity instanceof ItemEntity item)) {
95
                continue;
96
            }
97
            if (filter && !items.contains(item.getItem().getItem())) {
98
                continue;
99
            }
100
            if (limitRange.isOn() && mc.player.distanceTo(item) > range.getValue()) {
101
                continue;
102
            }
103
            found++;
104
            AABB box = shown(EntityUtil.lerpedBox(item, event.getPartialTicks()));
105
            if (boxes.isOn()) {
106
                style.draw(batch, box, true);
107
            }
108
            if (tracers.isOn()) {
109
                batch.tracer(box.getCenter(), tracerColor.getColor(), true);
110
            }
111
        }
112
        count = found;
113
    }
114
115
    // An item hitbox is tiny. The fancy box is grown and lifted clear of the floor.
116
    private AABB shown(AABB box) {
117
        return size.is(Size.ACCURATE) ? box : box.inflate(FANCY_GROW).move(0, FANCY_LIFT, 0);
118
    }
119
}
120
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleItemESP.ktKotlin · 271 lines · 9.8 KB
SettingsFilterItemsMaximumDistanceTracersRegularArrowsSpectralArrowsArrowsWithEffectsShowTridentsMergeIntersectingScaleYOffsetBackgroundAlpha
ModuleItemESP.ktKotlin · Minecraft 26.2 · 271 lines · 9.8 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 net.ccbluex.fastutil.mapToArray
22
import net.ccbluex.liquidbounce.config.ConfigSystem
23
import net.ccbluex.liquidbounce.config.types.group.Mode
24
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
25
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
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.render.GenericRainbowColorMode
32
import net.ccbluex.liquidbounce.render.GenericStaticColorMode
33
import net.ccbluex.liquidbounce.render.drawBox
34
import net.ccbluex.liquidbounce.render.drawLine
35
import net.ccbluex.liquidbounce.render.engine.type.Color4b
36
import net.ccbluex.liquidbounce.render.engine.type.Vec3f
37
import net.ccbluex.liquidbounce.render.renderEnvironment
38
import net.ccbluex.liquidbounce.utils.render.drawLegacy2DMarker
39
import net.ccbluex.liquidbounce.render.withPositionRelativeToCamera
40
import net.ccbluex.liquidbounce.utils.collection.Filter
41
import net.ccbluex.liquidbounce.utils.collection.itemSortedSetOf
42
import net.ccbluex.liquidbounce.utils.entity.cameraDistanceSq
43
import net.ccbluex.liquidbounce.utils.entity.interpolateCurrentPosition
44
import net.ccbluex.liquidbounce.utils.math.sq
45
import net.ccbluex.liquidbounce.utils.math.KeyedAabb
46
import net.ccbluex.liquidbounce.utils.math.mergeIntersectingAabbsSweep
47
import net.ccbluex.liquidbounce.utils.math.toVec3f
48
import net.ccbluex.liquidbounce.utils.math.worldToLocal
49
import net.minecraft.world.entity.Entity
50
import net.minecraft.world.entity.item.ItemEntity
51
import net.minecraft.world.entity.projectile.arrow.AbstractArrow.Pickup
52
import net.minecraft.world.entity.projectile.arrow.Arrow
53
import net.minecraft.world.entity.projectile.arrow.SpectralArrow
54
import net.minecraft.world.entity.projectile.arrow.ThrownTrident
55
import net.minecraft.world.phys.AABB
56
57
/**
58
 * ItemESP module
59
 *
60
 * Allows you to see dropped items through walls.
61
 */
62
63
object ModuleItemESP : ClientModule("ItemESP", ModuleCategories.RENDER) {
64
65
    override val baseKey: String
66
        get() = "${ConfigSystem.KEY_PREFIX}.module.itemEsp"
67
68
    private val filter by enumChoice("Filter", Filter.BLACKLIST)
69
    private val items by items("Items", itemSortedSetOf())
70
    private val maximumDistance by float("MaximumDistance", 128F, 1F..512F)
71
72
    val showTracers by boolean("Tracers", false)
73
74
    private object ShowArrows : ToggleableValueGroup(this, "ShowArrows", true) {
75
        val regularArrows by boolean("RegularArrows", true)
76
        val spectralArrows by boolean("SpectralArrows", true)
77
        val arrowsWithEffects by boolean("ArrowsWithEffects", true)
78
    }
79
80
    init {
81
        tree(ShowArrows)
82
    }
83
84
    private val showTridents by boolean("ShowTridents", true)
85
86
    private val modes = choices("Mode", 0) {
87
        arrayOf(
88
            GlowMode,
89
//            OutlineMode,
90
            BoxMode,
91
            Legacy2DMode,
92
        )
93
    }
94
    private val colorMode = choices("ColorMode", 0) {
95
        arrayOf(
96
            GenericStaticColorMode(it, Color4b(255, 179, 72, 255)),
97
            GenericRainbowColorMode(it)
98
        )
99
    }
100
101
    // showTracers
102
    @Suppress("unused")
103
    private val tracerRenderHandler = handler<WorldRenderEvent> { event ->
104
        // Check if the tracer option is enabled
105
        if (!showTracers) return@handler
106
107
        event.renderEnvironment {
108
            val eyeVector = Vec3f.eyeVector(camera)
109
110
            val entities = world.entitiesForRendering()
111
            for (entity in entities) {
112
                if (!shouldRender(entity)) continue
113
114
                val color = getColor()
115
116
                // Interpolating the position (motion smoothing)
117
                val pos = entity.interpolateCurrentPosition(event.partialTicks).subtract(camera.position()).toVec3f()
118
119
                drawLine(
120
                    argb = color.argb,
121
                    p1 = eyeVector,
122
                    p2 = pos,
123
                )
124
            }
125
        }
126
    }
127
128
    private object BoxMode : Mode("Box") {
129
130
        override val parent: ModeValueGroup<Mode>
131
            get() = modes
132
133
        private val box = AABB(-0.125, 0.125, -0.125, 0.125, 0.375, 0.125)
134
        private val mergeIntersecting by boolean("MergeIntersecting", false)
135
136
        private val entities = mutableListOf<Entity>()
137
138
        override fun disable() {
139
            entities.clear()
140
            super.disable()
141
        }
142
143
        @Suppress("unused")
144
        private val tickHandler = handler<GameTickEvent> {
145
            entities.clear()
146
            world.entitiesForRendering().filterTo(entities, ::shouldRender)
147
        }
148
149
        @Suppress("unused")
150
        private val renderHandler = handler<WorldRenderEvent> { event ->
151
            if (entities.isEmpty()) return@handler
152
153
            val color = getColor()
154
            val faceColor = color.with(a = 50)
155
            val outlineColor = color.with(a = 100)
156
157
            event.renderEnvironment {
158
                if (!mergeIntersecting) {
159
                    for (entity in entities) {
160
                        val pos = entity.interpolateCurrentPosition(event.partialTicks)
161
162
                        withPositionRelativeToCamera(pos) {
163
                            drawBox(box, faceColor, outlineColor)
164
                        }
165
                    }
166
                    return@renderEnvironment
167
                }
168
169
                val mergedBoxes = mergeIntersectingAabbsSweep(
170
                    entities.mapToArray { entity ->
171
                        val pos = entity.interpolateCurrentPosition(event.partialTicks)
172
                        KeyedAabb(box.move(pos), color)
173
                    }.asList()
174
                )
175
176
                for ((mergedBox, _) in mergedBoxes) {
177
                    val (origin, localBox) = mergedBox.worldToLocal()
178
                    withPositionRelativeToCamera(origin) {
179
                        drawBox(localBox, faceColor, outlineColor)
180
                    }
181
                }
182
            }
183
        }
184
    }
185
186
    private object Legacy2DMode : Mode("Legacy2D") {
187
        override val parent: ModeValueGroup<Mode>
188
            get() = modes
189
190
        private val scale by float("Scale", 0.1f, 0.02f..0.3f)
191
        private val yOffset by float("YOffset", 0f, -1f..1f)
192
        private val backgroundAlpha by int("BackgroundAlpha", 150, 0..255)
193
194
        private val entities = mutableListOf<Entity>()
195
196
        override fun disable() {
197
            entities.clear()
198
            super.disable()
199
        }
200
201
        @Suppress("unused")
202
        private val tickHandler = handler<GameTickEvent> {
203
            entities.clear()
204
            world.entitiesForRendering().filterTo(entities, ::shouldRender)
205
        }
206
207
        @Suppress("unused")
208
        private val renderHandler = handler<WorldRenderEvent> { event ->
209
            if (entities.isEmpty()) return@handler
210
211
            val color = getColor().argb
212
            val backgroundColor = Color4b.BLACK.with(a = backgroundAlpha).argb
213
214
            event.renderEnvironment {
215
                for (entity in entities) {
216
                    val pos = entity.interpolateCurrentPosition(event.partialTicks).add(0.0, yOffset.toDouble(), 0.0)
217
218
                    drawLegacy2DMarker(
219
                        pos = pos,
220
                        entityHeight = entity.boundingBox.ysize,
221
                        scale = scale,
222
                        foregroundArgb = color,
223
                        backgroundArgb = backgroundColor
224
                    )
225
                }
226
            }
227
        }
228
    }
229
230
    object GlowMode : Mode("Glow") {
231
        override val parent: ModeValueGroup<Mode>
232
            get() = modes
233
    }
234
235
    object OutlineMode : Mode("Outline") {
236
        override val parent: ModeValueGroup<Mode>
237
            get() = modes
238
    }
239
240
    fun shouldRender(entity: Entity?) : Boolean {
241
        if (entity == null) return false
242
243
        val distanceSq = entity.eyePosition.cameraDistanceSq()
244
        if (distanceSq > maximumDistance.sq()) return false
245
246
        return when (entity) {
247
            is ItemEntity -> filter(entity.item.item, items)
248
249
            is ThrownTrident -> showTridents
250
251
            // arrow checks
252
            // The server never sends the actual pickupType of arrows fired
253
            // from Infinity-enchanted bows to clients. :(
254
            // Therefore, those arrows are still rendered as collectible, even though they shouldn't be.
255
            // The same applies to tridents thrown and arrows fired by players in Creative mode.
256
257
            // However, it's not completely useless:
258
            // arrows shot by mobs such as skeletons and pillagers are not rendered.
259
            is Arrow if ShowArrows.running && entity.pickup == Pickup.ALLOWED ->
260
                if (entity.color == -1) ShowArrows.regularArrows else ShowArrows.arrowsWithEffects
261
262
            is SpectralArrow if ShowArrows.running && entity.pickup == Pickup.ALLOWED ->
263
                ShowArrows.spectralArrows
264
265
            else -> false
266
        }
267
    }
268
269
    fun getColor() = this.colorMode.activeMode.getColor(null)
270
}
271