DropESP module

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

1 implementationVISUALS

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.

CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/DropESP.javaJava · 653 lines · 31.0 KB
SettingsdropEspModedropEspPresentationModedropEspWorldSizedropEspDynamicWorldScaledropEspDynamicWorldScaleCoefficientdropEspLimitCommonDistancedropEspCommonMaxDistancedropEspFramedropEspItemIcondropEspSpecialColordropEspSpecialItems
DropESP.javaJava · Minecraft 26.2 · 653 lines · 31.0 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.visuals;
9
10
import combatant.client.render.engine.text.BuiltinFontCatalog;
11
import combatant.client.config.values.*;
12
import net.minecraft.ChatFormatting;
13
import net.minecraft.client.Minecraft;
14
import net.minecraft.client.gui.GuiGraphicsExtractor;
15
import net.minecraft.core.component.DataComponents;
16
import net.minecraft.network.chat.Component;
17
import net.minecraft.network.chat.MutableComponent;
18
import net.minecraft.core.registries.BuiltInRegistries;
19
import net.minecraft.world.entity.Entity;
20
import net.minecraft.world.entity.item.ItemEntity;
21
import net.minecraft.world.item.ItemStack;
22
import net.minecraft.world.item.Rarity;
23
import net.minecraft.world.phys.AABB;
24
import net.minecraft.world.phys.Vec3;
25
import combatant.client.config.SettingDef;
26
import combatant.client.config.values.*;
27
import combatant.client.features.gui.clickgui.settings.TextListSetting;
28
import combatant.client.features.gui.hud.HudRenderSpace;
29
import combatant.client.features.module.HudPhase;
30
import combatant.client.features.module.Module;
31
import combatant.client.features.module.ModuleCategory;
32
import combatant.client.features.module.ModuleInfo;
33
import combatant.client.features.module.WorldPhase;
34
import combatant.client.mixininterface.IEntity;
35
import combatant.client.render.engine.color.RenderColor;
36
import combatant.client.render.engine.RenderState;
37
import combatant.client.render.engine.core.ViewportContext;
38
import combatant.client.render.engine.core.CombatantWorldMatrices;
39
import combatant.client.render.engine.renderer.Renderer2D;
40
import combatant.client.render.engine.renderer.Renderer3D;
41
import combatant.client.render.engine.renderer.ui.ItemBatchRenderer;
42
import combatant.client.render.engine.text.TextRenderer;
43
import combatant.client.render.engine.text.RuntimeTextLayout;
44
import combatant.client.render.engine.text.VanillaTextRenderer;
45
import combatant.client.render.engine.text.WorldTextRenderer;
46
import combatant.client.render.engine.world.WorldBillboardRenderer;
47
import combatant.client.render.engine.world.WorldUiPresentationService;
48
import combatant.client.render.helpers.ScreenProjection;
49
import combatant.client.render.helpers.ScreenSpaceOverlay2D;
50
import combatant.client.util.item.IllegalItemUtil;
51
import combatant.client.util.item.RarityColorUtil;
52
import combatant.client.util.item.TopEnchantUtil;
53
import combatant.client.util.text.TextRenderUtil;
54
55
//todo Description
56
@ModuleInfo(id = "dropesp", displayName = "DropESP", category = ModuleCategory.VISUALS)
57
public class DropESP extends Module {
58
59
    private static final String SETTING_LIMIT_COMMON_DISTANCE = "limit_common_distance";
60
    private static final String SETTING_COMMON_MAX_DISTANCE = "common_max_distance";
61
    private static final String SETTING_SPECIAL_ITEMS_COLOR = "special_items_color";
62
    private static final String SETTING_ILLEGAL_ENCHANT_COLOR = "illegal_enchant_color";
63
    private static final String SETTING_TOP_ENCHANT_IGNORE_LIST = "top_enchant_ignore_list";
64
    private static final String SETTING_SPECIAL_ITEM_IDS = "special_item_ids";
65
    private static final String SETTING_MODE = "mode";
66
    private static final String SETTING_FRAME = "frame";
67
    private static final String SETTING_ITEM_ICON = "item_icon";
68
    private static final String SETTING_PRESENTATION_MODE = "presentation_mode";
69
    private static final String SETTING_WORLD_SIZE = "world_size";
70
    private static final String SETTING_DYNAMIC_WORLD_SCALE = "dynamic_world_scale";
71
    private static final String SETTING_DYNAMIC_WORLD_SCALE_COEFFICIENT = "dynamic_world_scale_coefficient";
72
    private static final double ITEM_BOX_EXPAND_XZ = 0.10;
73
    private static final double ITEM_BOX_EXPAND_TOP = 0.10;
74
    // Direct UNSCALED_LOGICAL dimensions. No framebuffer/gui-scale compensation.
75
    // Slightly larger than rich_src's default presentation for readability.
76
    private static final double RICH_TEXT_LOGICAL_HEIGHT = 17.0;
77
    private static final double DROP_TEXT_SCALE = 0.92;
78
    private static final double MATTE_LABEL_PAD_X = 3.6;
79
    private static final double MATTE_LABEL_PAD_Y = 1.25;
80
    private static final float MATTE_LABEL_RADIUS = 3.6f;
81
    private static final int MATTE_BACKDROP_ALPHA = 148;
82
    private static final double MATTE_ICON_SIZE = 15.0;
83
    private static final double MATTE_ICON_GAP = 3.6;
84
    private static final float MATTE_ICON_SCALE = 0.9375f;
85
    private static final WorldUiPresentationService.Policy WORLD_PRESENTATION_POLICY =
86
            new WorldUiPresentationService.Policy(0.0150, 12.0, 18.0, 32.0, 0.45, 4.00);
87
    private final Minecraft mc = Minecraft.getInstance();
88
    private final ModeValue modeValue = modeSetting("dropEspMode", SETTING_MODE, "Matte", "Vanilla", "Matte");
89
    private final EnumValue<WorldUiPresentationService.Mode> presentationMode =
90
            enumSetting("dropEspPresentationMode", SETTING_PRESENTATION_MODE,
91
                    WorldUiPresentationService.Mode.HYBRID, WorldUiPresentationService.Mode.values());
92
    private final NumberValue<Float> worldSize =
93
            visibleWhen(num("dropEspWorldSize", SETTING_WORLD_SIZE, 0.72f, 0.35f, 1.50f),
94
                    () -> presentationMode.get() != WorldUiPresentationService.Mode.SCREEN);
95
    private final BooleanValue dynamicWorldScale =
96
            visibleWhen(bool("dropEspDynamicWorldScale", SETTING_DYNAMIC_WORLD_SCALE, true),
97
                    () -> presentationMode.get() != WorldUiPresentationService.Mode.SCREEN);
98
    private final NumberValue<Float> dynamicWorldScaleCoefficient =
99
            visibleWhen(num("dropEspDynamicWorldScaleCoefficient", SETTING_DYNAMIC_WORLD_SCALE_COEFFICIENT, 0.25f, 0.0f, 1.0f),
100
                    () -> presentationMode.get() != WorldUiPresentationService.Mode.SCREEN && dynamicWorldScale.get());
101
    private final BooleanValue limitCommonDistanceValue = bool("dropEspLimitCommonDistance", SETTING_LIMIT_COMMON_DISTANCE, true);
102
    private final NumberValue<Integer> commonMaxDistanceValue =
103
            visibleWhen(num("dropEspCommonMaxDistance", SETTING_COMMON_MAX_DISTANCE, 32, 4, 256), limitCommonDistanceValue::get);
104
    private final BooleanValue frameValue =
105
            visibleWhen(bool("dropEspFrame", SETTING_FRAME, true), this::isOverlayMode);
106
    private final BooleanValue itemIconValue =
107
            visibleWhen(bool("dropEspItemIcon", SETTING_ITEM_ICON, false),
108
                    () -> isMatteMode() || presentationMode.get() != WorldUiPresentationService.Mode.SCREEN);
109
    private final RGBColorValue specialColorValue = colorNoAlpha("dropEspSpecialColor", SETTING_SPECIAL_ITEMS_COLOR, "#FFAA00");
110
    private final ItemIdSetValue topIgnore = TopEnchantUtil.ignoreValue();
111
    private final ItemIdSetValue specialItemsValue =
112
            itemList("dropEspSpecialItems", SETTING_SPECIAL_ITEM_IDS, TextListSetting.PickerMode.ITEMS);
113
114
    {
115
        setting(SettingDef.colorNoAlpha(SETTING_ILLEGAL_ENCHANT_COLOR, IllegalItemUtil.illegalColorValue()));
116
        setting(SettingDef.textList(SETTING_TOP_ENCHANT_IGNORE_LIST, topIgnore, TextListSetting.PickerMode.ENCHANTMENTS));
117
    }
118
119
    private static int compareDropRenderOrder(DropOverlayEntry a, DropOverlayEntry b) {
120
        int rarity = Integer.compare(a.sortPriority(), b.sortPriority());
121
        if (rarity != 0) return rarity;
122
        return Double.compare(b.distSq(), a.distSq());
123
    }
124
125
    private static int compareDropRenderOrder(DropVanillaEntry a, DropVanillaEntry b) {
126
        int rarity = Integer.compare(a.sortPriority(), b.sortPriority());
127
        if (rarity != 0) return rarity;
128
        return Double.compare(b.distSq(), a.distSq());
129
    }
130
131
    private static int compareDropWorldRenderOrder(DropWorldEntry a, DropWorldEntry b) {
132
        int rarity = Integer.compare(a.sortPriority(), b.sortPriority());
133
        if (rarity != 0) return rarity;
134
        return Double.compare(b.distSq(), a.distSq());
135
    }
136
137
    @Override
138
    public HudRenderSpace getHudRenderSpace() {
139
        return HudRenderSpace.UNSCALED_LOGICAL;
140
    }
141
142
    @Override
143
    public HudPhase getHudPhase() {
144
        return HudPhase.FIRST;
145
    }
146
147
    @Override
148
    public WorldPhase getWorldPhase() {
149
        return WorldPhase.END_MAIN_BILLBOARD;
150
    }
151
152
    @Override
153
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
154
        if (!isEnabled() || renderer == null || mc.level == null || mc.player == null) return;
155
        if (presentationMode.get() == WorldUiPresentationService.Mode.SCREEN) return;
156
157
        TextRenderer labelRenderer = dropLabelRenderer(TextRenderer.get());
158
        Vec3 cameraPos = presentationCameraPosition(tickDelta);
159
        boolean framesEnabled = frameValue.get();
160
        java.util.List<DropWorldEntry> entries = new java.util.ArrayList<>();
161
        java.util.List<ItemBatchRenderer.WorldItemRow> itemRows = new java.util.ArrayList<>();
162
163
        for (ItemEntity item : mc.level.getEntitiesOfClass(
164
                ItemEntity.class,
165
                mc.player.getBoundingBox().inflate(64),
166
                e -> true
167
        )) {
168
            Vec3 pos = obtainEntityLerpedPos(item, tickDelta);
169
            double distSq = pos.distanceToSqr(cameraPos);
170
            double dist = Math.sqrt(distSq);
171
            if (!passesDistanceFilter(item, dist)) continue;
172
            WorldUiPresentationService.Snapshot presentation = resolvePresentation(dist);
173
            if (presentation.worldAlpha() <= 0.001f) continue;
174
175
            ItemStack stack = item.getItem().copy();
176
            Component text = formatReferenceItemLabel(stack);
177
            AABB labelBox = item.getBoundingBox().move(pos.subtract(item.position())).inflate(0.1);
178
            Vec3 anchor = new Vec3(labelBox.getCenter().x, labelBox.maxY, labelBox.getCenter().z);
179
180
            Vec3 frameAnchor = null;
181
            double frameWorldWidth = 0.0;
182
            double frameWorldHeight = 0.0;
183
            if (framesEnabled) {
184
                AABB frameBox = item.getBoundingBox().move(
185
                        pos.x - item.getX(),
186
                        pos.y - item.getY(),
187
                        pos.z - item.getZ()
188
                );
189
                frameBox = frameBox.inflate(0.1);
190
                frameAnchor = new Vec3(
191
                        (frameBox.minX + frameBox.maxX) * 0.5,
192
                        (frameBox.minY + frameBox.maxY) * 0.5,
193
                        (frameBox.minZ + frameBox.maxZ) * 0.5
194
                );
195
                frameWorldWidth = Math.max(frameBox.maxX - frameBox.minX, frameBox.maxZ - frameBox.minZ);
196
                frameWorldHeight = frameBox.maxY - frameBox.minY;
197
            }
198
199
            entries.add(new DropWorldEntry(
200
                    resolveSortPriority(stack), distSq, anchor, frameAnchor, frameWorldWidth, frameWorldHeight,
201
                    presentation.worldUnitsPerPixel(), presentation.worldAlpha(), stack, text, resolveDisplayColor(stack)));
202
        }
203
204
        entries.sort(DropESP::compareDropWorldRenderOrder);
205
        for (int i = 0; i < entries.size(); i++) {
206
            DropWorldEntry entry = entries.get(i);
207
            itemRows.add(new ItemBatchRenderer.WorldItemRow(null,
208
                    itemIconValue.get() ? new ItemStack[]{entry.stack()} : new ItemStack[0], i));
209
        }
210
        // Capture the billboard axes before GuiItemAtlas performs any off-screen rendering.
211
        // More importantly, currentBasis itself is backed by the immutable captured camera
212
        // matrix, so item-atlas state can never influence billboard orientation.
213
        WorldBillboardRenderer.Basis basis = WorldBillboardRenderer.currentBasis();
214
        java.util.List<ItemBatchRenderer.WorldItemSprite[]> sprites =
215
                ItemBatchRenderer.resolveWorldItemSprites(itemRows);
216
        for (int i = 0; i < entries.size(); i++) {
217
            ItemBatchRenderer.WorldItemSprite sprite = i < sprites.size() && sprites.get(i).length > 0
218
                    ? sprites.get(i)[0]
219
                    : null;
220
            renderWorldDrop(renderer, basis, labelRenderer, entries.get(i), sprite);
221
        }
222
    }
223
224
    @Override
225
    public void onRenderHudEngine(Renderer2D renderer, TextRenderer textRenderer, GuiGraphicsExtractor ctx, float tickDelta) {
226
        if (!isEnabled() || mc.level == null || mc.player == null) return;
227
        if (presentationMode.get() == WorldUiPresentationService.Mode.WORLD) return;
228
229
        boolean matteMode = isMatteMode();
230
        boolean overlayMode = isOverlayMode();
231
        TextRenderer labelRenderer = overlayMode ? dropLabelRenderer(textRenderer) : VanillaTextRenderer.INSTANCE;
232
        boolean measureStarted = false;
233
        java.util.List<DropOverlayEntry> overlayEntries = new java.util.ArrayList<>();
234
        java.util.List<DropVanillaEntry> vanillaEntries = new java.util.ArrayList<>();
235
        double textScale = overlayMode ? DROP_TEXT_SCALE : ScreenSpaceOverlay2D.VANILLA_TEXT_SCALE;
236
237
        if (!labelRenderer.isBuilding()) {
238
            labelRenderer.begin(textScale, true, false);
239
            measureStarted = true;
240
        }
241
242
        Vec3 cameraPos = presentationCameraPosition(tickDelta);
243
        for (ItemEntity item : mc.level.getEntitiesOfClass(
244
                ItemEntity.class,
245
                mc.player.getBoundingBox().inflate(64),
246
                e -> true
247
        )) {
248
249
            Vec3 pos = obtainEntityLerpedPos(item, tickDelta);
250
251
            double distSq = pos.distanceToSqr(cameraPos);
252
            double dist = Math.sqrt(distSq);
253
            if (!passesDistanceFilter(item, dist)) continue;
254
            float presentationAlpha = resolvePresentation(dist).screenAlpha();
255
            if (presentationAlpha <= 0.001f) continue;
256
257
            ItemStack stack = item.getItem();
258
            Component text = formatReferenceItemLabel(stack);
259
            int color = resolveDisplayColor(stack);
260
            int sortPriority = resolveSortPriority(stack);
261
262
            if (overlayMode) {
263
                AABB overlayBox = item.getBoundingBox().move(
264
                        pos.x - item.getX(),
265
                        pos.y - item.getY(),
266
                        pos.z - item.getZ()
267
                ).inflate(0.1);
268
                ScreenSpaceOverlay2D.ScreenRect rect = ScreenSpaceOverlay2D.projectBox(overlayBox, tickDelta);
269
                if (rect == null) continue;
270
271
                DropLabelEntry matteLabel = matteMode
272
                        ? createMatteDropLabel(labelRenderer, stack, text, color, rect, itemIconValue.get())
273
                        : null;
274
                ScreenSpaceOverlay2D.LabelEntry label = matteMode
275
                        ? null
276
                        : ScreenSpaceOverlay2D.createCenteredLabel(labelRenderer, text.getString(), color, rect);
277
                overlayEntries.add(new DropOverlayEntry(
278
                        sortPriority, distSq, rect, color, matteLabel, label, presentationAlpha));
279
            } else {
280
                AABB box = item.getBoundingBox().move(
281
                        pos.x - item.getX(),
282
                        pos.y - item.getY(),
283
                        pos.z - item.getZ()
284
                );
285
286
                Vec3 center = new Vec3(
287
                        (box.minX + box.maxX) * 0.5,
288
                        box.minY + (box.maxY - box.minY) * 0.6,
289
                        (box.minZ + box.maxZ) * 0.5
290
                );
291
292
                Vec3 screen = ScreenProjection.worldToScreen(center, tickDelta);
293
                if (screen == null) continue;
294
295
                double x = screen.x - (labelRenderer.getWidth(text.getString(), false) / 2.0);
296
                double y = screen.y;
297
                vanillaEntries.add(new DropVanillaEntry(
298
                        sortPriority, distSq, ScreenSpaceOverlay2D.labelAt(text.getString(), x, y, color), presentationAlpha));
299
            }
300
        }
301
302
        if (measureStarted) {
303
            labelRenderer.end();
304
        }
305
        if (overlayEntries.isEmpty() && vanillaEntries.isEmpty()) return;
306
307
        overlayEntries.sort(DropESP::compareDropRenderOrder);
308
        vanillaEntries.sort(DropESP::compareDropRenderOrder);
309
310
        if (overlayMode) {
311
            for (DropOverlayEntry entry : overlayEntries) {
312
                renderOverlayEntryPass(renderer, labelRenderer, entry, matteMode, textScale);
313
            }
314
        } else {
315
            for (DropVanillaEntry entry : vanillaEntries) {
316
                renderSingleLabel(labelRenderer, entry.label(), textScale, entry.alpha());
317
                Renderer2D.flushBatch(Renderer2D.FlushReason.EXPLICIT);
318
            }
319
        }
320
    }
321
322
    private void renderOverlayEntryPass(Renderer2D renderer,
323
                                        TextRenderer labelRenderer,
324
                                        DropOverlayEntry entry,
325
                                        boolean matteMode,
326
                                        double textScale) {
327
        double previousAlpha = renderer.getAlpha();
328
        renderer.setAlpha(previousAlpha * entry.alpha());
329
        try {
330
            ScreenSpaceOverlay2D.ScreenRect rect = entry.rect();
331
            if (frameValue.get()) {
332
                // DropESP frames are hard rectangular quad outlines in every
333
                // presentation mode. No rounded/SDF stroke is used here.
334
                ScreenSpaceOverlay2D.drawFrame(renderer, rect, entry.color());
335
            }
336
337
            if (matteMode) {
338
                DropLabelEntry label = entry.matteLabel();
339
                if (label == null) return;
340
                renderer.roundedRect(label.x(), label.y(), label.width(), label.height(),
341
                        MATTE_LABEL_RADIUS, 0.0f, withAlpha(0x000000, MATTE_BACKDROP_ALPHA));
342
                if (label.icon()) {
343
                    renderer.item(label.stack(), label.iconX(), label.iconY(), MATTE_ICON_SCALE, 0, Renderer2D.ITEM_OVERLAY_NONE, null);
344
                }
345
                renderSingleDropLabel(labelRenderer, label, textScale, entry.alpha());
346
            } else {
347
                ScreenSpaceOverlay2D.LabelEntry label = entry.label();
348
                if (label == null) return;
349
                renderSingleLabel(labelRenderer, label, textScale, entry.alpha());
350
            }
351
        } finally {
352
            renderer.setAlpha(previousAlpha);
353
        }
354
355
        Renderer2D.flushBatch(Renderer2D.FlushReason.EXPLICIT);
356
    }
357
358
    private void renderSingleDropLabel(TextRenderer labelRenderer, DropLabelEntry label, double textScale, float alpha) {
359
        boolean renderStarted = false;
360
        if (!labelRenderer.isBuilding()) {
361
            labelRenderer.begin(textScale);
362
            renderStarted = true;
363
        }
364
        try {
365
            double cursor = label.textX();
366
            for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(label.text(), label.color())) {
367
                String safe = RuntimeTextLayout.singleLine(part.text());
368
                cursor = labelRenderer.render(safe, cursor, label.textY(),
369
                        new RenderColor(scaleAlpha(part.color(), alpha)), false);
370
            }
371
        } finally {
372
            if (renderStarted) labelRenderer.end();
373
        }
374
    }
375
376
    private void renderSingleLabel(TextRenderer labelRenderer,
377
                                   ScreenSpaceOverlay2D.LabelEntry label,
378
                                   double textScale,
379
                                   float alpha) {
380
        boolean renderStarted = false;
381
        if (!labelRenderer.isBuilding()) {
382
            labelRenderer.begin(textScale);
383
            renderStarted = true;
384
        }
385
        try {
386
            ScreenSpaceOverlay2D.renderLabels(labelRenderer, java.util.List.of(label), false, alpha);
387
        } finally {
388
            if (renderStarted) labelRenderer.end();
389
        }
390
    }
391
392
    private DropLabelEntry createMatteDropLabel(TextRenderer labelRenderer,
393
                                                ItemStack stack,
394
                                                Component text,
395
                                                int color,
396
                                                ScreenSpaceOverlay2D.ScreenRect rect,
397
                                                boolean icon) {
398
        double textWidth = screenStyledTextWidth(labelRenderer, text, DROP_TEXT_SCALE, color);
399
        double measuredTextHeight = RuntimeTextLayout.height(labelRenderer, DROP_TEXT_SCALE, false);
400
        double textHeight = Math.max(RICH_TEXT_LOGICAL_HEIGHT, measuredTextHeight);
401
        double iconBlock = icon ? MATTE_ICON_SIZE + MATTE_ICON_GAP : 0.0;
402
        double width = textWidth + iconBlock + MATTE_LABEL_PAD_X * 2.0;
403
        double contentHeight = Math.max(textHeight, icon ? MATTE_ICON_SIZE : 0.0);
404
        double height = contentHeight + MATTE_LABEL_PAD_Y * 2.0;
405
        double x = rect.minX() + (rect.width() - width) * 0.5;
406
        double y = rect.minY() - height + MATTE_LABEL_PAD_Y;
407
        double iconX = x + MATTE_LABEL_PAD_X;
408
        double iconY = y + (height - MATTE_ICON_SIZE) * 0.5;
409
        double textX = x + MATTE_LABEL_PAD_X + iconBlock;
410
        double textY = y + (height - measuredTextHeight) * 0.5;
411
        return new DropLabelEntry(stack, text, x, y, width, height, icon, iconX, iconY, textX, textY, color);
412
    }
413
414
    private static double screenStyledTextWidth(TextRenderer renderer, Component text, double scale, int defaultColor) {
415
        if (renderer == null || text == null) return 0.0;
416
        double width = 0.0;
417
        for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(text, defaultColor)) {
418
            width += RuntimeTextLayout.width(renderer, part.text(), scale, false);
419
        }
420
        return width;
421
    }
422
423
    private static double worldStyledTextWidth(TextRenderer renderer, Component text, double scale, int defaultColor) {
424
        if (renderer == null || text == null) return 0.0;
425
        double width = 0.0;
426
        for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(text, defaultColor)) {
427
            String safe = RuntimeTextLayout.singleLine(part.text());
428
            width += WorldTextRenderer.measure(renderer, safe, scale, false).width();
429
        }
430
        return width;
431
    }
432
433
    private void renderWorldDrop(Renderer3D renderer,
434
                                 WorldBillboardRenderer.Basis basis,
435
                                 TextRenderer labelRenderer,
436
                                 DropWorldEntry entry,
437
                                 ItemBatchRenderer.WorldItemSprite itemSprite) {
438
        double textScale = DROP_TEXT_SCALE;
439
        double textWidth = worldStyledTextWidth(labelRenderer, entry.text(), textScale, entry.color());
440
        double measuredTextHeight = WorldTextRenderer.measure(labelRenderer, "Ag", textScale, false).height();
441
        boolean icon = itemIconValue.get() && itemSprite != null;
442
        double iconBlock = icon ? MATTE_ICON_SIZE + MATTE_ICON_GAP : 0.0;
443
        double textHeight = Math.max(RICH_TEXT_LOGICAL_HEIGHT, measuredTextHeight);
444
        double contentHeight = Math.max(textHeight, icon ? MATTE_ICON_SIZE : 0.0);
445
        double width = textWidth + iconBlock + MATTE_LABEL_PAD_X * 2.0;
446
        double height = contentHeight + MATTE_LABEL_PAD_Y * 2.0;
447
        double x = -width * 0.5;
448
        double y = -height + MATTE_LABEL_PAD_Y;
449
450
        if (entry.frameAnchor() != null && entry.frameWorldWidth() > 0.0 && entry.frameWorldHeight() > 0.0) {
451
            double fw = entry.frameWorldWidth() / entry.worldScale();
452
            double fh = entry.frameWorldHeight() / entry.worldScale();
453
            double fx = -fw * 0.5;
454
            double fy = -fh * 0.5;
455
            double t = 0.5;
456
            int c = scaleAlpha(entry.color(), entry.alpha());
457
            WorldBillboardRenderer.quad(renderer, basis, entry.frameAnchor(), fx - t, fy - t, fw + t * 2.0, t, entry.worldScale(), c);
458
            WorldBillboardRenderer.quad(renderer, basis, entry.frameAnchor(), fx - t, fy - t, t, fh + t * 2.0, entry.worldScale(), c);
459
            WorldBillboardRenderer.quad(renderer, basis, entry.frameAnchor(), fx - t, fy + fh, fw + t * 2.0, t, entry.worldScale(), c);
460
            WorldBillboardRenderer.quad(renderer, basis, entry.frameAnchor(), fx + fw, fy - t, t, fh + t * 2.0, entry.worldScale(), c);
461
        }
462
463
        WorldBillboardRenderer.roundedRect(
464
                renderer, basis, entry.anchor(), x, y, width, height, MATTE_LABEL_RADIUS, entry.worldScale(),
465
                withAlpha(0x000000, Math.round(MATTE_BACKDROP_ALPHA * entry.alpha()))
466
        );
467
468
        double cursorX = x + MATTE_LABEL_PAD_X;
469
        if (icon) {
470
            double iconY = y + (height - MATTE_ICON_SIZE) * 0.5;
471
            WorldBillboardRenderer.item(renderer, basis, entry.anchor(), itemSprite,
472
                    cursorX, iconY, MATTE_ICON_SIZE, entry.worldScale(), entry.alpha());
473
            cursorX += iconBlock;
474
        }
475
        double textY = y + (height - measuredTextHeight) * 0.5;
476
        double textCursor = cursorX;
477
        for (TextRenderUtil.Part part : TextRenderUtil.flattenStyled(entry.text(), entry.color())) {
478
            String safe = RuntimeTextLayout.singleLine(part.text());
479
            WorldBillboardRenderer.text(renderer, basis, labelRenderer, safe, entry.anchor(),
480
                    textCursor, textY, textScale, entry.worldScale(), part.color(), entry.alpha(), false);
481
            textCursor += WorldTextRenderer.measure(labelRenderer, safe, textScale, false).width();
482
        }
483
    }
484
485
    private static TextRenderer dropLabelRenderer(TextRenderer fallback) {
486
        return BuiltinFontCatalog.INTER_MEDIUM.renderer(fallback);
487
    }
488
489
    private static Component formatReferenceItemLabel(ItemStack stack) {
490
        if (stack == null || stack.isEmpty()) return Component.empty();
491
        MutableComponent text = Component.literal(stack.getHoverName().getString());
492
        if (stack.getCount() > 1) {
493
            text.append(Component.literal(" [").withStyle(ChatFormatting.WHITE));
494
            text.append(Component.literal(Integer.toString(stack.getCount())).withStyle(ChatFormatting.RED));
495
            text.append(Component.literal("x").withStyle(ChatFormatting.GRAY));
496
            text.append(Component.literal("]").withStyle(ChatFormatting.WHITE));
497
        }
498
        return RuntimeTextLayout.singleLine(text);
499
    }
500
501
    private static int withAlpha(int rgb, int alpha) {
502
        int a = Math.max(0, Math.min(255, alpha));
503
        return (rgb & 0x00FFFFFF) | (a << 24);
504
    }
505
506
    private static int scaleAlpha(int argb, float alpha) {
507
        int source = (argb >>> 24) & 0xFF;
508
        return withAlpha(argb, Math.round(source * Math.max(0.0f, Math.min(1.0f, alpha))));
509
    }
510
511
    private boolean passesDistanceFilter(ItemEntity item, double dist) {
512
513
        String id = BuiltInRegistries.ITEM.getKey(item.getItem().getItem()).toString().toLowerCase();
514
515
        if (specialItemsValue.get().contains(id)) {
516
            return true;
517
        }
518
519
        if (limitCommonDistanceValue.get()) {
520
521
            if (item.getItem().isEnchanted()) {
522
                return true;
523
            }
524
525
            var rarity = item.getItem().getOrDefault(
526
                    DataComponents.RARITY,
527
                    Rarity.COMMON
528
            );
529
530
            if (rarity == Rarity.COMMON) {
531
                return dist <= commonMaxDistanceValue.get();
532
            }
533
        }
534
535
        return true;
536
    }
537
538
    private WorldUiPresentationService.Snapshot resolvePresentation(double distance) {
539
        double projectionYScale = RenderState.worldProjection.m11();
540
        ViewportContext viewport = ViewportContext.current();
541
        double logicalHeight = viewport != null ? viewport.height() : 0.0;
542
        return WorldUiPresentationService.resolve(
543
                presentationMode.get(), distance, WORLD_PRESENTATION_POLICY, projectionYScale, logicalHeight,
544
                worldSize.get(), dynamicWorldScale.get(), dynamicWorldScaleCoefficient.get());
545
    }
546
547
    private Vec3 presentationCameraPosition(float tickDelta) {
548
        Vec3 captured = CombatantWorldMatrices.cameraPosition();
549
        if (captured != null) return captured;
550
        if (mc.gameRenderer != null && mc.gameRenderer.mainCamera() != null) {
551
            return mc.gameRenderer.mainCamera().position();
552
        }
553
        return mc.player != null ? mc.player.getEyePosition(tickDelta) : Vec3.ZERO;
554
    }
555
556
    @Override
557
    public java.util.List<ConfigValue<?>> getConfigValues() {
558
        java.util.List<ConfigValue<?>> list = new java.util.ArrayList<>(super.getConfigValues());
559
        list.add(TopEnchantUtil.topColorValue());
560
        return list;
561
    }
562
563
    private boolean isMatteMode() {
564
        return "Matte".equalsIgnoreCase(modeValue.get());
565
    }
566
567
    private boolean isOverlayMode() {
568
        return isMatteMode();
569
    }
570
571
    private int resolveSortPriority(ItemStack stack) {
572
        String id = BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().toLowerCase();
573
        if (IllegalItemUtil.isIllegal(stack)) {
574
            return 1000;
575
        }
576
        if (TopEnchantUtil.hasTopEnchant(stack)) {
577
            return 900;
578
        }
579
        if (specialItemsValue.get().contains(id)) {
580
            return 800;
581
        }
582
583
        Rarity rarity = stack.getOrDefault(DataComponents.RARITY, Rarity.COMMON);
584
        return switch (rarity) {
585
            case EPIC -> 400;
586
            case RARE -> 300;
587
            case UNCOMMON -> 200;
588
            case COMMON -> 100;
589
            default -> 100;
590
        };
591
    }
592
593
    private int resolveDisplayColor(ItemStack stack) {
594
        String id = BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().toLowerCase();
595
        if (IllegalItemUtil.isIllegal(stack)) {
596
            return IllegalItemUtil.illegalColor();
597
        }
598
        if (TopEnchantUtil.hasTopEnchant(stack)) {
599
            return TopEnchantUtil.topColor();
600
        }
601
        if (specialItemsValue.get().contains(id)) {
602
            return specialColorValue.getArgb();
603
        }
604
        float[] c = RarityColorUtil.INSTANCE.getRarityColor(stack);
605
        return rgbaToARGB(c);
606
    }
607
608
    private int rgbaToARGB(float[] c) {
609
        int r = (int) (c[0] * 255);
610
        int g = (int) (c[1] * 255);
611
        int b = (int) (c[2] * 255);
612
        int a = (int) (c[3] * 255);
613
        return (a << 24) | (r << 16) | (g << 8) | b;
614
    }
615
616
    private Vec3 obtainEntityLerpedPos(Entity e, float f) {
617
        try {
618
            return e.getPosition(f);
619
        } catch (NoSuchMethodError ex) {
620
            if (e instanceof IEntity access) {
621
                Vec3 last = access.get$InstantRenderPos();
622
                return last.lerp(e.position(), f);
623
            }
624
            return e.position();
625
        }
626
    }
627
628
629
    private record DropOverlayEntry(int sortPriority, double distSq, ScreenSpaceOverlay2D.ScreenRect rect, int color,
630
                                    DropLabelEntry matteLabel, ScreenSpaceOverlay2D.LabelEntry label, float alpha) {
631
    }
632
633
    private record DropVanillaEntry(int sortPriority, double distSq, ScreenSpaceOverlay2D.LabelEntry label, float alpha) {
634
    }
635
636
    private record DropWorldEntry(int sortPriority,
637
                                  double distSq,
638
                                  Vec3 anchor,
639
                                  Vec3 frameAnchor,
640
                                  double frameWorldWidth,
641
                                  double frameWorldHeight,
642
                                  double worldScale,
643
                                  float alpha,
644
                                  ItemStack stack,
645
                                  Component text,
646
                                  int color) {
647
    }
648
649
    private record DropLabelEntry(ItemStack stack, Component text, double x, double y, double width, double height,
650
                                  boolean icon, double iconX, double iconY, double textX, double textY, int color) {
651
    }
652
}
653