esp module

esp: Minecraft 26.3 cheat module, full source for every implementation (6 clients: Meteor Client, MelaHack (ThunderHack fork), OfflineClient, …).

6 implementationsRenderRENDERVISUALS

Full module source: 6 implementations

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

Meteor ClientRendersrc/main/java/meteordevelopment/meteorclient/systems/modules/render/ESP.javaJava · 462 lines · 16.6 KB

Renders entities through walls.

Settingsmodehighlight-targettarget-hitboxoutline-widthglow-multiplierignore-selfshape-modefill-opacityfade-distanceentitiescolor-modeshow-friend-colorsnon-living-entity-colorplayers-coloranimals-colorwater-animals-colormonsters-colorambient-colormisc-colortarget-colortarget-hitbox-color
ESP.javaJava · Minecraft 26.2 · 462 lines · 16.6 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.render;
7
8
import meteordevelopment.meteorclient.events.render.Render2DEvent;
9
import meteordevelopment.meteorclient.events.render.Render3DEvent;
10
import meteordevelopment.meteorclient.renderer.Renderer2D;
11
import meteordevelopment.meteorclient.renderer.ShapeMode;
12
import meteordevelopment.meteorclient.settings.*;
13
import meteordevelopment.meteorclient.systems.config.Config;
14
import meteordevelopment.meteorclient.systems.friends.Friends;
15
import meteordevelopment.meteorclient.systems.modules.Categories;
16
import meteordevelopment.meteorclient.systems.modules.Module;
17
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
18
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
19
import meteordevelopment.meteorclient.utils.render.NametagUtils;
20
import meteordevelopment.meteorclient.utils.render.WireframeEntityRenderer;
21
import meteordevelopment.meteorclient.utils.render.color.Color;
22
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
23
import meteordevelopment.orbit.EventHandler;
24
import net.minecraft.util.Mth;
25
import net.minecraft.world.entity.Entity;
26
import net.minecraft.world.entity.EntityType;
27
import net.minecraft.world.entity.EntityTypes;
28
import net.minecraft.world.entity.player.Player;
29
import net.minecraft.world.phys.AABB;
30
import net.minecraft.world.phys.EntityHitResult;
31
import org.joml.Vector3d;
32
33
import java.util.Set;
34
35
public class ESP extends Module {
36
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
37
    private final SettingGroup sgColors = settings.createGroup("Colors");
38
39
    // General
40
41
    public final Setting<Mode> mode = sgGeneral.add(new EnumSetting.Builder<Mode>()
42
        .name("mode")
43
        .description("Rendering mode.")
44
        .defaultValue(Mode.Shader)
45
        .build()
46
    );
47
48
    public final Setting<Boolean> highlightTarget = sgGeneral.add(new BoolSetting.Builder()
49
        .name("highlight-target")
50
        .description("highlights the currently targeted entity differently")
51
        .defaultValue(false)
52
        .build()
53
    );
54
55
    public final Setting<Boolean> targetHitbox = sgGeneral.add(new BoolSetting.Builder()
56
        .name("target-hitbox")
57
        .description("draw the hitbox of the target entity")
58
        .defaultValue(true)
59
        .visible(highlightTarget::get)
60
        .build()
61
    );
62
63
    public final Setting<Integer> outlineWidth = sgGeneral.add(new IntSetting.Builder()
64
        .name("outline-width")
65
        .description("The width of the shader outline.")
66
        .visible(() -> mode.get() == Mode.Shader)
67
        .defaultValue(2)
68
        .range(1, 10)
69
        .sliderRange(1, 5)
70
        .build()
71
    );
72
73
    public final Setting<Double> glowMultiplier = sgGeneral.add(new DoubleSetting.Builder()
74
        .name("glow-multiplier")
75
        .description("Multiplier for glow effect")
76
        .visible(() -> mode.get() == Mode.Shader)
77
        .decimalPlaces(3)
78
        .defaultValue(3.5)
79
        .min(0)
80
        .sliderMax(10)
81
        .build()
82
    );
83
84
    public final Setting<Boolean> ignoreSelf = sgGeneral.add(new BoolSetting.Builder()
85
        .name("ignore-self")
86
        .description("Ignores yourself drawing the shader.")
87
        .defaultValue(true)
88
        .build()
89
    );
90
91
    public final Setting<ShapeMode> shapeMode = sgGeneral.add(new EnumSetting.Builder<ShapeMode>()
92
        .name("shape-mode")
93
        .description("How the shapes are rendered.")
94
        .visible(() -> mode.get() != Mode.Glow)
95
        .defaultValue(ShapeMode.Both)
96
        .build()
97
    );
98
99
    public final Setting<Double> fillOpacity = sgGeneral.add(new DoubleSetting.Builder()
100
        .name("fill-opacity")
101
        .description("The opacity of the shape fill.")
102
        .visible(() -> shapeMode.get() != ShapeMode.Lines && mode.get() != Mode.Glow)
103
        .defaultValue(0.3)
104
        .range(0, 1)
105
        .sliderMax(1)
106
        .build()
107
    );
108
109
    private final Setting<Double> fadeDistance = sgGeneral.add(new DoubleSetting.Builder()
110
        .name("fade-distance")
111
        .description("The distance from an entity where the color begins to fade.")
112
        .defaultValue(3)
113
        .min(0)
114
        .sliderMax(12)
115
        .build()
116
    );
117
118
    private final Setting<Set<EntityType<?>>> entities = sgGeneral.add(new EntityTypeListSetting.Builder()
119
        .name("entities")
120
        .description("Select specific entities.")
121
        .defaultValue(EntityTypes.PLAYER)
122
        .build()
123
    );
124
125
    // Colors
126
127
    public final Setting<ESPColorMode> colorMode = sgColors.add(new EnumSetting.Builder<ESPColorMode>()
128
        .name("color-mode")
129
        .description("Determines the colors used for entities.")
130
        .defaultValue(ESPColorMode.EntityType)
131
        .build()
132
    );
133
134
    public final Setting<Boolean> friendOverride = sgColors.add(new BoolSetting.Builder()
135
        .name("show-friend-colors")
136
        .description("Whether or not to override the distance/health color of friends with the friend color.")
137
        .defaultValue(true)
138
        .visible(() -> colorMode.get() == ESPColorMode.Distance || colorMode.get() == ESPColorMode.Health)
139
        .build()
140
    );
141
142
    private final Setting<SettingColor> nonLivingEntityColor = sgColors.add(new ColorSetting.Builder()
143
        .name("non-living-entity-color")
144
        .description("The color used for non living entities such as dropped items.")
145
        .defaultValue(new SettingColor(25, 25, 25))
146
        .visible(() -> colorMode.get() == ESPColorMode.Health)
147
        .build()
148
    );
149
150
    private final Setting<SettingColor> playersColor = sgColors.add(new ColorSetting.Builder()
151
        .name("players-color")
152
        .description("The other player's color.")
153
        .defaultValue(new SettingColor(255, 255, 255))
154
        .visible(() -> colorMode.get() == ESPColorMode.EntityType)
155
        .build()
156
    );
157
158
    private final Setting<SettingColor> animalsColor = sgColors.add(new ColorSetting.Builder()
159
        .name("animals-color")
160
        .description("The animal's color.")
161
        .defaultValue(new SettingColor(25, 255, 25, 255))
162
        .visible(() -> colorMode.get() == ESPColorMode.EntityType)
163
        .build()
164
    );
165
166
    private final Setting<SettingColor> waterAnimalsColor = sgColors.add(new ColorSetting.Builder()
167
        .name("water-animals-color")
168
        .description("The water animal's color.")
169
        .defaultValue(new SettingColor(25, 25, 255, 255))
170
        .visible(() -> colorMode.get() == ESPColorMode.EntityType)
171
        .build()
172
    );
173
174
    private final Setting<SettingColor> monstersColor = sgColors.add(new ColorSetting.Builder()
175
        .name("monsters-color")
176
        .description("The monster's color.")
177
        .defaultValue(new SettingColor(255, 25, 25, 255))
178
        .visible(() -> colorMode.get() == ESPColorMode.EntityType)
179
        .build()
180
    );
181
182
    private final Setting<SettingColor> ambientColor = sgColors.add(new ColorSetting.Builder()
183
        .name("ambient-color")
184
        .description("The ambient's color.")
185
        .defaultValue(new SettingColor(25, 25, 25, 255))
186
        .visible(() -> colorMode.get() == ESPColorMode.EntityType)
187
        .build()
188
    );
189
190
    private final Setting<SettingColor> miscColor = sgColors.add(new ColorSetting.Builder()
191
        .name("misc-color")
192
        .description("The misc color.")
193
        .defaultValue(new SettingColor(175, 175, 175, 255))
194
        .visible(() -> colorMode.get() == ESPColorMode.EntityType)
195
        .build()
196
    );
197
198
    private final Setting<SettingColor> targetColor = sgColors.add(new ColorSetting.Builder()
199
        .name("target-color")
200
        .description("The target color.")
201
        .defaultValue(new SettingColor(200, 200, 200, 255))
202
        .visible(highlightTarget::get)
203
        .build()
204
    );
205
206
    private final Setting<SettingColor> targetHitboxColor = sgColors.add(new ColorSetting.Builder()
207
        .name("target-hitbox-color")
208
        .description("The target hitbox color.")
209
        .defaultValue(new SettingColor(100, 200, 200, 255))
210
        .visible(() -> highlightTarget.get() && targetHitbox.get())
211
        .build()
212
    );
213
214
    private final Color lineColor = new Color();
215
    private final Color sideColor = new Color();
216
    private final Color baseColor = new Color();
217
218
    private final Vector3d pos1 = new Vector3d();
219
    private final Vector3d pos2 = new Vector3d();
220
    private final Vector3d pos = new Vector3d();
221
222
    private int count;
223
224
    public ESP() {
225
        super(Categories.Render, "esp", "Renders entities through walls.");
226
    }
227
228
    // Box
229
230
    @EventHandler
231
    private void onRender3D(Render3DEvent event) {
232
        if (mode.get() == Mode._2D) return;
233
234
        count = 0;
235
236
        Entity target = null;
237
        if (highlightTarget.get() && targetHitbox.get() && mc.hitResult instanceof EntityHitResult hr)
238
            target = hr.getEntity();
239
240
        for (Entity entity : mc.level.entitiesForRendering()) {
241
            if (target != entity && shouldSkip(entity)) continue;
242
            if (target == entity || mode.get() == Mode.Box || mode.get() == Mode.Wireframe)
243
                drawBoundingBox(event, entity);
244
            count++;
245
        }
246
    }
247
248
    private void drawBoundingBox(Render3DEvent event, Entity entity) {
249
        Color color = getColor(entity);
250
        if (color != null) {
251
            lineColor.set(color);
252
            sideColor.set(color).a((int) (sideColor.a * fillOpacity.get()));
253
        }
254
255
        if (mode.get() == Mode.Wireframe) {
256
            WireframeEntityRenderer.render(event, entity, 1, sideColor, lineColor, shapeMode.get());
257
        }
258
259
        boolean target = drawAsTarget(entity);
260
261
        if (mode.get() == Mode.Box || (targetHitbox.get() && target)) {
262
            double x = Mth.lerp(event.tickDelta, entity.xOld, entity.getX()) - entity.getX();
263
            double y = Mth.lerp(event.tickDelta, entity.yOld, entity.getY()) - entity.getY();
264
            double z = Mth.lerp(event.tickDelta, entity.zOld, entity.getZ()) - entity.getZ();
265
266
            ShapeMode shape = shapeMode.get();
267
            if (target && mode.get() != Mode.Box) shape = ShapeMode.Lines;
268
            if (target) lineColor.set(targetHitboxColor.get());
269
270
            AABB box = entity.getBoundingBox();
271
            event.renderer.box(x + box.minX, y + box.minY, z + box.minZ, x + box.maxX, y + box.maxY, z + box.maxZ, sideColor, lineColor, shape, 0);
272
        }
273
    }
274
275
    // 2D
276
277
    @EventHandler
278
    private void onRender2D(Render2DEvent event) {
279
        if (mode.get() != Mode._2D) return;
280
281
        Renderer2D.COLOR.begin();
282
        count = 0;
283
284
        for (Entity entity : mc.level.entitiesForRendering()) {
285
            if (shouldSkip(entity)) continue;
286
287
            AABB box = entity.getBoundingBox();
288
289
            double x = Mth.lerp(event.tickDelta, entity.xOld, entity.getX()) - entity.getX();
290
            double y = Mth.lerp(event.tickDelta, entity.yOld, entity.getY()) - entity.getY();
291
            double z = Mth.lerp(event.tickDelta, entity.zOld, entity.getZ()) - entity.getZ();
292
293
            // Check corners
294
            pos1.set(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
295
            pos2.set(0, 0, 0);
296
297
            //     Bottom
298
            if (checkCorner(box.minX + x, box.minY + y, box.minZ + z, pos1, pos2)) continue;
299
            if (checkCorner(box.maxX + x, box.minY + y, box.minZ + z, pos1, pos2)) continue;
300
            if (checkCorner(box.minX + x, box.minY + y, box.maxZ + z, pos1, pos2)) continue;
301
            if (checkCorner(box.maxX + x, box.minY + y, box.maxZ + z, pos1, pos2)) continue;
302
303
            //     Top
304
            if (checkCorner(box.minX + x, box.maxY + y, box.minZ + z, pos1, pos2)) continue;
305
            if (checkCorner(box.maxX + x, box.maxY + y, box.minZ + z, pos1, pos2)) continue;
306
            if (checkCorner(box.minX + x, box.maxY + y, box.maxZ + z, pos1, pos2)) continue;
307
            if (checkCorner(box.maxX + x, box.maxY + y, box.maxZ + z, pos1, pos2)) continue;
308
309
            // Setup color
310
            Color color = getColor(entity);
311
            if (color != null) {
312
                lineColor.set(color);
313
                sideColor.set(color).a((int) (sideColor.a * fillOpacity.get()));
314
            }
315
316
            // Render
317
            if (shapeMode.get() != ShapeMode.Lines && sideColor.a > 0) {
318
                Renderer2D.COLOR.quad(pos1.x, pos1.y, pos2.x - pos1.x, pos2.y - pos1.y, sideColor);
319
            }
320
321
            if (shapeMode.get() != ShapeMode.Sides) {
322
                Renderer2D.COLOR.line(pos1.x, pos1.y, pos1.x, pos2.y, lineColor);
323
                Renderer2D.COLOR.line(pos2.x, pos1.y, pos2.x, pos2.y, lineColor);
324
                Renderer2D.COLOR.line(pos1.x, pos1.y, pos2.x, pos1.y, lineColor);
325
                Renderer2D.COLOR.line(pos1.x, pos2.y, pos2.x, pos2.y, lineColor);
326
            }
327
328
            count++;
329
        }
330
331
        Renderer2D.COLOR.render();
332
    }
333
334
    public boolean forceRender() {
335
        return isActive() && (mode.get() == Mode.Shader || mode.get() == Mode.Glow);
336
    }
337
338
    private boolean checkCorner(double x, double y, double z, Vector3d min, Vector3d max) {
339
        pos.set(x, y, z);
340
        if (!NametagUtils.to2D(pos, 1)) return true;
341
342
        // Check Min
343
        if (pos.x < min.x) min.x = pos.x;
344
        if (pos.y < min.y) min.y = pos.y;
345
        if (pos.z < min.z) min.z = pos.z;
346
347
        // Check Max
348
        if (pos.x > max.x) max.x = pos.x;
349
        if (pos.y > max.y) max.y = pos.y;
350
        if (pos.z > max.z) max.z = pos.z;
351
352
        return false;
353
    }
354
355
    // Utils
356
357
    public boolean drawAsTarget(Entity entity) {
358
        return highlightTarget.get() && mc.hitResult instanceof EntityHitResult hr && hr.getEntity() == entity;
359
    }
360
361
    public boolean shouldSkip(Entity entity) {
362
        if (drawAsTarget(entity)) return false;
363
        if (!entities.get().contains(entity.getType())) return true;
364
        if (entity == mc.player && ignoreSelf.get()) return true;
365
        if (entity == mc.getCameraEntity() && mc.options.getCameraType().isFirstPerson()) return true;
366
        return !EntityUtils.isInRenderDistance(entity);
367
    }
368
369
    public boolean shouldSkip(EntityType<?> entityType) {
370
        return !entities.get().contains(entityType);
371
    }
372
373
    public Color getColor(Entity entity) {
374
        Color color;
375
        double alpha = 1;
376
377
        if (drawAsTarget(entity)) {
378
            color = targetColor.get();
379
        } else {
380
            if (!entities.get().contains(entity.getType())) return null;
381
382
            alpha = getFadeAlpha(entity);
383
            if (alpha == 0) return null;
384
385
            color = getEntityTypeColor(entity);
386
        }
387
388
        return baseColor.set(color.r, color.g, color.b, (int) (color.a * alpha));
389
    }
390
391
    private double getFadeAlpha(Entity entity) {
392
        double dist = PlayerUtils.squaredDistanceToCamera(entity.getX(), entity.getY() + entity.getEyeHeight(entity.getPose()), entity.getZ());
393
        double fadeDist = Math.pow(fadeDistance.get(), 2);
394
        double alpha = 1;
395
        if (dist <= fadeDist * fadeDist) alpha = (float) (Math.sqrt(dist) / fadeDist);
396
        if (alpha <= 0.075) alpha = 0;
397
        return alpha;
398
    }
399
400
    public Color getEntityTypeColor(Entity entity) {
401
        if (colorMode.get() == ESPColorMode.EntityType) {
402
            if (entity instanceof Player player) {
403
                return PlayerUtils.getPlayerColor(player, playersColor.get());
404
            } else {
405
                return switch (entity.getType().getCategory()) {
406
                    case CREATURE -> animalsColor.get();
407
                    case WATER_AMBIENT, WATER_CREATURE, UNDERGROUND_WATER_CREATURE, AXOLOTLS -> waterAnimalsColor.get();
408
                    case MONSTER -> monstersColor.get();
409
                    case AMBIENT -> ambientColor.get();
410
                    default -> miscColor.get();
411
                };
412
            }
413
        }
414
415
        if (friendOverride.get() && entity instanceof Player player
416
            && Friends.get().isFriend(player)) {
417
            return Config.get().friendColor.get();
418
        }
419
420
        if (colorMode.get() == ESPColorMode.Health)
421
            return EntityUtils.getColorFromHealth(entity, nonLivingEntityColor.get());
422
        else return EntityUtils.getColorFromDistance(entity);
423
    }
424
425
    @Override
426
    public String getInfoString() {
427
        return Integer.toString(count);
428
    }
429
430
    public boolean isShader() {
431
        return isActive() && mode.get() == Mode.Shader;
432
    }
433
434
    public boolean isGlow() {
435
        return isActive() && mode.get() == Mode.Glow;
436
    }
437
438
    public enum ESPColorMode {
439
        EntityType,
440
        Distance,
441
        Health;
442
443
        @Override
444
        public String toString() {
445
            return this == EntityType ? "Entity Type" : super.toString();
446
        }
447
    }
448
449
    public enum Mode {
450
        Box,
451
        Wireframe,
452
        _2D,
453
        Shader,
454
        Glow;
455
456
        @Override
457
        public String toString() {
458
            return this == _2D ? "2D" : super.toString();
459
        }
460
    }
461
}
462
MelaHack (ThunderHack fork)RENDERsrc/main/java/thunder/hack/features/modules/render/ESP.javaJava · 481 lines · 30.5 KB

Highlights specific entities.

SettingsLingeringPotionsTNTFuseTNTRangeTNTFuseTextTNTRadiusTNTSphereColorBeaconRadiusKeepYSphereColorBeakonColorBurrowBurrowTextColorBurrowColorPearlsDizorentRadiusDizorentColorBoxPlayersFriendsCrystalsCreaturesMonstersAmbientsOthersOutlineColorModerenderHealthhealthOutlineBoxColorsBoxOutlinePlayersCFriendsCCrystalsCCreaturesCMonstersCAmbientsCOthersChealthBhealthUhealthBG
ESP.javaJava · Minecraft 26.2 · 481 lines · 30.5 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
import com.mojang.math.Axis;
9
import thunder.hack.utility.render.compat.RenderSystem;
10
import net.minecraft.client.Camera;
11
import thunder.hack.utility.render.ShaderProgramKeys;
12
import net.minecraft.client.gui.GuiGraphicsExtractor;
13
import thunder.hack.utility.render.BufferRenderer;
14
import net.minecraft.core.*;
15
import net.minecraft.core.particles.ColorParticleOption;
16
import net.minecraft.core.particles.ParticleOptions;
17
import net.minecraft.world.entity.AreaEffectCloud;
18
import net.minecraft.world.entity.Entity;
19
import net.minecraft.world.entity.LivingEntity;
20
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
21
import net.minecraft.world.entity.item.PrimedTnt;
22
import net.minecraft.world.entity.player.Player;
23
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEnderpearl;
24
import net.minecraft.world.item.Items;
25
import net.minecraft.world.level.block.Block;
26
import net.minecraft.world.level.block.Blocks;
27
import net.minecraft.world.level.block.entity.BeaconBlockEntity;
28
import net.minecraft.world.level.block.entity.BlockEntity;
29
import net.minecraft.world.phys.*;
30
import org.jetbrains.annotations.NotNull;
31
import org.joml.Matrix4f;
32
import org.joml.Vector4d;
33
import thunder.hack.core.Managers;
34
import thunder.hack.gui.font.FontRenderers;
35
import thunder.hack.injection.accesors.IAreaEffectCloudEntity;
36
import thunder.hack.injection.accesors.IBeaconBlockEntity;
37
import thunder.hack.features.modules.Module;
38
import thunder.hack.features.modules.client.HudEditor;
39
import thunder.hack.setting.Setting;
40
import thunder.hack.setting.impl.ColorSetting;
41
import thunder.hack.setting.impl.SettingGroup;
42
import thunder.hack.utility.render.Render2DEngine;
43
import thunder.hack.utility.render.Render3DEngine;
44
45
import java.awt.*;
46
47
import static thunder.hack.utility.render.animation.AnimationUtility.fast;
48
49
public class ESP extends Module {
50
    public ESP() {
51
        super("ESP", Category.RENDER);
52
    }
53
54
    private final Setting<Boolean> lingeringPotions = new Setting<>("LingeringPotions", false);
55
    private final Setting<Boolean> tntFuse = new Setting<>("TNTFuse", false);
56
    private final Setting<Float> tntrange = new Setting<>("TNTRange", 8.0f, 0f, 8f);
57
    private final Setting<ColorSetting> tntFuseText = new Setting<>("TNTFuseText", new ColorSetting(new Color(-1)), v -> tntFuse.getValue());
58
    private final Setting<Boolean> tntRadius = new Setting<>("TNTRadius", false);
59
    private final Setting<ColorSetting> tntRadiusColor = new Setting<>("TNTSphereColor", new ColorSetting(new Color(-1)), v -> tntRadius.getValue());
60
    private final Setting<Boolean> beaconRadius = new Setting<>("BeaconRadius", false);
61
    private final Setting<Boolean> keepY = new Setting<>("KeepY", false, v -> beaconRadius.getValue());
62
    private final Setting<ColorSetting> sphereColor = new Setting<>("SphereColor", new ColorSetting(new Color(-1)), v -> beaconRadius.getValue());
63
    private final Setting<ColorSetting> beakonColor = new Setting<>("BeakonColor", new ColorSetting(new Color(-1)), v -> beaconRadius.getValue());
64
    private final Setting<Boolean> burrow = new Setting<>("Burrow", false);
65
    private final Setting<ColorSetting> burrowTextColor = new Setting<>("BurrowTextColor", new ColorSetting(new Color(-1)), v -> burrow.getValue());
66
    private final Setting<ColorSetting> burrowColor = new Setting<>("BurrowColor", new ColorSetting(new Color(-1)), v -> burrow.getValue());
67
    private final Setting<Boolean> pearls = new Setting<>("Pearls", false);
68
    private final Setting<Boolean> dizorentRadius = new Setting<>("DizorentRadius", true);
69
    private final Setting<ColorSetting> dizorentColor = new Setting<>("DizorentColor", new ColorSetting(new Color(0xB300F1CC, true)), v -> dizorentRadius.getValue());
70
71
    private final Setting<SettingGroup> boxEsp = new Setting<>("Box", new SettingGroup(false, 0));
72
    private final Setting<Boolean> players = new Setting<>("Players", true).addToGroup(boxEsp);
73
    private final Setting<Boolean> friends = new Setting<>("Friends", true).addToGroup(boxEsp);
74
    private final Setting<Boolean> crystals = new Setting<>("Crystals", true).addToGroup(boxEsp);
75
    private final Setting<Boolean> creatures = new Setting<>("Creatures", false).addToGroup(boxEsp);
76
    private final Setting<Boolean> monsters = new Setting<>("Monsters", false).addToGroup(boxEsp);
77
    private final Setting<Boolean> ambients = new Setting<>("Ambients", false).addToGroup(boxEsp);
78
    private final Setting<Boolean> others = new Setting<>("Others", false).addToGroup(boxEsp);
79
    private final Setting<Boolean> outline = new Setting<>("Outline", true).addToGroup(boxEsp);
80
    private final Setting<Colors> colorMode = new Setting<>("ColorMode", Colors.SyncColor).addToGroup(boxEsp);
81
    private final Setting<Boolean> renderHealth = new Setting<>("renderHealth", true).addToGroup(boxEsp);
82
    private final Setting<Boolean> healthOutline = new Setting<>("healthOutline", true).addToGroup(boxEsp);
83
84
    private final Setting<SettingGroup> boxColors = new Setting<>("BoxColors", new SettingGroup(false, 0));
85
    private final Setting<ColorSetting> boxOutline = new Setting<>("BoxOutline", new ColorSetting(new Color(0x000000))).addToGroup(boxColors);
86
    private final Setting<ColorSetting> playersC = new Setting<>("PlayersC", new ColorSetting(new Color(0xFF9200))).addToGroup(boxColors);
87
    private final Setting<ColorSetting> friendsC = new Setting<>("FriendsC", new ColorSetting(new Color(0x30FF00))).addToGroup(boxColors);
88
    private final Setting<ColorSetting> crystalsC = new Setting<>("CrystalsC", new ColorSetting(new Color(0x00BBFF))).addToGroup(boxColors);
89
    private final Setting<ColorSetting> creaturesC = new Setting<>("CreaturesC", new ColorSetting(new Color(0xA0A4A6))).addToGroup(boxColors);
90
    private final Setting<ColorSetting> monstersC = new Setting<>("MonstersC", new ColorSetting(new Color(0xFF0000))).addToGroup(boxColors);
91
    private final Setting<ColorSetting> ambientsC = new Setting<>("AmbientsC", new ColorSetting(new Color(0x7B00FF))).addToGroup(boxColors);
92
    private final Setting<ColorSetting> othersC = new Setting<>("OthersC", new ColorSetting(new Color(0xFF0062))).addToGroup(boxColors);
93
    public final Setting<ColorSetting> healthB = new Setting<>("healthB", new ColorSetting(new Color(0xff1100))).addToGroup(boxColors);
94
    public final Setting<ColorSetting> healthU = new Setting<>("healthU", new ColorSetting(new Color(0x2fff00))).addToGroup(boxColors);
95
    private final Setting<ColorSetting> healthbg = new Setting<>("healthBG", new ColorSetting(new Color(0x000000))).addToGroup(boxColors);
96
    private final Setting<ColorSetting> healthOutlineC = new Setting<>("healthOutlineC", new ColorSetting(new Color(0x000000))).addToGroup(boxColors);
97
98
    private float dizorentAnimation = 0f;
99
100
    public void onRender3D(PoseStack stack) {
101
        if(false) return;
102
        if (lingeringPotions.getValue()) {
103
            for (Entity ent : mc.level.entitiesForRendering()) {
104
                if (ent instanceof AreaEffectCloud aece) {
105
                    double x = aece.getX() - mc.getEntityRenderDispatcher().camera.position().x;
106
                    double y = aece.getY() - mc.getEntityRenderDispatcher().camera.position().y;
107
                    double z = aece.getZ() - mc.getEntityRenderDispatcher().camera.position().z;
108
109
                    float middle = aece.getRadius();
110
111
                    stack.pushPose();
112
                    stack.translate(x, y, z);
113
114
                    Render3DEngine.setupRender();
115
                    RenderSystem.disableDepthTest();
116
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
117
                    BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
118
119
                    for (int i = 0; i <= 360; i += 6) {
120
                        double v = Math.sin(Math.toRadians(i));
121
                        double u = Math.cos(Math.toRadians(i));
122
                        bufferBuilder.addVertex(stack.last().pose(), (float) u * middle, (float) 0, (float) v * middle).setColor(Render2DEngine.injectAlpha(new Color(getAreaCloudColor(aece)), 100).getRGB());
123
                        bufferBuilder.addVertex(stack.last().pose(), 0, 0, 0).setColor(Render2DEngine.injectAlpha(new Color(getAreaCloudColor(aece)), 0).getRGB());
124
                    }
125
                    Render2DEngine.endBuilding(bufferBuilder);
126
127
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
128
                    bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
129
                    for (int i = 0; i <= 360; i += 6) {
130
                        double v = Math.sin(Math.toRadians(i));
131
                        double u = Math.cos(Math.toRadians(i));
132
                        bufferBuilder.addVertex(stack.last().pose(), (float) u * middle, (float) 0, (float) v * middle).setColor(Render2DEngine.injectAlpha(new Color(getAreaCloudColor(aece)), 255).getRGB());
133
                        bufferBuilder.addVertex(stack.last().pose(), (float) u * (middle - 0.04f), (float) 0, (float) v * (middle - 0.04f)).setColor(Render2DEngine.injectAlpha(new Color(getAreaCloudColor(aece)), 255).getRGB());
134
                    }
135
                    Render2DEngine.endBuilding(bufferBuilder);
136
137
                    Render3DEngine.endRender();
138
                    RenderSystem.enableDepthTest();
139
                    stack.translate(-x, -y, -z);
140
                    stack.popPose();
141
142
                    RenderSystem.disableDepthTest();
143
                    PoseStack matrices = new PoseStack();
144
                    Camera camera = mc.gameRenderer.mainCamera();
145
                    matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
146
                    matrices.mulPose(Axis.YP.rotationDegrees(camera.yRot() + 180.0F));
147
                    matrices.translate(x, y, z);
148
                    matrices.mulPose(Axis.YP.rotationDegrees(-camera.yRot()));
149
                    matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
150
                    RenderSystem.enableBlend();
151
                    RenderSystem.defaultBlendFunc();
152
                    matrices.translate(0, 0, 0);
153
                    matrices.scale(-0.05f, -0.05f, 0);
154
                    FontRenderers.modules.drawCenteredString(matrices, String.format("%.1f", ((aece.getRadius() * 10) - 5f)), 0, -10f, -1);
155
                    RenderSystem.disableBlend();
156
                    RenderSystem.enableDepthTest();
157
                }
158
            }
159
        }
160
161
        if (dizorentRadius.getValue()) {
162
            dizorentAnimation = fast(dizorentAnimation, mc.player.getMainHandItem().getItem() == Items.ENDER_EYE ? 10 : 0, 15f);
163
164
            if (mc.player.getMainHandItem().getItem() == Items.ENDER_EYE) {
165
                double x = Render2DEngine.interpolate(mc.player.xo, mc.player.getX(), Render3DEngine.getTickDelta()) - mc.getEntityRenderDispatcher().camera.position().x;
166
                double y = Render2DEngine.interpolate(mc.player.yo, mc.player.getY(), Render3DEngine.getTickDelta()) - mc.getEntityRenderDispatcher().camera.position().y;
167
                double z = Render2DEngine.interpolate(mc.player.zo, mc.player.getZ(), Render3DEngine.getTickDelta()) - mc.getEntityRenderDispatcher().camera.position().z;
168
169
170
                stack.pushPose();
171
                stack.translate(x, y, z);
172
173
                Render3DEngine.setupRender();
174
                RenderSystem.disableDepthTest();
175
                RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
176
                BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
177
178
                for (int i = 0; i <= 360; i += 6) {
179
                    double v = Math.sin(Math.toRadians(i));
180
                    double u = Math.cos(Math.toRadians(i));
181
                    bufferBuilder.addVertex(stack.last().pose(), (float) u * dizorentAnimation, (float) 0, (float) v * dizorentAnimation).setColor(Render2DEngine.injectAlpha(new Color(dizorentColor.getValue().getColor()), 100).getRGB());
182
                    bufferBuilder.addVertex(stack.last().pose(), 0, 0, 0).setColor(Render2DEngine.injectAlpha(new Color(dizorentColor.getValue().getColor()), 0).getRGB());
183
                }
184
                Render2DEngine.endBuilding(bufferBuilder);
185
186
                RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
187
                bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
188
                for (int i = 0; i <= 360; i += 6) {
189
                    double v = Math.sin(Math.toRadians(i));
190
                    double u = Math.cos(Math.toRadians(i));
191
                    bufferBuilder.addVertex(stack.last().pose(), (float) u * dizorentAnimation, (float) 0, (float) v * dizorentAnimation).setColor(Render2DEngine.injectAlpha(new Color(dizorentColor.getValue().getColor()), 255).getRGB());
192
                    bufferBuilder.addVertex(stack.last().pose(), (float) u * (dizorentAnimation - 0.04f), (float) 0, (float) v * (dizorentAnimation - 0.04f)).setColor(Render2DEngine.injectAlpha(new Color(dizorentColor.getValue().getColor()), 255).getRGB());
193
                }
194
                Render2DEngine.endBuilding(bufferBuilder);
195
196
                Render3DEngine.endRender();
197
                RenderSystem.enableDepthTest();
198
                stack.translate(-x, -y, -z);
199
                stack.popPose();
200
201
                for (Player pl : Managers.ASYNC.getAsyncPlayers()) {
202
                    if (mc.player.distanceToSqr(pl.position()) > 100 || pl == mc.player)
203
                        continue;
204
                    Render3DEngine.drawTargetEsp(stack, pl);
205
                }
206
            }
207
        }
208
209
        if (beaconRadius.getValue()) {
210
            for (BlockEntity be : StorageEsp.getBlockEntities()) {
211
                if (be instanceof BeaconBlockEntity bbe) {
212
                    double x = be.getBlockPos().getX() - mc.getEntityRenderDispatcher().camera.position().x;
213
                    double y = be.getBlockPos().getY() - mc.getEntityRenderDispatcher().camera.position().y;
214
                    double z = be.getBlockPos().getZ() - mc.getEntityRenderDispatcher().camera.position().z;
215
216
                    Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(new AABB(be.getBlockPos()), beakonColor.getValue().getColorObject(), 2));
217
                    float range = ((IBeaconBlockEntity) bbe).getLevel() * 10 + 11;
218
219
                    boolean ky = keepY.getValue();
220
221
                    stack.pushPose();
222
                    stack.translate(x,  ky ? -10 : y, z);
223
                    Render3DEngine.drawCylinder(stack, range, ky ? 20 : 256, 20, ky ? 5 : 20, sphereColor.getValue().getColor());
224
                    stack.translate(-x, ky ? 10 : y, -z);
225
                    stack.popPose();
226
                }
227
            }
228
        }
229
230
        if (burrow.getValue()) {
231
            for (Player pl : mc.level.players()) {
232
                BlockPos blockPos = BlockPos.containing(pl.position().add(0,0.15f,0));
233
                Block block = mc.level.getBlockState(blockPos).getBlock();
234
235
                double x = blockPos.getX() - mc.getEntityRenderDispatcher().camera.position().x;
236
                double y = blockPos.getY() - mc.getEntityRenderDispatcher().camera.position().y;
237
                double z = blockPos.getZ() - mc.getEntityRenderDispatcher().camera.position().z;
238
239
                if (block == Blocks.OBSIDIAN
240
                        || block == Blocks.CRYING_OBSIDIAN
241
                        || block == Blocks.ANVIL
242
                        || block == Blocks.PLAYER_HEAD
243
                        || block == Blocks.SKELETON_SKULL
244
                        || block == Blocks.WITHER_SKELETON_SKULL) {
245
                    Render3DEngine.OUTLINE_QUEUE.add(new Render3DEngine.OutlineAction(new AABB(blockPos), burrowColor.getValue().getColorObject(), 2));
246
                    RenderSystem.disableDepthTest();
247
                    PoseStack matrices = new PoseStack();
248
                    Camera camera = mc.gameRenderer.mainCamera();
249
                    matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
250
                    matrices.mulPose(Axis.YP.rotationDegrees(camera.yRot() + 180.0F));
251
                    matrices.translate(x + 0.5f, y + 0.5f, z + 0.5f);
252
                    matrices.mulPose(Axis.YP.rotationDegrees(-camera.yRot()));
253
                    matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
254
                    RenderSystem.enableBlend();
255
                    RenderSystem.defaultBlendFunc();
256
                    matrices.translate(0, 0, 0);
257
                    matrices.scale(-0.025f, -0.025f, 0);
258
                    FontRenderers.modules.drawCenteredString(matrices, "BURROW", 0, -5, burrowTextColor.getValue().getColor());
259
                    RenderSystem.disableBlend();
260
                    RenderSystem.enableDepthTest();
261
                }
262
            }
263
        }
264
265
        if (tntFuse.getValue() || tntRadius.getValue()) {
266
            for (Entity ent : mc.level.entitiesForRendering()) {
267
                if (ent instanceof PrimedTnt tnt) {
268
                    double x = tnt.xo + (tnt.position().x - tnt.xo) * Render3DEngine.getTickDelta() - mc.getEntityRenderDispatcher().camera.position().x;
269
                    double y = tnt.yo + (tnt.position().y - tnt.yo) * Render3DEngine.getTickDelta() - mc.getEntityRenderDispatcher().camera.position().y;
270
                    double z = tnt.zo + (tnt.position().z - tnt.zo) * Render3DEngine.getTickDelta() - mc.getEntityRenderDispatcher().camera.position().z;
271
272
                    if (tntFuse.getValue()) {
273
                        RenderSystem.disableDepthTest();
274
                        PoseStack matrices = new PoseStack();
275
                        Camera camera = mc.gameRenderer.mainCamera();
276
                        matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
277
                        matrices.mulPose(Axis.YP.rotationDegrees(camera.yRot() + 180.0F));
278
                        matrices.translate(x, y + 0.5f, z);
279
                        matrices.mulPose(Axis.YP.rotationDegrees(-camera.yRot()));
280
                        matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
281
                        RenderSystem.enableBlend();
282
                        RenderSystem.defaultBlendFunc();
283
                        matrices.translate(0, 0, 0);
284
                        matrices.scale(-0.025f, -0.025f, 0);
285
                        FontRenderers.modules.drawCenteredString(matrices, String.format("%.1f", ((float) tnt.getFuse() / 20f)) + "s", 0, -5, tntFuseText.getValue().getColor());
286
                        RenderSystem.disableBlend();
287
                        RenderSystem.enableDepthTest();
288
                    }
289
290
                    if (tntRadius.getValue()) {
291
                        stack.pushPose();
292
                        stack.translate(x, y, z);
293
                        Render3DEngine.drawSphere(stack, tntrange.getValue(), 20, 20, tntRadiusColor.getValue().getColor());
294
                        stack.translate(-x, -y, -z);
295
                        stack.popPose();
296
                    }
297
                }
298
            }
299
        }
300
    }
301
302
    public void onRender2D(GuiGraphicsExtractor context) {
303
        if(false) return;
304
        if (pearls.getValue()) {
305
            for (Entity ent : mc.level.entitiesForRendering()) {
306
                if (ent instanceof ThrownEnderpearl pearl) {
307
                    float xOffset = mc.getWindow().getGuiScaledWidth() / 2f;
308
                    float yOffset = mc.getWindow().getGuiScaledHeight() / 2f;
309
310
                    float xPos = (float) (pearl.xo + (pearl.position().x - pearl.xo) * Render3DEngine.getTickDelta());
311
                    float zPos = (float) (pearl.zo + (pearl.position().z - pearl.zo) * Render3DEngine.getTickDelta());
312
313
                    float yaw = getRotations(new Vec2(xPos, zPos)) - mc.player.getYRot();
314
                    context.pose().translate((float) (xOffset), (float) (yOffset));
315
                    context.pose().rotate((float) Math.toRadians(yaw));
316
                    context.pose().translate((float) (-xOffset), (float) (-yOffset));
317
                    Render2DEngine.drawTracerPointer(context.pose(), xOffset, yOffset - 50, 12.5f, 0.5f, 3.63f, true, true, HudEditor.getColor(1).getRGB());
318
                    context.pose().translate((float) (xOffset), (float) (yOffset));
319
                    context.pose().rotate((float) Math.toRadians(-yaw));
320
                    context.pose().translate((float) (-xOffset), (float) (-yOffset));
321
                    RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
322
                    FontRenderers.modules.drawCenteredString(context.pose(), String.format("%.1f", mc.player.distanceTo(pearl)) + "m", (float) (Math.sin(Math.toRadians(yaw)) * 50f) + xOffset, (float) (yOffset - (Math.cos(Math.toRadians(yaw)) * 50f)) - 20, -1);
323
                }
324
            }
325
        }
326
327
        Matrix4f matrix = thunder.hack.utility.render.GuiMatrix.positionMatrix(context.pose());
328
        Render2DEngine.setupRender();
329
        RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
330
        BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_COLOR);
331
332
        for (Entity ent : mc.level.entitiesForRendering())
333
            if (shouldRender(ent))
334
                drawBox(bufferBuilder, ent, matrix);
335
336
        Render2DEngine.endBuilding(bufferBuilder);
337
        Render2DEngine.endRender();
338
    }
339
340
    public boolean shouldRender(Entity entity) {
341
        if (entity == null)
342
            return false;
343
344
        if (mc.player == null)
345
            return false;
346
347
        if (entity instanceof Player) {
348
            if (entity == mc.player)
349
                return false;
350
            if (Managers.FRIEND.isFriend((Player) entity))
351
                return friends.getValue();
352
            return players.getValue();
353
        }
354
355
        if (entity instanceof EndCrystal)
356
            return crystals.getValue();
357
358
        return switch (entity.getType().getCategory()) {
359
            case CREATURE, WATER_CREATURE -> creatures.getValue();
360
            case MONSTER -> monsters.getValue();
361
            case AMBIENT, WATER_AMBIENT -> ambients.getValue();
362
            default -> others.getValue();
363
        };
364
    }
365
366
    public Color getEntityColor(Entity entity) {
367
        if (entity == null)
368
            return new Color(-1);
369
370
        if (entity instanceof Player) {
371
            if (Managers.FRIEND.isFriend((Player) entity))
372
                return friendsC.getValue().getColorObject();
373
            return playersC.getValue().getColorObject();
374
        }
375
376
        if (entity instanceof EndCrystal)
377
            return crystalsC.getValue().getColorObject();
378
379
        return switch (entity.getType().getCategory()) {
380
            case CREATURE, WATER_CREATURE -> creaturesC.getValue().getColorObject();
381
            case MONSTER -> monstersC.getValue().getColorObject();
382
            case AMBIENT, WATER_AMBIENT -> ambientsC.getValue().getColorObject();
383
            default -> othersC.getValue().getColorObject();
384
        };
385
    }
386
387
    public void drawBox(BufferBuilder bufferBuilder, @NotNull Entity ent, Matrix4f matrix) {
388
        Vec3[] vectors = getVectors(ent);
389
390
        Color col = getEntityColor(ent);
391
392
        Vector4d position = null;
393
        for (Vec3 vector : vectors) {
394
            vector = Render3DEngine.worldSpaceToScreenSpace(new Vec3(vector.x, vector.y, vector.z));
395
            if (vector.z > 0 && vector.z < 1) {
396
                if (position == null) position = new Vector4d(vector.x, vector.y, vector.z, 0);
397
                position.x = Math.min(vector.x, position.x);
398
                position.y = Math.min(vector.y, position.y);
399
                position.z = Math.max(vector.x, position.z);
400
                position.w = Math.max(vector.y, position.w);
401
            }
402
        }
403
404
405
        if (position != null) {
406
            double posX = position.x;
407
            double posY = position.y;
408
            double endPosX = position.z;
409
            double endPosY = position.w;
410
411
            if (outline.getValue()) {
412
                // ебаный пиздец
413
                Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 1F), (float) posY, (float) (posX + 0.5), (float) (endPosY + 0.5), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject());
414
                Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 1F), (float) (posY - 0.5), (float) (endPosX + 0.5), (float) (posY + 0.5 + 0.5), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject());
415
                Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (endPosX - 0.5 - 0.5), (float) posY, (float) (endPosX + 0.5), (float) (endPosY + 0.5), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject());
416
                Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 1), (float) (endPosY - 0.5 - 0.5), (float) (endPosX + 0.5), (float) (endPosY + 0.5), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject(), boxOutline.getValue().getColorObject());
417
            }
418
419
            switch (colorMode.getValue()) {
420
                case Custom -> {
421
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 0.5f), (float) posY, (float) (posX + 0.5 - 0.5), (float) endPosY, col, col, col, col);
422
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) posX, (float) (endPosY - 0.5f), (float) endPosX, (float) endPosY, col, col, col, col);
423
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 0.5), (float) posY, (float) endPosX, (float) (posY + 0.5), col, col, col, col);
424
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (endPosX - 0.5), (float) posY, (float) endPosX, (float) endPosY, col, col, col, col);
425
                }
426
                case SyncColor -> {
427
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 0.5f), (float) posY, (float) (posX + 0.5 - 0.5), (float) endPosY, HudEditor.getColor(270), HudEditor.getColor(0), HudEditor.getColor(0), HudEditor.getColor(270));
428
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) posX, (float) (endPosY - 0.5f), (float) endPosX, (float) endPosY, HudEditor.getColor(0), HudEditor.getColor(180), HudEditor.getColor(180), HudEditor.getColor(0));
429
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 0.5), (float) posY, (float) endPosX, (float) (posY + 0.5), HudEditor.getColor(180), HudEditor.getColor(90), HudEditor.getColor(90), HudEditor.getColor(180));
430
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (endPosX - 0.5), (float) posY, (float) endPosX, (float) endPosY, HudEditor.getColor(90), HudEditor.getColor(270), HudEditor.getColor(270), HudEditor.getColor(90));
431
                }
432
            }
433
434
435
            if (ent instanceof LivingEntity lent && lent.getHealth() != 0 && renderHealth.getValue()) {
436
437
                if (healthOutline.getValue())
438
                    Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 5.5), (float) (posY - 0.5), (float) (posX - 2.5), (float) (endPosY + 0.5), healthOutlineC.getValue().getColorObject(), healthOutlineC.getValue().getColorObject(), healthOutlineC.getValue().getColorObject(), healthOutlineC.getValue().getColorObject());
439
440
                Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 5), (float) posY, (float) posX - 3, (float) endPosY, healthbg.getValue().getColorObject(), healthbg.getValue().getColorObject(), healthbg.getValue().getColorObject(), healthbg.getValue().getColorObject());
441
442
                switch (colorMode.getValue()) {
443
                    case Custom ->
444
                            Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 5), (float) (endPosY + (posY - endPosY) * lent.getHealth() / lent.getMaxHealth()), (float) posX - 3, (float) endPosY, healthB.getValue().getColorObject(), healthB.getValue().getColorObject(), healthU.getValue().getColorObject(), healthU.getValue().getColorObject());
445
                    case SyncColor ->
446
                            Render2DEngine.setRectPoints(bufferBuilder, matrix, (float) (posX - 5), (float) (endPosY + (posY - endPosY) * lent.getHealth() / lent.getMaxHealth()), (float) posX - 3, (float) endPosY, HudEditor.getColor(90), HudEditor.getColor(90), HudEditor.getColor(270), HudEditor.getColor(270));
447
                }
448
            }
449
        }
450
    }
451
452
    @NotNull
453
    private static Vec3[] getVectors(@NotNull Entity ent) {
454
        double x = ent.xo + (ent.getX() - ent.xo) * Render3DEngine.getTickDelta();
455
        double y = ent.yo + (ent.getY() - ent.yo) * Render3DEngine.getTickDelta();
456
        double z = ent.zo + (ent.getZ() - ent.zo) * Render3DEngine.getTickDelta();
457
        AABB axisAlignedBB2 = ent.getBoundingBox();
458
        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);
459
        return 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)};
460
    }
461
462
    private int getAreaCloudColor(AreaEffectCloud ent) {
463
        ParticleOptions particleEffect = ent.getParticle();
464
        if (particleEffect instanceof ColorParticleOption effect) {
465
            return ((IAreaEffectCloudEntity)ent).getPotionContentsComponent().getColor();
466
        }
467
        return -1;
468
    }
469
470
    public static float getRotations(Vec2 vec) {
471
        if (mc.player == null) return 0;
472
        double x = vec.x - mc.player.position().x;
473
        double z = vec.y - mc.player.position().z;
474
        return (float) -(Math.atan2(x, z) * (180 / Math.PI));
475
    }
476
477
    public enum Colors {
478
        SyncColor, Custom
479
    }
480
}
481
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/Esp.javaJava · 270 lines · 12.0 KB

See entities through walls.

SettingsStyleBox sizeAlso glowTracersIgnore sleepingIgnore invisibleIgnore petsArmour standsNeutral mobsSelfRangeNear fadeHighlight targetTarget colourTarget hitboxHitbox colour
Esp.javaJava · Minecraft 26.2 · 270 lines · 12.0 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.Render2DEvent;
5
import com.jellypudding.offlineclient.event.events.Render3DEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.modules.combat.Hitboxes;
9
import com.jellypudding.offlineclient.render.BoxStyle;
10
import com.jellypudding.offlineclient.render.DrawBatch;
11
import com.jellypudding.offlineclient.render.WireframeRenderer;
12
import com.jellypudding.offlineclient.render.WorldToScreen;
13
import com.jellypudding.offlineclient.setting.BoolSetting;
14
import com.jellypudding.offlineclient.setting.ColorSetting;
15
import com.jellypudding.offlineclient.setting.EnumSetting;
16
import com.jellypudding.offlineclient.setting.NumberSetting;
17
import com.jellypudding.offlineclient.util.ColorUtil;
18
import com.jellypudding.offlineclient.util.EntityColors;
19
import com.jellypudding.offlineclient.util.EntityFilter;
20
import com.jellypudding.offlineclient.util.EntityUtil;
21
import com.jellypudding.offlineclient.util.Modules;
22
import net.minecraft.client.gui.GuiGraphicsExtractor;
23
import net.minecraft.world.entity.Entity;
24
import net.minecraft.world.entity.EntityTypes;
25
import net.minecraft.world.entity.Mob;
26
import net.minecraft.world.entity.decoration.ArmorStand;
27
import net.minecraft.world.entity.player.Player;
28
import net.minecraft.world.phys.AABB;
29
import net.minecraft.world.phys.Vec3;
30
31
import java.util.List;
32
33
public final class Esp extends Module {
34
35
    public enum Style { BOXES, WIREFRAME, FLAT, GLOW }
36
37
    public enum Size { ACCURATE, FANCY }
38
39
    public enum Neutral { ALWAYS, WHEN_ANGRY, NEVER }
40
41
    // How much a fancy box grows on every side and how far it lifts.
42
    private static final double FANCY_GROW = 0.05;
43
44
    private final EnumSetting<Style> style = new EnumSetting<>("Style",
45
        "How the entities are marked.", Style.BOXES)
46
        .describe(Style.BOXES, "A box round each one.")
47
        .describe(Style.WIREFRAME, "The shape of the model itself drawn as boxes.")
48
        .describe(Style.FLAT, "A flat rectangle on the screen round each one.")
49
        .describe(Style.GLOW, "The vanilla glow effect.");
50
    private final BoxStyle shape = BoxStyle.shapeOnly(BoxStyle.Shape.LINES);
51
    private final EnumSetting<Size> size = new EnumSetting<>("Box size",
52
        "How big the box around an entity is.", Size.FANCY)
53
        .describe(Size.ACCURATE, "The hitbox itself.")
54
        .describe(Size.FANCY, "A little larger and lifted so it sits clear of the model.")
55
        .under(style, Style.BOXES, Style.WIREFRAME, Style.FLAT);
56
    private final BoolSetting alsoGlow = new BoolSetting("Also glow",
57
        "Add the vanilla glow on top of the boxes.", false)
58
        .under(style, Style.BOXES, Style.WIREFRAME, Style.FLAT);
59
    private final BoolSetting tracers = new BoolSetting("Tracers",
60
        "Also draws a line from you to each one.", false);
61
    private final EntityFilter filter = new EntityFilter("Highlight", "highlighted", true,
62
        EntityFilter.Pick.NONE, EntityFilter.Pick.NONE, List.of(EntityTypes.END_CRYSTAL));
63
    private final BoolSetting ignoreSleeping = new BoolSetting("Ignore sleeping",
64
        "Players lying in a bed get nothing.", false);
65
    private final BoolSetting ignoreInvisible = new BoolSetting("Ignore invisible",
66
        "Invisible entities get nothing.", false);
67
    private final BoolSetting ignorePets = new BoolSetting("Ignore pets",
68
        "Tamed and saddled and trusting animals get nothing.", false);
69
    private final BoolSetting armourStands = new BoolSetting("Armour stands",
70
        "Also mark armour stands.", true);
71
    private final EnumSetting<Neutral> neutral = new EnumSetting<>("Neutral mobs",
72
        "Endermen and piglins and wolves and the like.", Neutral.ALWAYS)
73
        .describe(Neutral.ALWAYS, "Mark them like any other mob.")
74
        .describe(Neutral.WHEN_ANGRY, "Only mark them once they are angry.")
75
        .describe(Neutral.NEVER, "Leave them out.");
76
    private final BoolSetting self = new BoolSetting("Self",
77
        "Also mark your own body in third person.", false);
78
    private final NumberSetting range = new NumberSetting("Range",
79
        "Furthest an entity can be and still show.", 128, 16, 256, 8, " blocks").min(1);
80
    private final NumberSetting nearFade = new NumberSetting("Near fade",
81
        "Entities closer than this to the camera fade out so a box does not fill your screen.",
82
        3, 0, 12, 0.5, " blocks").min(0).max(32);
83
    private final BoolSetting highlightTarget = new BoolSetting("Highlight target",
84
        "The entity under your crosshair gets its own colour even if its kind is not picked.", false);
85
    private final ColorSetting targetColor = new ColorSetting("Target colour",
86
        "Colour of the entity under your crosshair.", 0, 0f, 0.8f, false)
87
        .under(highlightTarget);
88
    private final BoolSetting targetHitbox = new BoolSetting("Target hitbox",
89
        "Draw the hitbox of the entity under your crosshair as lines.", true)
90
        .under(highlightTarget);
91
    private final ColorSetting hitboxColor = new ColorSetting("Hitbox colour",
92
        "Colour of that hitbox.", 180, 0.5f, 0.8f, false)
93
        .under(targetHitbox);
94
    private final EntityColors colors = new EntityColors(EntityColors.Mode.TYPE);
95
96
    public Esp() {
97
        super("ESP", "See entities through walls.", Category.RENDER);
98
        addSettings(style);
99
        addSettings(shape.settings());
100
        addSettings(size, alsoGlow, tracers);
101
        addSettings(filter.settings());
102
        addSettings(ignoreSleeping, ignoreInvisible, ignorePets, armourStands, neutral, self,
103
            range, nearFade, highlightTarget, targetColor, targetHitbox, hitboxColor);
104
        addSettings(colors.settings());
105
        searchTags("crystal esp", "wallhack", "boxes", "wireframe");
106
    }
107
108
    @Override
109
    public String getSuffix() {
110
        return style.getValueString();
111
    }
112
113
    @Subscribe
114
    private void onRender3D(Render3DEvent event) {
115
        boolean shapes = style.isAny(Style.BOXES, Style.WIREFRAME);
116
        if (!inGame() || (!shapes && !tracers.isOn() && !highlightTarget.isOn())) {
117
            return;
118
        }
119
        DrawBatch batch = event.getBatch();
120
        Hitboxes hitboxes = Modules.get(Hitboxes.class);
121
        float partial = event.getPartialTicks();
122
        for (Entity entity : mc.level.entitiesForRendering()) {
123
            boolean target = isTarget(entity);
124
            if (!target && !matches(entity)) {
125
                continue;
126
            }
127
            int line = fadedColor(entity, target);
128
            int fill = ColorUtil.fade(line, shape.fillShare());
129
            AABB box = grownBox(entity, partial, hitboxes);
130
            if (style.is(Style.WIREFRAME)) {
131
                WireframeRenderer.draw(batch, entity, partial, shape, line, fill, true);
132
            } else if (style.is(Style.BOXES)) {
133
                shape.draw(batch, box, line, fill, true);
134
            }
135
            if (target && targetHitbox.isOn()) {
136
                batch.outlineBox(EntityUtil.lerpedBox(entity, partial), hitboxColor.getColor(), true);
137
            }
138
            if (tracers.isOn()) {
139
                batch.tracer(box.getCenter(), line, true);
140
            }
141
        }
142
    }
143
144
    // A rectangle round the projected corners of each box.
145
    @Subscribe
146
    private void onRender2D(Render2DEvent event) {
147
        if (!style.is(Style.FLAT) || !inGame() || !WorldToScreen.update()) {
148
            return;
149
        }
150
        Hitboxes hitboxes = Modules.get(Hitboxes.class);
151
        float partial = event.getPartialTicks();
152
        for (Entity entity : mc.level.entitiesForRendering()) {
153
            boolean target = isTarget(entity);
154
            if (!target && !matches(entity)) {
155
                continue;
156
            }
157
            double[] bounds = screenBounds(grownBox(entity, partial, hitboxes));
158
            if (bounds == null) {
159
                continue;
160
            }
161
            int line = fadedColor(entity, target);
162
            drawFlat(event.getContext(), bounds, line, ColorUtil.fade(line, shape.fillShare()));
163
        }
164
    }
165
166
    private void drawFlat(GuiGraphicsExtractor context, double[] bounds, int line, int fill) {
167
        int x1 = (int) Math.floor(bounds[0]);
168
        int y1 = (int) Math.floor(bounds[1]);
169
        int x2 = (int) Math.ceil(bounds[2]);
170
        int y2 = (int) Math.ceil(bounds[3]);
171
        if (shape.drawsSides()) {
172
            context.fill(x1, y1, x2, y2, fill);
173
        }
174
        if (shape.drawsLines()) {
175
            context.outline(x1, y1, x2 - x1, y2 - y1, line);
176
        }
177
    }
178
179
    // The screen rectangle that holds all eight corners or null when any sit behind the camera.
180
    private static double[] screenBounds(AABB box) {
181
        double minX = Double.MAX_VALUE;
182
        double minY = Double.MAX_VALUE;
183
        double maxX = -Double.MAX_VALUE;
184
        double maxY = -Double.MAX_VALUE;
185
        for (int i = 0; i < 8; i++) {
186
            Vec3 corner = new Vec3((i & 1) == 0 ? box.minX : box.maxX,
187
                (i & 2) == 0 ? box.minY : box.maxY, (i & 4) == 0 ? box.minZ : box.maxZ);
188
            Vec3 screen = WorldToScreen.project(corner);
189
            if (screen == null) {
190
                return null;
191
            }
192
            minX = Math.min(minX, screen.x);
193
            minY = Math.min(minY, screen.y);
194
            maxX = Math.max(maxX, screen.x);
195
            maxY = Math.max(maxY, screen.y);
196
        }
197
        return new double[] {minX, minY, maxX, maxY};
198
    }
199
200
    // Hitboxes expands the reach of a hit and a fancy box sits a little outside the model.
201
    private AABB grownBox(Entity entity, float partial, Hitboxes hitboxes) {
202
        AABB box = EntityUtil.lerpedBox(entity, partial);
203
        double grow = hitboxes == null ? 0 : hitboxes.expansionFor(entity);
204
        if (grow > 0) {
205
            box = box.inflate(grow);
206
        }
207
        return size.is(Size.ACCURATE) ? box : box.inflate(FANCY_GROW).move(0, FANCY_GROW, 0);
208
    }
209
210
    // The colour for the entity faded down as it comes close to the camera.
211
    private int fadedColor(Entity entity, boolean target) {
212
        int color = target ? targetColor.getColor() : colors.colorOf(entity);
213
        double fade = nearFade.getValue();
214
        if (fade <= 0) {
215
            return color;
216
        }
217
        double away = Math.sqrt(entity.distanceToSqr(DrawBatch.cameraPos()));
218
        return ColorUtil.fade(color, (float) Math.clamp(away / fade, 0, 1));
219
    }
220
221
    private boolean isTarget(Entity entity) {
222
        return highlightTarget.isOn() && entity == mc.crosshairPickEntity && entity != mc.player;
223
    }
224
225
    // The glow styles work through mixins that pick the targets and set the outline colour.
226
    public boolean shouldGlow(Entity entity) {
227
        return isEnabled() && (style.is(Style.GLOW) || alsoGlow.isOn()) && (matches(entity) || isTarget(entity));
228
    }
229
230
    public int glowColor(Entity entity) {
231
        return isTarget(entity) ? targetColor.getColor() : colors.colorOf(entity);
232
    }
233
234
    private boolean wantedMob(Mob mob) {
235
        if (ignorePets.isOn() && EntityUtil.isPet(mob)) {
236
            return false;
237
        }
238
        if (!EntityUtil.isNeutral(mob)) {
239
            return true;
240
        }
241
        return switch (neutral.getValue()) {
242
            case ALWAYS -> true;
243
            case WHEN_ANGRY -> !EntityUtil.isCalm(mob);
244
            case NEVER -> false;
245
        };
246
    }
247
248
    private boolean matches(Entity entity) {
249
        if (mc.player == null || mc.player.distanceTo(entity) > range.getValue()) {
250
            return false;
251
        }
252
        if (entity == mc.player) {
253
            return self.isOn() && (Modules.enabled(Freecam.class) || !mc.options.getCameraType().isFirstPerson());
254
        }
255
        if (ignoreInvisible.isOn() && entity.isInvisible()) {
256
            return false;
257
        }
258
        if (ignoreSleeping.isOn() && entity instanceof Player player && player.isSleeping()) {
259
            return false;
260
        }
261
        if (!armourStands.isOn() && entity instanceof ArmorStand) {
262
            return false;
263
        }
264
        if (entity instanceof Mob mob && !wantedMob(mob)) {
265
            return false;
266
        }
267
        return filter.matches(entity);
268
    }
269
}
270
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/ESP.javaJava · 1,617 lines · 71.4 KB
SettingsespRenderEntitiesespEntityColorespSearchEntitiesespRenderSelfespBoxModeespFrameColorSourceespFrameColorModeespFramePrimaryColorespFrameSecondaryColorespFrameColorSpeedespFrameColorPhaseespFrameColorSpreadespFrameGradientAngleespFrameGradientStrengthespShaderChamsEntitiesespShaderChamsEntityColorespHealthBarespHealthBarTargetsespHealthBarGradientespHealthBarLimitDistanceespHealthBarDistanceesp3dLineWidthesp3dGradientStrengthesp3dFillAlphaesp3dOutlineAlphaespShaderGlowEnabledespShaderGlowStrengthespShaderGlowAlphaespShaderGlowIntensityespShaderOutlineEnabledespShaderOutlineWidthespShaderOutlineAlphaespShaderOutlineIntensityespShaderFillEnabledespShaderFillStyleespShaderSmokeScaleespShaderSmokeSpeedespShaderSmokeOctavesespShaderSmokeContrastespShaderFillAlpha
ESP.javaJava · Minecraft 26.2 · 1,617 lines · 71.4 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
11
import com.mojang.blaze3d.GpuFormat;
12
import com.mojang.blaze3d.ProjectionType;
13
import com.mojang.blaze3d.buffers.GpuBufferSlice;
14
import com.mojang.blaze3d.pipeline.RenderTarget;
15
import com.mojang.blaze3d.pipeline.TextureTarget;
16
import com.mojang.blaze3d.systems.RenderSystem;
17
import com.mojang.blaze3d.textures.AddressMode;
18
import com.mojang.blaze3d.textures.FilterMode;
19
import com.mojang.blaze3d.textures.GpuSampler;
20
import com.mojang.blaze3d.textures.GpuTextureView;
21
import com.mojang.blaze3d.vertex.PoseStack;
22
import combatant.client.config.values.*;
23
import combatant.client.features.gui.hud.HudRenderSpace;
24
import combatant.client.features.module.*;
25
import combatant.client.features.module.Module;
26
import net.minecraft.client.Minecraft;
27
import net.minecraft.client.renderer.LevelRenderer;
28
import net.minecraft.client.renderer.ProjectionMatrixBuffer;
29
import net.minecraft.client.renderer.RenderBuffers;
30
import net.minecraft.client.renderer.SubmitNodeStorage;
31
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
32
import net.minecraft.client.renderer.entity.EntityRenderer;
33
import net.minecraft.client.renderer.entity.state.EntityRenderState;
34
import net.minecraft.client.renderer.feature.FeatureRenderDispatcher;
35
import net.minecraft.client.renderer.state.level.LevelRenderState;
36
import net.minecraft.core.registries.BuiltInRegistries;
37
import net.minecraft.resources.Identifier;
38
import net.minecraft.world.entity.Entity;
39
import net.minecraft.world.entity.LivingEntity;
40
import net.minecraft.world.entity.player.Player;
41
import net.minecraft.world.phys.AABB;
42
import net.minecraft.world.phys.Vec3;
43
import org.joml.Matrix4f;
44
import org.joml.Quaternionf;
45
import combatant.client.config.common.CommonSettingSchemas;
46
import combatant.client.features.gui.clickgui.settings.TextListSetting;
47
import combatant.client.features.module.modules.combat.Hitbox;
48
import combatant.client.features.relations.CategoryService;
49
import combatant.client.features.relations.CategoryType;
50
import combatant.client.mixins.accessors.EntityRenderManagerAccessor;
51
import combatant.client.mixins.accessors.EntityRendererAccessor;
52
import combatant.client.mixins.accessors.LevelRendererAccessor;
53
import combatant.client.render.ShaderEspRenderContext;
54
import combatant.client.render.compat.EntityCullingCompat;
55
import combatant.client.render.engine.RenderState;
56
import combatant.client.render.engine.animation.AnimationUtility;
57
import combatant.client.render.engine.animation.AnimatedRenderColors;
58
import combatant.client.render.engine.core.CombatantWorldMatrices;
59
import combatant.client.render.engine.core.CombatantRenderSystem;
60
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
61
import combatant.client.render.engine.postprocess.PostProcessManager;
62
import combatant.client.render.engine.postprocess.PostProcessExecutionContext;
63
import combatant.client.render.engine.postprocess.PostProcessPass;
64
import combatant.client.render.engine.postprocess.PostProcessBackendResourceOwner;
65
import combatant.client.render.engine.postprocess.SeparableMaskBlurComputeBackend;
66
import combatant.client.render.engine.rhi.CombatantRhi;
67
import combatant.client.render.engine.renderer.FullScreenRenderer;
68
import combatant.client.render.engine.renderer.MeshRenderer;
69
import combatant.client.render.engine.renderer.Renderer2D;
70
import combatant.client.render.engine.renderer.Renderer3D;
71
import combatant.client.render.engine.text.TextRenderer;
72
import combatant.client.render.engine.uniform.MeshBuilder;
73
import combatant.client.render.engine.uniform.impl.ShaderEspBlurUniforms;
74
import combatant.client.render.engine.uniform.impl.ShaderEspGradientUniforms;
75
import combatant.client.render.engine.uniform.impl.ShaderEspSmokeUniforms;
76
import combatant.client.render.iris.IrisCombatantFrameHooks;
77
import combatant.client.render.helpers.MatteHudStyle;
78
import combatant.client.render.helpers.ScreenProjection;
79
import combatant.client.render.helpers.ScreenSpaceOverlay2D;
80
import combatant.client.util.player.PlayerHealthResolver;
81
82
import java.util.*;
83
84
//todo Description
85
@ModuleInfo(id = "esp", displayName = "ESP", aliases = {"wallhack", "wh", "outline"}, category = ModuleCategory.VISUALS)
86
public class ESP extends Module {
87
88
    private static final String MODE_FULL = "Full";
89
    private static final String MODE_CORNERS = "Corners";
90
    private static final String MODE_3D = "3D";
91
    private static final String MODE_SHADER = "Шейдер";
92
    private static final String SHADER_FILL_SOLID = "Solid";
93
    private static final String SHADER_FILL_SMOKE = "Smoke";
94
    private static final String COLOR_SOURCE_RELATIONS = "Relations";
95
    private static final String COLOR_SOURCE_CUSTOM = "Custom";
96
    private static final int OUTLINE_ALPHA = 145;
97
    private static final int COLOR_ALPHA = 210;
98
    private static final int HEALTH_ALPHA = 220;
99
    private static final int ABSORB_RGB = 0x3AA7FF;
100
    private static final float OUTLINE_EXPAND = 1.5f;
101
    private static final float OUTLINE_THICKNESS = 1.5f;
102
    private static final float COLOR_THICKNESS = 2.0f;
103
    private static final float GRAD_LIGHTEN = 0.30f;
104
    private static final float GRAD_DARKEN = 0.42f;
105
    private static final float HEALTH_BAR_WIDTH = 5.0f;
106
    private static final float HEALTH_BAR_GAP = 8.0f;
107
    private static final float HEALTH_BAR_INSET = 1.0f;
108
    private static final double AABB_TOP_OFFSET = 0.18;
109
    private static final float CORNER_SEGMENT_FRACTION = 0.27f;
110
    private static final boolean PIXEL_SNAP = true;
111
    private static final double SHADER_MAX_DISTANCE = 128.0;
112
    private static final float BOX_3D_GRADIENT_SPEED = 0.00115f;
113
    private static ProjectionMatrixBuffer shaderEspProjection;
114
    private static GpuSampler shaderEspSampler;
115
    private final Minecraft mc = Minecraft.getInstance();
116
    private final BooleanValue renderEntities =
117
            bool("espRenderEntities", "render_entities", false);
118
    private final RGBColorValue entityColor =
119
            visibleWhen(colorNoAlpha("espEntityColor", "entity_color", "#78C8FF"), renderEntities::get);
120
    private final ItemIdSetValue searchEntities =
121
            visibleWhen(itemList("espSearchEntities", "search_entities", TextListSetting.PickerMode.ENTITIES), renderEntities::get);
122
    private final BooleanValue renderSelf =
123
            bool("espRenderSelf", "render_self", false);
124
    private final ModeValue boxMode =
125
            modeCommon("espBoxMode", "box_mode", CommonSettingSchemas.ESP_BOX_MODE, MODE_FULL, MODE_FULL, MODE_CORNERS, MODE_3D, MODE_SHADER);
126
    private final ModeValue frameColorSource =
127
            visibleWhen(modeSetting("espFrameColorSource", "frame_color_source", COLOR_SOURCE_RELATIONS,
128
                    COLOR_SOURCE_RELATIONS, COLOR_SOURCE_CUSTOM), () -> !is3DBox());
129
    private final EnumValue<AnimatedRenderColors.Mode> frameColorMode =
130
            visibleWhen(enumCommon("espFrameColorMode", "frame_color_mode",
131
                    CommonSettingSchemas.RENDER_COLOR_MODE, AnimatedRenderColors.Mode.STATIC,
132
                    AnimatedRenderColors.Mode.STATIC,
133
                    AnimatedRenderColors.Mode.RAINBOW,
134
                    AnimatedRenderColors.Mode.LIGHT_RAINBOW,
135
                    AnimatedRenderColors.Mode.SKY,
136
                    AnimatedRenderColors.Mode.FADE,
137
                    AnimatedRenderColors.Mode.DOUBLE_COLOR,
138
                    AnimatedRenderColors.Mode.ANALOGOUS,
139
                    AnimatedRenderColors.Mode.THEME), this::usesCustomFrameColors);
140
    private final RGBColorValue framePrimaryColor =
141
            visibleWhen(common(colorNoAlpha("espFramePrimaryColor", "frame_primary_color", "#78C8FF"),
142
                    CommonSettingSchemas.RENDER_PRIMARY_COLOR.commonI18nKey()), this::usesPrimaryFrameColor);
143
    private final RGBColorValue frameSecondaryColor =
144
            visibleWhen(common(colorNoAlpha("espFrameSecondaryColor", "frame_secondary_color", "#B064FF"),
145
                    CommonSettingSchemas.RENDER_SECONDARY_COLOR.commonI18nKey()), this::usesSecondaryFrameColor);
146
    private final NumberValue<Integer> frameColorSpeed =
147
            visibleWhen(numCommon("espFrameColorSpeed", "frame_color_speed", CommonSettingSchemas.RENDER_COLOR_SPEED,
148
                    18, 2, 54), this::usesAnimatedFrameColors);
149
    private final NumberValue<Integer> frameColorPhase =
150
            visibleWhen(num("espFrameColorPhase", "frame_color_phase", 0, -360, 360), this::usesAnimatedFrameColors);
151
    private final NumberValue<Integer> frameColorSpread =
152
            visibleWhen(num("espFrameColorSpread", "frame_color_spread", 180, -720, 720), this::usesAnimatedFrameColors);
153
    private final NumberValue<Float> frameGradientAngle =
154
            visibleWhen(num("espFrameGradientAngle", "frame_gradient_angle", 90.0f, -180.0f, 180.0f), this::usesAnimatedFrameColors);
155
    private final NumberValue<Float> frameGradientStrength =
156
            visibleWhen(num("espFrameGradientStrength", "frame_gradient_strength", 1.0f, 0.0f, 2.0f), this::usesAnimatedFrameColors);
157
    private final SetValue shaderChamsEntities =
158
            visibleWhen(textList("espShaderChamsEntities", "shader_chams_entities",
159
                    TextListSetting.PickerMode.ENTITIES, Set.of("minecraft:end_crystal")), this::isShaderBox);
160
    private final RGBColorValue shaderChamsEntityColor =
161
            visibleWhen(colorNoAlpha("espShaderChamsEntityColor", "shader_chams_entity_color", "#B064FF"), this::isShaderBox);
162
    private final BooleanValue healthBar =
163
            visibleWhen(boolCommon("espHealthBar", "health_bar_left", CommonSettingSchemas.ESP_HEALTH_BAR, true), () -> !is3DBox() && !isShaderBox());
164
    private final BooleanMapValue healthBarTargets =
165
            visibleWhen(group("espHealthBarTargets", "health_bar_targets", new LinkedHashMap<>() {{
166
                put("players", true);
167
                put("friends", true);
168
                put("enemies", true);
169
                put("staff", true);
170
                put("entities", false);
171
            }}), () -> healthBar.get() && !is3DBox() && !isShaderBox());
172
    private final BooleanValue healthBarGradient =
173
            visibleWhen(boolCommon("espHealthBarGradient", "health_bar_gradient", CommonSettingSchemas.ESP_HEALTH_BAR_GRADIENT, true), () -> healthBar.get() && !is3DBox() && !isShaderBox());
174
    private final BooleanValue healthBarLimitDistance =
175
            visibleWhen(bool("espHealthBarLimitDistance", "health_bar_limit_distance", false),
176
                    () -> healthBar.get() && !is3DBox() && !isShaderBox());
177
    private final NumberValue<Integer> healthBarDistance =
178
            visibleWhen(numCommon("espHealthBarDistance", "health_bar_distance", CommonSettingSchemas.ESP_HEALTH_BAR_DISTANCE, 80, 5, 256),
179
                    () -> healthBar.get() && healthBarLimitDistance.get() && !is3DBox() && !isShaderBox());
180
    private final NumberValue<Float> box3dLineWidth =
181
            visibleWhen(numCommon("esp3dLineWidth", "line_width", CommonSettingSchemas.ESP_LINE_WIDTH, 1.5f, 0.5f, 6.0f), this::is3DBox);
182
    private final NumberValue<Float> box3dGradientStrength =
183
            visibleWhen(num("esp3dGradientStrength", "gradient_strength", 1.35f, 0.0f, 2.5f), this::is3DBox);
184
    private final NumberValue<Float> box3dFillAlpha =
185
            visibleWhen(num("esp3dFillAlpha", "fill_alpha", 0.30f, 0.0f, 1.0f), this::is3DBox);
186
    private final NumberValue<Float> box3dOutlineAlpha =
187
            visibleWhen(num("esp3dOutlineAlpha", "outline_alpha", 1.0f, 0.0f, 1.0f), this::is3DBox);
188
    private final BooleanValue shaderGlow =
189
            visibleWhen(bool("espShaderGlowEnabled", "shader_glow_enabled", true), this::isShaderBox);
190
    private final NumberValue<Float> shaderGlowStrength =
191
            visibleWhen(num("espShaderGlowStrength", "shader_glow_strength", 8.0f, 1.0f, 48.0f), () -> isShaderBox() && shaderGlow.get());
192
    private final NumberValue<Float> shaderGlowAlpha =
193
            visibleWhen(num("espShaderGlowAlpha", "shader_glow_alpha", 0.72f, 0.0f, 1.0f), () -> isShaderBox() && shaderGlow.get());
194
    private final NumberValue<Float> shaderGlowIntensity =
195
            visibleWhen(num("espShaderGlowIntensity", "shader_glow_intensity", 1.25f, 0.10f, 4.0f), () -> isShaderBox() && shaderGlow.get());
196
    private final BooleanValue shaderOutline =
197
            visibleWhen(bool("espShaderOutlineEnabled", "shader_outline_enabled", true), this::isShaderBox);
198
    private final NumberValue<Float> shaderOutlineWidth =
199
            visibleWhen(num("espShaderOutlineWidth", "shader_outline_width", 2.0f, 0.5f, 18.0f), () -> isShaderBox() && shaderOutline.get());
200
    private final NumberValue<Float> shaderOutlineAlpha =
201
            visibleWhen(num("espShaderOutlineAlpha", "shader_outline_alpha", 0.92f, 0.0f, 1.0f), () -> isShaderBox() && shaderOutline.get());
202
    private final NumberValue<Float> shaderOutlineIntensity =
203
            visibleWhen(num("espShaderOutlineIntensity", "shader_outline_intensity", 1.15f, 0.10f, 4.0f), () -> isShaderBox() && shaderOutline.get());
204
    private final BooleanValue shaderFill =
205
            visibleWhen(bool("espShaderFillEnabled", "shader_fill_enabled", true), this::isShaderBox);
206
    private final ModeValue shaderFillStyle =
207
            visibleWhen(modeSetting("espShaderFillStyle", "shader_fill_style", SHADER_FILL_SOLID, SHADER_FILL_SOLID, SHADER_FILL_SMOKE),
208
                    () -> isShaderBox() && shaderFill.get());
209
    private final NumberValue<Float> shaderSmokeScale =
210
            visibleWhen(num("espShaderSmokeScale", "shader_smoke_scale", 2.60f, 0.35f, 8.0f),
211
                    () -> isShaderBox() && shaderFill.get() && isShaderSmokeFill());
212
    private final NumberValue<Float> shaderSmokeSpeed =
213
            visibleWhen(num("espShaderSmokeSpeed", "shader_smoke_speed", 0.55f, 0.0f, 3.0f),
214
                    () -> isShaderBox() && shaderFill.get() && isShaderSmokeFill());
215
    private final NumberValue<Integer> shaderSmokeOctaves =
216
            visibleWhen(num("espShaderSmokeOctaves", "shader_smoke_octaves", 4, 1, 6),
217
                    () -> isShaderBox() && shaderFill.get() && isShaderSmokeFill());
218
    private final NumberValue<Float> shaderSmokeContrast =
219
            visibleWhen(num("espShaderSmokeContrast", "shader_smoke_contrast", 1.20f, 0.35f, 3.0f),
220
                    () -> isShaderBox() && shaderFill.get() && isShaderSmokeFill());
221
    private final NumberValue<Float> shaderFillAlpha =
222
            visibleWhen(num("espShaderFillAlpha", "shader_fill_alpha", 0.41f, 0.0f, 1.0f),
223
                    () -> isShaderBox() && shaderFill.get());
224
    private final NumberValue<Float> shaderDarkMultiplier =
225
            visibleWhen(num("espShaderDarkMultiplier", "shader_dark_multiplier", 0.55f, 0.0f, 1.5f), this::isShaderBox);
226
    private final PostProcessPass shaderEspPass = new ShaderEspPass();
227
    private final SubmitNodeStorage shaderEspCommandQueue = new SubmitNodeStorage();
228
    private TextureTarget shaderMask;
229
    private TextureTarget shaderBlurBuffer;
230
    private TextureTarget shaderEffectBuffer;
231
    private final SeparableMaskBlurComputeBackend shaderEspComputeBlur = new SeparableMaskBlurComputeBackend();
232
    private FeatureRenderDispatcher shaderEspRenderDispatcher;
233
    private RenderBuffers shaderEspRenderBuffers;
234
    private int shaderBufferW = -1;
235
    private int shaderBufferH = -1;
236
237
    {
238
        PostProcessManager.register(shaderEspPass);
239
    }
240
241
    private static boolean containsEntityId(Set<String> selected, Identifier id) {
242
        String full = id.toString();
243
        String path = id.getPath();
244
        for (String raw : selected) {
245
            if (raw == null || raw.isBlank()) {
246
                continue;
247
            }
248
            String normalized = raw.trim().toLowerCase(Locale.ROOT);
249
            if (full.equals(normalized) || path.equals(normalized)) {
250
                return true;
251
            }
252
            if (!normalized.contains(":") && full.equals("minecraft:" + normalized)) {
253
                return true;
254
            }
255
        }
256
        return false;
257
    }
258
259
    private static GpuSampler getShaderEspSampler() {
260
        if (shaderEspSampler != null) {
261
            return shaderEspSampler;
262
        }
263
        shaderEspSampler = RenderSystem.getDevice().createSampler(
264
                AddressMode.CLAMP_TO_EDGE,
265
                AddressMode.CLAMP_TO_EDGE,
266
                FilterMode.LINEAR,
267
                FilterMode.LINEAR,
268
                1,
269
                OptionalDouble.empty()
270
        );
271
        return shaderEspSampler;
272
    }
273
274
    private static void clearFramebuffer(RenderTarget framebuffer) {
275
        if (framebuffer == null || framebuffer.getColorTexture() == null) {
276
            return;
277
        }
278
        RenderSystem.getDevice().createCommandEncoder().clearColorTexture(framebuffer.getColorTexture(), new org.joml.Vector4f(0.0f, 0.0f, 0.0f, 0.0f));
279
    }
280
281
    private static String formatHealth(float health) {
282
        if (Math.abs(health - Math.round(health)) < 0.05f) {
283
            return Math.round(health) + " HP";
284
        }
285
        return String.format(Locale.ROOT, "%.1f HP", health);
286
    }
287
288
    private static void addFilledBox(MeshBuilder mesh,
289
                                     AABB box,
290
                                     int c000, int c001, int c010, int c011,
291
                                     int c100, int c101, int c110, int c111) {
292
        double minX = box.minX;
293
        double minY = box.minY;
294
        double minZ = box.minZ;
295
        double maxX = box.maxX;
296
        double maxY = box.maxY;
297
        double maxZ = box.maxZ;
298
299
        quad(mesh, minX, minY, minZ, c000, maxX, minY, minZ, c100, maxX, minY, maxZ, c101, minX, minY, maxZ, c001);
300
        quad(mesh, minX, maxY, minZ, c010, minX, maxY, maxZ, c011, maxX, maxY, maxZ, c111, maxX, maxY, minZ, c110);
301
        quad(mesh, minX, minY, maxZ, c001, maxX, minY, maxZ, c101, maxX, maxY, maxZ, c111, minX, maxY, maxZ, c011);
302
        quad(mesh, minX, minY, minZ, c000, minX, maxY, minZ, c010, maxX, maxY, minZ, c110, maxX, minY, minZ, c100);
303
        quad(mesh, maxX, minY, minZ, c100, maxX, maxY, minZ, c110, maxX, maxY, maxZ, c111, maxX, minY, maxZ, c101);
304
        quad(mesh, minX, minY, minZ, c000, minX, minY, maxZ, c001, minX, maxY, maxZ, c011, minX, maxY, minZ, c010);
305
    }
306
307
    private static void addOutlineBox(MeshBuilder mesh,
308
                                      AABB box,
309
                                      int c000, int c001, int c010, int c011,
310
                                      int c100, int c101, int c110, int c111) {
311
        double minX = box.minX;
312
        double minY = box.minY;
313
        double minZ = box.minZ;
314
        double maxX = box.maxX;
315
        double maxY = box.maxY;
316
        double maxZ = box.maxZ;
317
318
        line(mesh, minX, minY, minZ, c000, maxX, minY, minZ, c100);
319
        line(mesh, maxX, minY, minZ, c100, maxX, minY, maxZ, c101);
320
        line(mesh, maxX, minY, maxZ, c101, minX, minY, maxZ, c001);
321
        line(mesh, minX, minY, maxZ, c001, minX, minY, minZ, c000);
322
323
        line(mesh, minX, maxY, minZ, c010, maxX, maxY, minZ, c110);
324
        line(mesh, maxX, maxY, minZ, c110, maxX, maxY, maxZ, c111);
325
        line(mesh, maxX, maxY, maxZ, c111, minX, maxY, maxZ, c011);
326
        line(mesh, minX, maxY, maxZ, c011, minX, maxY, minZ, c010);
327
328
        line(mesh, minX, minY, minZ, c000, minX, maxY, minZ, c010);
329
        line(mesh, maxX, minY, minZ, c100, maxX, maxY, minZ, c110);
330
        line(mesh, maxX, minY, maxZ, c101, maxX, maxY, maxZ, c111);
331
        line(mesh, minX, minY, maxZ, c001, minX, maxY, maxZ, c011);
332
    }
333
334
    private static void quad(MeshBuilder mesh,
335
                             double x1, double y1, double z1, int c1,
336
                             double x2, double y2, double z2, int c2,
337
                             double x3, double y3, double z3, int c3,
338
                             double x4, double y4, double z4, int c4) {
339
        mesh.ensureQuadCapacity();
340
        putVertex(mesh, x1, y1, z1, c1);
341
        int i1 = mesh.next();
342
        putVertex(mesh, x2, y2, z2, c2);
343
        int i2 = mesh.next();
344
        putVertex(mesh, x3, y3, z3, c3);
345
        int i3 = mesh.next();
346
        putVertex(mesh, x4, y4, z4, c4);
347
        int i4 = mesh.next();
348
        mesh.quad(i1, i2, i3, i4);
349
    }
350
351
    private static void quad(MeshBuilder mesh,
352
                             double x1, double y1, double z1,
353
                             double x2, double y2, double z2,
354
                             double x3, double y3, double z3,
355
                             double x4, double y4, double z4,
356
                             int r, int g, int b, int a) {
357
        mesh.ensureQuadCapacity();
358
        int i1 = mesh.vec3(x1, y1, z1).color(r, g, b, a).next();
359
        int i2 = mesh.vec3(x2, y2, z2).color(r, g, b, a).next();
360
        int i3 = mesh.vec3(x3, y3, z3).color(r, g, b, a).next();
361
        int i4 = mesh.vec3(x4, y4, z4).color(r, g, b, a).next();
362
        mesh.quad(i1, i2, i3, i4);
363
    }
364
365
    private static void line(MeshBuilder mesh,
366
                             double x1, double y1, double z1, int c1,
367
                             double x2, double y2, double z2, int c2) {
368
        mesh.ensureLineCapacity();
369
        putVertex(mesh, x1, y1, z1, c1);
370
        int i1 = mesh.next();
371
        putVertex(mesh, x2, y2, z2, c2);
372
        int i2 = mesh.next();
373
        mesh.line(i1, i2);
374
    }
375
376
    private static void line(MeshBuilder mesh,
377
                             double x1, double y1, double z1,
378
                             double x2, double y2, double z2,
379
                             int r, int g, int b, int a) {
380
        mesh.ensureLineCapacity();
381
        int i1 = mesh.vec3(x1, y1, z1).color(r, g, b, a).next();
382
        int i2 = mesh.vec3(x2, y2, z2).color(r, g, b, a).next();
383
        mesh.line(i1, i2);
384
    }
385
386
    private static void putVertex(MeshBuilder mesh, double x, double y, double z, int argb) {
387
        mesh.vec3(x, y, z).color(
388
                (argb >>> 16) & 0xFF,
389
                (argb >>> 8) & 0xFF,
390
                argb & 0xFF,
391
                (argb >>> 24) & 0xFF
392
        );
393
    }
394
395
    private static int boxGradientColor(int baseRgb, AABB box, double x, double y, double z, int alpha, float strength) {
396
        double nx = safeRatio(x - box.minX, box.maxX - box.minX);
397
        double ny = safeRatio(y - box.minY, box.maxY - box.minY);
398
        double nz = safeRatio(z - box.minZ, box.maxZ - box.minZ);
399
        double phase = AnimationUtility.time(BOX_3D_GRADIENT_SPEED)
400
                + (box.minX + box.minY * 0.7 + box.minZ * 1.3) * 0.18;
401
        double waveA = 0.5 + 0.5 * Math.sin(phase + nx * 2.65 + ny * 5.30 - nz * 1.75);
402
        double waveB = 0.5 + 0.5 * Math.sin(phase * 0.72 - nx * 3.10 + ny * 1.35 + nz * 4.40);
403
        float t = clamp01((float) (ny * 0.44 + nz * 0.18 + (1.0 - nx) * 0.16 + waveA * 0.16 + waveB * 0.12));
404
405
        int darkRgb = mixRgb(baseRgb, 0x000000, clamp01(0.18f + 0.36f * strength));
406
        int lightRgb = mixRgb(baseRgb, 0xFFFFFF, clamp01(0.16f + 0.40f * strength));
407
        int gradientRgb = mixRgb(darkRgb, lightRgb, t);
408
        int preservedRgb = mixRgb(baseRgb, gradientRgb, clamp01(strength));
409
        return withAlpha(preservedRgb, alpha);
410
    }
411
412
    private static double safeRatio(double value, double length) {
413
        if (length <= 0.0001) return 0.0;
414
        if (value <= 0.0) return 0.0;
415
        if (value >= length) return 1.0;
416
        return value / length;
417
    }
418
419
    private boolean usesCustomFrameColors() {
420
        return !is3DBox() && COLOR_SOURCE_CUSTOM.equalsIgnoreCase(frameColorSource.get());
421
    }
422
423
    private boolean usesAnimatedFrameColors() {
424
        return usesCustomFrameColors() && AnimatedRenderColors.animated(frameColorMode.get());
425
    }
426
427
    private boolean usesPrimaryFrameColor() {
428
        if (!usesCustomFrameColors()) return false;
429
        return switch (frameColorMode.get()) {
430
            case STATIC, FADE, DOUBLE_COLOR, ANALOGOUS -> true;
431
            case RAINBOW, LIGHT_RAINBOW, SKY, THEME -> false;
432
        };
433
    }
434
435
    private boolean usesSecondaryFrameColor() {
436
        return usesCustomFrameColors() && AnimatedRenderColors.usesSecondary(frameColorMode.get());
437
    }
438
439
    private static float shaderSmokeTime() {
440
        return (System.currentTimeMillis() % 600_000L) / 1000.0f;
441
    }
442
443
    private int customPaletteColor(double tx, double ty, int alpha) {
444
        float progress = gradientProgress(tx, ty, frameGradientAngle.get());
445
        float spread = frameColorSpread.get() * frameGradientStrength.get();
446
        int phase = frameColorPhase.get() + Math.round(progress * spread);
447
        int primary = withAlpha(framePrimaryColor.getArgb(), alpha);
448
        int secondary = withAlpha(frameSecondaryColor.getArgb(), alpha);
449
        return AnimatedRenderColors.withAlpha(AnimatedRenderColors.resolve(
450
                frameColorMode.get(),
451
                frameColorSpeed.get(),
452
                phase,
453
                primary,
454
                secondary,
455
                true
456
        ), alpha);
457
    }
458
459
    private int shaderPalettePrimary() {
460
        int primary = withAlpha(framePrimaryColor.getArgb(), 255);
461
        return AnimatedRenderColors.angularPrimaryColor(frameColorMode.get(), primary);
462
    }
463
464
    private int shaderPaletteSecondary() {
465
        int primary = withAlpha(framePrimaryColor.getArgb(), 255);
466
        int secondary = withAlpha(frameSecondaryColor.getArgb(), 255);
467
        return AnimatedRenderColors.angularSecondaryColor(frameColorMode.get(), primary, secondary);
468
    }
469
470
    private float shaderPaletteBaseAngle() {
471
        if (!usesAnimatedFrameColors()) return frameColorPhase.get();
472
        int speed = Math.max(1, frameColorSpeed.get());
473
        long timeAngle = (System.currentTimeMillis() / speed) % 360L;
474
        return (float) timeAngle + frameColorPhase.get();
475
    }
476
477
    private float shaderPaletteSpread() {
478
        return frameColorSpread.get() * frameGradientStrength.get();
479
    }
480
481
    private static float gradientProgress(double tx, double ty, float angleDeg) {
482
        double x = Math.max(0.0, Math.min(1.0, tx));
483
        double y = Math.max(0.0, Math.min(1.0, ty));
484
        double radians = Math.toRadians(angleDeg);
485
        double dx = Math.cos(radians);
486
        double dy = Math.sin(radians);
487
        double projection = x * dx + y * dy;
488
        double min = Math.min(0.0, dx) + Math.min(0.0, dy);
489
        double max = Math.max(0.0, dx) + Math.max(0.0, dy);
490
        double range = max - min;
491
        if (range <= 1.0e-6) return 0.5f;
492
        return clamp01((float) ((projection - min) / range));
493
    }
494
495
    private static int withAlpha(int rgb, int alpha) {
496
        int a = clamp(alpha);
497
        return (a << 24) | (rgb & 0x00FFFFFF);
498
    }
499
500
    private static int alpha255(float alpha) {
501
        return clamp(Math.round(clamp01(alpha) * 255.0f));
502
    }
503
504
    private static int mixRgb(int rgbA, int rgbB, float t) {
505
        float clamped = Math.max(0f, Math.min(1f, t));
506
        int ar = (rgbA >>> 16) & 0xFF;
507
        int ag = (rgbA >>> 8) & 0xFF;
508
        int ab = rgbA & 0xFF;
509
        int br = (rgbB >>> 16) & 0xFF;
510
        int bg = (rgbB >>> 8) & 0xFF;
511
        int bb = rgbB & 0xFF;
512
513
        int r = Math.round(ar + (br - ar) * clamped);
514
        int g = Math.round(ag + (bg - ag) * clamped);
515
        int b = Math.round(ab + (bb - ab) * clamped);
516
        return (clamp(r) << 16) | (clamp(g) << 8) | clamp(b);
517
    }
518
519
    private static int scaleRgb(int rgb, float multiplier) {
520
        float m = Math.max(0.0f, Math.min(2.0f, multiplier));
521
        int r = Math.round(((rgb >>> 16) & 0xFF) * m);
522
        int g = Math.round(((rgb >>> 8) & 0xFF) * m);
523
        int b = Math.round((rgb & 0xFF) * m);
524
        return (clamp(r) << 16) | (clamp(g) << 8) | clamp(b);
525
    }
526
527
    private static float clamp01(float v) {
528
        if (v < 0f) return 0f;
529
        if (v > 1f) return 1f;
530
        return v;
531
    }
532
533
    private static int healthRgb(float ratio) {
534
        float t = clamp01(ratio);
535
        if (t >= 0.5f) {
536
            float k = (t - 0.5f) / 0.5f;
537
            return mixRgb(0xFFFF00, 0x00FF00, k);
538
        }
539
        float k = t / 0.5f;
540
        return mixRgb(0xFF0000, 0xFFFF00, k);
541
    }
542
543
    private static int clamp(int v) {
544
        if (v < 0) return 0;
545
        if (v > 255) return 255;
546
        return v;
547
    }
548
549
    private static int mixArgb(int a, int b, float t) {
550
        float clamped = clamp01(t);
551
        int aa = (a >>> 24) & 0xFF;
552
        int ar = (a >>> 16) & 0xFF;
553
        int ag = (a >>> 8) & 0xFF;
554
        int ab = a & 0xFF;
555
        int ba = (b >>> 24) & 0xFF;
556
        int br = (b >>> 16) & 0xFF;
557
        int bg = (b >>> 8) & 0xFF;
558
        int bb = b & 0xFF;
559
560
        int oa = Math.round(aa + (ba - aa) * clamped);
561
        int or = Math.round(ar + (br - ar) * clamped);
562
        int og = Math.round(ag + (bg - ag) * clamped);
563
        int ob = Math.round(ab + (bb - ab) * clamped);
564
        return (clamp(oa) << 24) | (clamp(or) << 16) | (clamp(og) << 8) | clamp(ob);
565
    }
566
567
    @Override
568
    public HudRenderSpace getHudRenderSpace() {
569
        return HudRenderSpace.UNSCALED_LOGICAL;
570
    }
571
572
    @Override
573
    public HudPhase getHudPhase() {
574
        return HudPhase.BEFORE_MISC_OVERLAYS;
575
    }
576
577
    @Override
578
    public WorldPhase getWorldPhase() {
579
        return WorldPhase.END_MAIN;
580
    }
581
582
    @Override
583
    public void onRenderHudEngine(Renderer2D renderer, TextRenderer textRenderer, float tickDelta) {
584
        if (!isEnabled() || mc.level == null || mc.player == null) return;
585
586
        Vec3 camPos = mc.gameRenderer.mainCamera().position();
587
588
        if (!is3DBox() && !isShaderBox()) {
589
            List<RenderEntry> playerEntries = collectPlayerEntries(camPos);
590
            playerEntries.sort(Comparator.comparingDouble(RenderEntry::distSq).reversed());
591
592
            for (RenderEntry entry : playerEntries) {
593
                draw2DESP(renderer, entry.entity(), tickDelta, entry.color(), entry.distSq());
594
            }
595
        }
596
597
        renderSearchEntityOverlay(renderer, textRenderer, tickDelta, camPos);
598
    }
599
600
    @Override
601
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
602
        if (!isEnabled() || !is3DBox() || mc.level == null || mc.player == null) return;
603
604
        Vec3 camPos = mc.gameRenderer.mainCamera().position();
605
        List<RenderEntry> entries = collectPlayerEntries(camPos);
606
        if (entries.isEmpty()) return;
607
608
        float previousLineWidth = RenderState.lineWidth;
609
        MeshBuilder lines;
610
        MeshBuilder tris;
611
        try {
612
            RenderState.lineWidth = box3dLineWidth.get();
613
            lines = renderer.batch(CombatantRenderPipelines.WORLD_COLORED_LINES, Renderer3D.DepthMode.NONE);
614
            tris = renderer.batch(CombatantRenderPipelines.WORLD_COLORED, Renderer3D.DepthMode.NONE);
615
        } finally {
616
            RenderState.lineWidth = previousLineWidth;
617
        }
618
619
        entries.sort(Comparator.comparingDouble(RenderEntry::distSq).reversed());
620
        for (RenderEntry entry : entries) {
621
            Entity entity = entry.entity();
622
            AABB box = resolveWorldBox(entity, tickDelta, shouldUseHitboxExpansion(entity));
623
            int color = resolve3DColor(entity, entry.color());
624
            add3DBox(tris, lines, box, color);
625
        }
626
    }
627
628
    @Override
629
    public void onDisable() {
630
        shaderEspComputeBlur.close();
631
        closeShaderEspRenderDispatcher();
632
    }
633
634
    private void closeShaderEspRenderDispatcher() {
635
        if (shaderEspRenderDispatcher != null) {
636
            shaderEspRenderDispatcher.close();
637
            shaderEspRenderDispatcher = null;
638
        }
639
        if (shaderEspRenderBuffers != null) {
640
            shaderEspRenderBuffers.close();
641
            shaderEspRenderBuffers = null;
642
        }
643
    }
644
645
    private List<RenderEntry> collectPlayerEntries(Vec3 camPos) {
646
        List<RenderEntry> entries = new ArrayList<>();
647
648
        for (Player player : mc.level.players()) {
649
            if (!shouldRenderPlayer(player)) continue;
650
            int color = resolvePlayerColor(player);
651
            double distSq = player.distanceToSqr(camPos);
652
            entries.add(new RenderEntry(player, color, distSq));
653
        }
654
655
        return entries;
656
    }
657
658
    private List<RenderEntry> collectSearchEntityEntries(Vec3 camPos) {
659
        List<RenderEntry> entries = new ArrayList<>();
660
        if (!renderEntities.get()) return entries;
661
662
        int color = entityColor.getArgb();
663
        for (Entity entity : mc.level.entitiesForRendering()) {
664
            if (!shouldRenderEntity(entity)) continue;
665
            double distSq = entity.distanceToSqr(camPos);
666
            entries.add(new RenderEntry(entity, color, distSq));
667
        }
668
669
        return entries;
670
    }
671
672
    private boolean shouldRenderPlayer(Player p) {
673
        if (p == null) return false;
674
        if (p == mc.player) {
675
            if (mc.options.getCameraType().isFirstPerson()) return false;
676
            return renderSelf.get();
677
        }
678
        return true;
679
    }
680
681
    private boolean shouldRenderEntity(Entity e) {
682
        if (e == null) return false;
683
        if (e instanceof Player) return false;
684
        if (e == mc.player) return false;
685
        Identifier id = BuiltInRegistries.ENTITY_TYPE.getKey(e.getType());
686
        if (id == null) return false;
687
        return searchEntities.get().contains(id.toString());
688
    }
689
690
    private int resolvePlayerColor(Player p) {
691
        return CategoryService.getColor(p);
692
    }
693
694
    private int resolve3DColor(Entity entity, int fallbackColor) {
695
        if (entity instanceof Player player) {
696
            return CategoryService.getColor(player);
697
        }
698
        return fallbackColor;
699
    }
700
701
    private boolean renderShaderEsp(GpuTextureView src, GpuTextureView dst, float tickDelta) {
702
        if (!isEnabled() || !isShaderBox() || mc.level == null || mc.player == null) {
703
            return false;
704
        }
705
        if (!shaderGlow.get() && !shaderOutline.get() && !shaderFill.get()) {
706
            return false;
707
        }
708
709
        Vec3 camPos = mc.gameRenderer.mainCamera().position();
710
        List<RenderEntry> entries = collectShaderEntries(camPos);
711
        if (entries.isEmpty()) {
712
            return false;
713
        }
714
715
        ensureShaderBuffers();
716
        if (shaderMask == null || shaderBlurBuffer == null || shaderEffectBuffer == null) {
717
            return false;
718
        }
719
720
        if (!renderShaderEntityMask(entries, tickDelta)) {
721
            return false;
722
        }
723
724
        PostProcessManager.copy(src, dst);
725
726
        int width = mc.getWindow().getWidth();
727
        int height = mc.getWindow().getHeight();
728
        return renderShaderColorPass(dst, width, height);
729
    }
730
731
    private List<RenderEntry> collectShaderEntries(Vec3 camPos) {
732
        List<RenderEntry> entries = new ArrayList<>();
733
        double maxDistSq = SHADER_MAX_DISTANCE * SHADER_MAX_DISTANCE;
734
735
        for (RenderEntry entry : collectPlayerEntries(camPos)) {
736
            if (entry.distSq() > maxDistSq) {
737
                continue;
738
            }
739
            entries.add(entry);
740
        }
741
742
        for (RenderEntry entry : collectShaderChamsEntityEntries(camPos, maxDistSq)) {
743
            entries.add(entry);
744
        }
745
746
        entries.sort(Comparator.comparingDouble(RenderEntry::distSq).reversed());
747
        return entries;
748
    }
749
750
    private List<RenderEntry> collectShaderChamsEntityEntries(Vec3 camPos, double maxDistSq) {
751
        List<RenderEntry> entries = new ArrayList<>();
752
        Set<String> selected = shaderChamsEntities.get();
753
        if (selected == null || selected.isEmpty()) {
754
            return entries;
755
        }
756
757
        int color = shaderChamsEntityColor.getArgb();
758
        for (Entity entity : mc.level.entitiesForRendering()) {
759
            if (!shouldRenderShaderChamsEntity(entity, selected)) {
760
                continue;
761
            }
762
            double distSq = entity.distanceToSqr(camPos);
763
            if (distSq > maxDistSq) {
764
                continue;
765
            }
766
            entries.add(new RenderEntry(entity, color, distSq));
767
        }
768
        return entries;
769
    }
770
771
    private boolean shouldRenderShaderChamsEntity(Entity entity, Set<String> selected) {
772
        if (entity == null) return false;
773
        if (entity instanceof Player) return false;
774
        if (entity == mc.player) return false;
775
776
        Identifier id = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType());
777
        if (id == null) return false;
778
        return containsEntityId(selected, id);
779
    }
780
781
    private boolean renderShaderColorPass(GpuTextureView dst, int width, int height) {
782
        if (shaderMask.getColorTextureView() == null) {
783
            return false;
784
        }
785
786
        float darkMultiplier = shaderDarkMultiplier.get();
787
        boolean rendered = false;
788
789
        if (shaderGlow.get()) {
790
            float glowRadius = Math.max(1.0f, shaderGlowStrength.get());
791
            GpuTextureView glowMask = blurShaderMask(shaderMask, shaderEffectBuffer, glowRadius, width, height);
792
            drawShaderGradient(glowMask, dst, width, height,
793
                    alpha255(shaderGlowAlpha.get()),
794
                    darkMultiplier,
795
                    shaderGlowIntensity.get());
796
            rendered = true;
797
        }
798
799
        if (shaderFill.get()) {
800
            if (isShaderSmokeFill()) {
801
                drawShaderSmoke(shaderMask, dst, width, height);
802
            } else {
803
                drawShaderGradient(shaderMask.getColorTextureView(), dst, width, height,
804
                        alpha255(shaderFillAlpha.get()),
805
                        darkMultiplier,
806
                        1.0f);
807
            }
808
            rendered = true;
809
        }
810
811
        if (shaderOutline.get()) {
812
            float outlineRadius = Math.max(0.5f, shaderOutlineWidth.get());
813
            GpuTextureView outlineMask = blurShaderMask(shaderMask, shaderEffectBuffer, outlineRadius, width, height);
814
            drawShaderGradient(outlineMask, dst, width, height,
815
                    alpha255(shaderOutlineAlpha.get()),
816
                    darkMultiplier,
817
                    shaderOutlineIntensity.get());
818
            rendered = true;
819
        }
820
821
        return rendered;
822
    }
823
824
    private GpuTextureView blurShaderMask(RenderTarget input, RenderTarget output, float radius, int width, int height) {
825
        GpuTextureView inputView = input != null ? input.getColorTextureView() : null;
826
        if (inputView == null) return null;
827
828
        GpuTextureView compute = shaderEspComputeBlur.blur(
829
                CombatantRenderSystem.rhi(), inputView, inputView, getShaderEspSampler(),
830
                width, height, Math.min(radius, 63.0f));
831
        if (compute != null) return compute;
832
833
        clearFramebuffer(shaderBlurBuffer);
834
        ShaderEspBlurUniforms.update(width, height, Math.min(radius, 63.0f), 1.0f, 0.0f);
835
        FullScreenRenderer.begin("Combatant Fullscreen Pass")
836
                .attachment(shaderBlurBuffer.getColorTextureView())
837
                .pipeline(CombatantRenderPipelines.SHADER_ESP_SHADOW)
838
                .uniform("ShaderEspBlur", ShaderEspBlurUniforms.get())
839
                .sampler("u_Texture", inputView, getShaderEspSampler())
840
                .sampler("u_Mask", inputView, getShaderEspSampler())
841
                .end();
842
843
        clearFramebuffer(output);
844
        ShaderEspBlurUniforms.update(width, height, Math.min(radius, 63.0f), 0.0f, 1.0f);
845
        FullScreenRenderer.begin("Combatant Fullscreen Pass")
846
                .attachment(output.getColorTextureView())
847
                .pipeline(CombatantRenderPipelines.SHADER_ESP_SHADOW)
848
                .uniform("ShaderEspBlur", ShaderEspBlurUniforms.get())
849
                .sampler("u_Texture", shaderBlurBuffer.getColorTextureView(), getShaderEspSampler())
850
                .sampler("u_Mask", inputView, getShaderEspSampler())
851
                .end();
852
        return output.getColorTextureView();
853
    }
854
855
    private void drawShaderGradient(GpuTextureView input, GpuTextureView dst, int width, int height, int alpha,
856
                                    float darkMultiplier, float intensity) {
857
        if (input == null || dst == null) return;
858
        boolean overrideColor = usesCustomFrameColors();
859
        ShaderEspGradientUniforms.update(
860
                0.0f,
861
                0.0f,
862
                width,
863
                height,
864
                shaderPalettePrimary(),
865
                shaderPaletteSecondary(),
866
                AnimatedRenderColors.shaderMode(frameColorMode.get()),
867
                shaderPaletteBaseAngle(),
868
                shaderPaletteSpread(),
869
                frameGradientAngle.get(),
870
                darkMultiplier,
871
                overrideColor ? 1.0f : 0.0f,
872
                Math.max(0.0f, Math.min(4.0f, intensity)),
873
                alpha / 255.0f
874
        );
875
        FullScreenRenderer.begin("Combatant Fullscreen Pass")
876
                .attachment(dst)
877
                .pipeline(CombatantRenderPipelines.SHADER_ESP_GRADIENT)
878
                .uniform("ShaderEspGradient", ShaderEspGradientUniforms.get())
879
                .sampler("u_Texture", input, getShaderEspSampler())
880
                .end();
881
    }
882
883
    private void drawShaderSmoke(RenderTarget input, GpuTextureView dst, int width, int height) {
884
        boolean overrideColor = usesCustomFrameColors();
885
        ShaderEspSmokeUniforms.update(
886
                0.0f,
887
                0.0f,
888
                width,
889
                height,
890
                shaderSmokeTime(),
891
                shaderSmokeScale.get(),
892
                shaderSmokeSpeed.get(),
893
                clamp01(shaderFillAlpha.get()),
894
                shaderSmokeOctaves.get(),
895
                shaderSmokeContrast.get(),
896
                overrideColor ? 1.0f : 0.0f,
897
                1.0f,
898
                shaderPalettePrimary(),
899
                shaderPaletteSecondary(),
900
                AnimatedRenderColors.shaderMode(frameColorMode.get()),
901
                shaderPaletteBaseAngle(),
902
                shaderPaletteSpread(),
903
                frameGradientAngle.get()
904
        );
905
        FullScreenRenderer.begin("Combatant Fullscreen Pass")
906
                .attachment(dst)
907
                .pipeline(CombatantRenderPipelines.SHADER_ESP_SMOKE)
908
                .uniform("ShaderEspSmoke", ShaderEspSmokeUniforms.get())
909
                .sampler("u_Texture", input.getColorTextureView(), getShaderEspSampler())
910
                .end();
911
    }
912
913
    private void ensureShaderBuffers() {
914
        int width = mc.getWindow().getWidth();
915
        int height = mc.getWindow().getHeight();
916
        if (width <= 0 || height <= 0) {
917
            return;
918
        }
919
920
        boolean sizeChanged = width != shaderBufferW || height != shaderBufferH;
921
        if (shaderMask == null) {
922
            shaderMask = new TextureTarget("combatant-shader-esp-mask", width, height, true, GpuFormat.RGBA8_UNORM);
923
            shaderBlurBuffer = new TextureTarget("combatant-shader-esp-blur", width, height, false, GpuFormat.RGBA8_UNORM);
924
            shaderEffectBuffer = new TextureTarget("combatant-shader-esp-effect", width, height, false, GpuFormat.RGBA8_UNORM);
925
            shaderBufferW = width;
926
            shaderBufferH = height;
927
        } else if (sizeChanged) {
928
            shaderMask.resize(width, height);
929
            shaderBlurBuffer.resize(width, height);
930
            shaderEffectBuffer.resize(width, height);
931
            shaderBufferW = width;
932
            shaderBufferH = height;
933
        }
934
935
    }
936
937
    private boolean renderShaderEntityMask(List<RenderEntry> entries, float tickDelta) {
938
        if (entries.isEmpty() || shaderMask == null) {
939
            return false;
940
        }
941
942
        LevelRenderer worldRenderer = mc.levelRenderer;
943
        if (worldRenderer == null) {
944
            return false;
945
        }
946
947
        // Shader ESP already softens/dilates the silhouette in post. Rendering the auxiliary
948
        // mask with world MSAA multiplies the entity pass cost (and forces a resolve) without
949
        // producing a meaningful final-quality gain, so keep this mask single-sampled.
950
        RenderTarget target = shaderMask;
951
952
        var colorTex = target.getColorTexture();
953
        if (colorTex == null) {
954
            return false;
955
        }
956
957
        var encoder = RenderSystem.getDevice().createCommandEncoder();
958
        encoder.clearColorTexture(colorTex, new org.joml.Vector4f(0.0f, 0.0f, 0.0f, 0.0f));
959
960
        var depthTex = target.getDepthTexture();
961
        if (depthTex != null) {
962
            encoder.clearDepthTexture(depthTex, 1.0);
963
        }
964
965
        GpuTextureView prevColor = RenderSystem.outputColorTextureOverride;
966
        GpuTextureView prevDepth = RenderSystem.outputDepthTextureOverride;
967
        GpuBufferSlice prevProjection = RenderSystem.getProjectionMatrixBuffer();
968
        ProjectionType prevProjectionType = RenderSystem.getProjectionType();
969
        Matrix4f prevMeshProjection = MeshRenderer.projection();
970
        Matrix4f prevWorldProjection = new Matrix4f(RenderState.worldProjection);
971
        boolean prevRendering3D = RenderState.rendering3D;
972
973
        RenderSystem.outputColorTextureOverride = target.getColorTextureView();
974
        RenderSystem.outputDepthTextureOverride = target.getDepthTextureView();
975
976
        if (shaderEspProjection == null) {
977
            shaderEspProjection = new ProjectionMatrixBuffer("combatant-shader-esp-projection");
978
        }
979
        Matrix4f espProjection = CombatantWorldMatrices.renderProjectionMatrix();
980
        if (espProjection == null) {
981
            espProjection = new Matrix4f(RenderState.worldProjection);
982
        }
983
        RenderSystem.setProjectionMatrix(shaderEspProjection.getBuffer(espProjection), ProjectionType.PERSPECTIVE);
984
        MeshRenderer.setProjection(espProjection);
985
        RenderState.worldProjection.set(espProjection);
986
        RenderState.rendering3D = true;
987
988
        var modelView = RenderSystem.getModelViewStack();
989
        modelView.pushMatrix();
990
        modelView.identity();
991
        Matrix4f capturedPosition = CombatantWorldMatrices.positionMatrix();
992
        if (capturedPosition != null) {
993
            modelView.mul(capturedPosition);
994
        } else if (mc.gameRenderer != null && mc.gameRenderer.mainCamera() != null) {
995
            modelView.mul(new Matrix4f().rotation(mc.gameRenderer.mainCamera().rotation().conjugate(new Quaternionf())));
996
        }
997
998
        PoseStack matrices = new PoseStack();
999
        boolean pushed = false;
1000
1001
        try (ShaderEspRenderContext.Scope ignored = ShaderEspRenderContext.enter()) {
1002
            LevelRendererAccessor accessor = (LevelRendererAccessor) worldRenderer;
1003
            LevelRenderState base = accessor.combatant$getWorldRenderState();
1004
            if (base == null || base.cameraRenderState == null) {
1005
                return false;
1006
            }
1007
1008
            LevelRenderState temp = new LevelRenderState();
1009
            temp.cameraRenderState = base.cameraRenderState;
1010
            temp.shouldShowEntityOutlines = true;
1011
1012
            shaderEspCommandQueue.getSubmitsPerOrder().clear();
1013
1014
            EntityRenderDispatcher entityRenderManager = mc.getEntityRenderDispatcher();
1015
            for (RenderEntry entry : entries) {
1016
                Entity entity = entry.entity();
1017
                EntityCullingCompat.forceVisibleForShaderEsp(entity);
1018
                EntityRenderer<?, ?> entityRenderer =
1019
                        ((EntityRenderManagerAccessor) entityRenderManager).combatant$invokeGetRenderer(entity);
1020
                if (entityRenderer == null) {
1021
                    continue;
1022
                }
1023
1024
                EntityRenderState state = ((EntityRendererAccessor) entityRenderer).combatant$invokeCreateRenderState();
1025
                ((EntityRendererAccessor) entityRenderer).combatant$invokeUpdateRenderState(entity, state, tickDelta);
1026
                if (state == null) {
1027
                    continue;
1028
                }
1029
1030
                state.outlineColor = 0xFF000000 | (entry.color() & 0x00FFFFFF);
1031
                state.shadowRadius = 0.0f;
1032
                state.shadowPieces.clear();
1033
                state.nameTag = null;
1034
                state.nameTagAttachment = null;
1035
                temp.entityRenderStates.add(state);
1036
            }
1037
1038
            if (temp.entityRenderStates.isEmpty()) {
1039
                return false;
1040
            }
1041
1042
            FeatureRenderDispatcher dispatcher = getShaderEspRenderDispatcher();
1043
            if (dispatcher == null) {
1044
                return false;
1045
            }
1046
1047
            boolean standaloneDispatcher = dispatcher == shaderEspRenderDispatcher && shaderEspRenderBuffers != null;
1048
            accessor.combatant$invokeSubmitEntities(matrices, temp, shaderEspCommandQueue);
1049
            pushed = true;
1050
            try {
1051
                try (FeatureRenderDispatcher.PreparedFrame prepared = dispatcher.prepareFrame(shaderEspCommandQueue)) {
1052
                    if (!prepared.hasAnyOutline()) {
1053
                        return false;
1054
                    }
1055
                    prepared.executeOutline();
1056
                }
1057
            } finally {
1058
                if (standaloneDispatcher) {
1059
                    shaderEspRenderBuffers.endFrame();
1060
                }
1061
            }
1062
        } finally {
1063
            modelView.popMatrix();
1064
            MeshRenderer.setProjection(prevMeshProjection);
1065
            RenderState.worldProjection.set(prevWorldProjection);
1066
            RenderState.rendering3D = prevRendering3D;
1067
            if (prevProjection != null && prevProjectionType != null) {
1068
                RenderSystem.setProjectionMatrix(prevProjection, prevProjectionType);
1069
            }
1070
            RenderSystem.outputColorTextureOverride = prevColor;
1071
            RenderSystem.outputDepthTextureOverride = prevDepth;
1072
            shaderEspCommandQueue.getSubmitsPerOrder().clear();
1073
        }
1074
1075
        return true;
1076
    }
1077
1078
    private FeatureRenderDispatcher getShaderEspRenderDispatcher() {
1079
        if (IrisCombatantFrameHooks.isRenderingAfterIrisFinalization()) {
1080
            return getStandaloneShaderEspRenderDispatcher();
1081
        }
1082
        if (mc != null && mc.levelRenderer instanceof LevelRendererAccessor accessor) {
1083
            FeatureRenderDispatcher dispatcher = accessor.combatant$getEntityRenderDispatcher();
1084
            if (dispatcher != null) {
1085
                return dispatcher;
1086
            }
1087
        }
1088
        return getStandaloneShaderEspRenderDispatcher();
1089
    }
1090
1091
    private FeatureRenderDispatcher getStandaloneShaderEspRenderDispatcher() {
1092
        if (shaderEspRenderDispatcher != null) {
1093
            return shaderEspRenderDispatcher;
1094
        }
1095
        if (mc.gameRenderer == null || mc.getModelManager() == null || mc.getAtlasManager() == null || mc.font == null) {
1096
            return null;
1097
        }
1098
        shaderEspRenderBuffers = new RenderBuffers(1);
1099
        shaderEspRenderDispatcher = new FeatureRenderDispatcher(
1100
                shaderEspRenderBuffers,
1101
                mc.getModelManager(),
1102
                mc.getAtlasManager(),
1103
                mc.font,
1104
                mc.gameRenderer.gameRenderState()
1105
        );
1106
        return shaderEspRenderDispatcher;
1107
    }
1108
1109
    private void renderSearchEntityOverlay(Renderer2D renderer, TextRenderer fallbackTextRenderer, float tickDelta, Vec3 camPos) {
1110
        List<RenderEntry> entries = collectSearchEntityEntries(camPos);
1111
        if (entries.isEmpty()) return;
1112
1113
        entries.sort(Comparator.comparingDouble(RenderEntry::distSq).reversed());
1114
1115
        TextRenderer labelRenderer = ScreenSpaceOverlay2D.labelRenderer(fallbackTextRenderer);
1116
        List<SearchLabelEntry> labels = new ArrayList<>();
1117
        boolean measureStarted = false;
1118
        if (!labelRenderer.isBuilding()) {
1119
            labelRenderer.begin(ScreenSpaceOverlay2D.TEXT_SCALE, true, false);
1120
            measureStarted = true;
1121
        }
1122
1123
        for (RenderEntry entry : entries) {
1124
            Entity entity = entry.entity();
1125
            AABB box = resolveWorldBox(entity, tickDelta, false);
1126
            ScreenSpaceOverlay2D.ScreenRect rect = ScreenSpaceOverlay2D.projectBox(box, tickDelta);
1127
            if (rect == null) continue;
1128
1129
            ScreenSpaceOverlay2D.LabelEntry label = createSearchEntityLabel(labelRenderer, entity, entry.color(), rect);
1130
            labels.add(new SearchLabelEntry(entry.entity(), entry.distSq(), rect, entry.color(), label));
1131
        }
1132
1133
        if (measureStarted) {
1134
            labelRenderer.end();
1135
        }
1136
        if (labels.isEmpty()) return;
1137
1138
        labels.sort(Comparator.comparingDouble(SearchLabelEntry::distSq).reversed());
1139
        for (SearchLabelEntry entry : labels) {
1140
            renderSearchEntityLabelPass(renderer, labelRenderer, entry);
1141
        }
1142
    }
1143
1144
    private void renderSearchEntityLabelPass(Renderer2D renderer,
1145
                                             TextRenderer labelRenderer,
1146
                                             SearchLabelEntry entry) {
1147
        ScreenSpaceOverlay2D.ScreenRect rect = entry.rect();
1148
        ScreenSpaceOverlay2D.LabelEntry label = entry.label();
1149
        MatteHudStyle.drawFrame(renderer, rect.minX(), rect.minY(), rect.width(), rect.height(), entry.color(), 1.0f);
1150
        if (shouldRenderHealthBar(entry.entity()) && healthBarInRange(entry.distSq())) {
1151
            drawHealthBar(renderer, rect.minX(), rect.minY(), rect.maxX(), rect.maxY(), entry.entity());
1152
        }
1153
        MatteHudStyle.drawLabelPlate(renderer, label.x(), label.y(), label.totalWidth(), label.height(), 1.0f);
1154
1155
        boolean renderStarted = false;
1156
        if (!labelRenderer.isBuilding()) {
1157
            labelRenderer.begin(ScreenSpaceOverlay2D.TEXT_SCALE);
1158
            renderStarted = true;
1159
        }
1160
        try {
1161
            ScreenSpaceOverlay2D.renderLabels(labelRenderer, List.of(label), false);
1162
        } finally {
1163
            if (renderStarted) {
1164
                labelRenderer.end();
1165
            }
1166
        }
1167
        Renderer2D.flushBatch(Renderer2D.FlushReason.EXPLICIT);
1168
    }
1169
1170
    private ScreenSpaceOverlay2D.LabelEntry createSearchEntityLabel(TextRenderer labelRenderer, Entity entity,
1171
                                                                    int baseColor,
1172
                                                                    ScreenSpaceOverlay2D.ScreenRect rect) {
1173
        String name = entity.getDisplayName() != null ? entity.getDisplayName().getString() : entity.getName().getString();
1174
        if (entity instanceof LivingEntity living) {
1175
            PlayerHealthResolver.HealthSnapshot health = PlayerHealthResolver.resolve(living);
1176
            float max = health.maxHealth();
1177
            if (max > 0.0f) {
1178
                float ratio = clamp01(health.totalHealth() / max);
1179
                String hpText = formatHealth(health.totalHealth());
1180
                return ScreenSpaceOverlay2D.createCenteredLabel(
1181
                        labelRenderer,
1182
                        name,
1183
                        hpText,
1184
                        baseColor,
1185
                        withAlpha(healthRgb(ratio), 235),
1186
                        rect
1187
                );
1188
            }
1189
        }
1190
        return ScreenSpaceOverlay2D.createCenteredLabel(labelRenderer, name, baseColor, rect);
1191
    }
1192
1193
    private void draw2DESP(Renderer2D renderer, Entity entity, float tickDelta, int baseColor, double distSq) {
1194
        AABB box = resolveWorldBox(entity, tickDelta, false);
1195
        ScreenBox screen = project(box, tickDelta);
1196
        if (screen == null) return;
1197
1198
        drawBoxESP(renderer, screen.minX(), screen.minY(), screen.maxX(), screen.maxY(), baseColor);
1199
        if (shouldRenderHealthBar(entity) && healthBarInRange(distSq)) {
1200
            drawHealthBar(renderer, screen.minX(), screen.minY(), screen.maxX(), screen.maxY(), entity);
1201
        }
1202
    }
1203
1204
    private AABB resolveWorldBox(Entity entity, float tickDelta, boolean hitboxExpanded) {
1205
        Vec3 pos = entity.getPosition(tickDelta);
1206
        AABB box = entity.getBoundingBox().move(
1207
                pos.x - entity.getX(),
1208
                pos.y - entity.getY(),
1209
                pos.z - entity.getZ()
1210
        );
1211
1212
        Hitbox hitbox = Modules.get(Hitbox.class);
1213
        if (hitboxExpanded && hitbox != null) {
1214
            box = box.inflate(hitbox.getPadding());
1215
        }
1216
1217
        return new AABB(box.minX, box.minY, box.minZ, box.maxX, box.maxY + AABB_TOP_OFFSET, box.maxZ);
1218
    }
1219
1220
    private ScreenBox project(AABB box, float tickDelta) {
1221
        Vec3[] pts = new Vec3[]{
1222
                new Vec3(box.minX, box.minY, box.minZ),
1223
                new Vec3(box.minX, box.minY, box.maxZ),
1224
                new Vec3(box.minX, box.maxY, box.minZ),
1225
                new Vec3(box.minX, box.maxY, box.maxZ),
1226
                new Vec3(box.maxX, box.minY, box.minZ),
1227
                new Vec3(box.maxX, box.minY, box.maxZ),
1228
                new Vec3(box.maxX, box.maxY, box.minZ),
1229
                new Vec3(box.maxX, box.maxY, box.maxZ)
1230
        };
1231
1232
        double minX = Double.POSITIVE_INFINITY;
1233
        double minY = Double.POSITIVE_INFINITY;
1234
        double maxX = Double.NEGATIVE_INFINITY;
1235
        double maxY = Double.NEGATIVE_INFINITY;
1236
1237
        for (Vec3 p : pts) {
1238
            Vec3 screen = ScreenProjection.worldToScreen(p, tickDelta);
1239
            if (screen == null) continue;
1240
            minX = Math.min(minX, screen.x);
1241
            minY = Math.min(minY, screen.y);
1242
            maxX = Math.max(maxX, screen.x);
1243
            maxY = Math.max(maxY, screen.y);
1244
        }
1245
1246
        if (minX == Double.POSITIVE_INFINITY) return null;
1247
        if (maxX <= minX || maxY <= minY) return null;
1248
1249
        if (PIXEL_SNAP) {
1250
            minX = Math.floor(minX);
1251
            minY = Math.floor(minY);
1252
            maxX = Math.ceil(maxX);
1253
            maxY = Math.ceil(maxY);
1254
        }
1255
1256
        return new ScreenBox(minX, minY, maxX, maxY);
1257
    }
1258
1259
    private void drawBoxESP(Renderer2D renderer, double minX, double minY, double maxX, double maxY, int baseColor) {
1260
        ColorResolver gradient;
1261
        if (usesCustomFrameColors()) {
1262
            gradient = new AnimatedFrameGradient(COLOR_ALPHA);
1263
        } else {
1264
            int baseRgb = baseColor & 0x00FFFFFF;
1265
            int darkRgb = mixRgb(baseRgb, 0x000000, GRAD_DARKEN);
1266
            int lightRgb = mixRgb(baseRgb, 0xFFFFFF, GRAD_LIGHTEN);
1267
            gradient = new Gradient(
1268
                    withAlpha(lightRgb, COLOR_ALPHA),
1269
                    withAlpha(baseRgb, COLOR_ALPHA),
1270
                    withAlpha(lightRgb, COLOR_ALPHA),
1271
                    withAlpha(darkRgb, COLOR_ALPHA)
1272
            );
1273
        }
1274
        int outline = withAlpha(0x000000, OUTLINE_ALPHA);
1275
        drawOutline(renderer,
1276
                minX - OUTLINE_EXPAND, minY - OUTLINE_EXPAND,
1277
                maxX + OUTLINE_EXPAND, maxY + OUTLINE_EXPAND,
1278
                OUTLINE_THICKNESS, SolidColor.of(outline));
1279
1280
        drawOutline(renderer, minX, minY, maxX, maxY, COLOR_THICKNESS, gradient);
1281
        double innerInset = COLOR_THICKNESS;
1282
        drawOutline(renderer,
1283
                minX + innerInset, minY + innerInset,
1284
                maxX - innerInset, maxY - innerInset,
1285
                OUTLINE_THICKNESS, SolidColor.of(outline));
1286
    }
1287
1288
    private boolean shouldRenderHealthBar(Entity entity) {
1289
        if (!healthBar.get() || is3DBox() || isShaderBox() || !(entity instanceof LivingEntity)) {
1290
            return false;
1291
        }
1292
        if (!(entity instanceof Player player)) {
1293
            return healthBarTargets.get("entities");
1294
        }
1295
1296
        CategoryType type = CategoryService.get(player);
1297
        return switch (type) {
1298
            case STAFF -> healthBarTargets.get("staff");
1299
            case FRIEND, BEDWARS_SELF -> healthBarTargets.get("friends");
1300
            case ENEMY, BEDWARS_ENEMY -> healthBarTargets.get("enemies");
1301
            case DEFAULT -> healthBarTargets.get("players");
1302
        };
1303
    }
1304
1305
    private boolean healthBarInRange(double distSq) {
1306
        if (!healthBarLimitDistance.get()) {
1307
            return true;
1308
        }
1309
        double maxDist = Math.max(0.0, healthBarDistance.get());
1310
        return distSq <= maxDist * maxDist;
1311
    }
1312
1313
    private void drawHealthBar(Renderer2D renderer, double x1, double y1, double x2, double y2, Entity entity) {
1314
        if (!(entity instanceof LivingEntity living)) return;
1315
        double height = y2 - y1;
1316
        if (height <= 0.0) return;
1317
1318
        PlayerHealthResolver.HealthSnapshot health = PlayerHealthResolver.resolve(living);
1319
        float max = health.maxHealth();
1320
        if (max <= 0f) return;
1321
        float current = health.totalHealth();
1322
        float ratio = clamp01(current / max);
1323
        float absorption = Math.max(0f, health.absorption());
1324
        float absorptionRatio = clamp01(absorption / max);
1325
1326
        double barX = x1 - HEALTH_BAR_GAP - HEALTH_BAR_WIDTH;
1327
        double barY = y1;
1328
1329
        renderer.quad(barX, barY, HEALTH_BAR_WIDTH, height, 0xFF000000);
1330
1331
        double inset = Math.min(HEALTH_BAR_INSET, Math.min(HEALTH_BAR_WIDTH * 0.45, height * 0.1));
1332
        double innerX = barX + inset;
1333
        double innerY = barY + inset;
1334
        double innerW = Math.max(0.0, HEALTH_BAR_WIDTH - inset * 2.0);
1335
        double innerH = Math.max(0.0, height - inset * 2.0);
1336
1337
        double fillH = innerH * ratio;
1338
        if (fillH <= 0.0) return;
1339
        double fillY = innerY + (innerH - fillH);
1340
        if (healthBarGradient.get()) {
1341
            float topT = clamp01((float) (fillH / Math.max(0.0001, innerH)));
1342
            int topRgb = mixRgb(0xFF0000, 0x00FF00, topT);
1343
            int bottomRgb = 0xFF0000;
1344
            renderer.quad(
1345
                    innerX, fillY, innerW, fillH,
1346
                    withAlpha(topRgb, HEALTH_ALPHA),
1347
                    withAlpha(topRgb, HEALTH_ALPHA),
1348
                    withAlpha(bottomRgb, HEALTH_ALPHA),
1349
                    withAlpha(bottomRgb, HEALTH_ALPHA)
1350
            );
1351
        } else {
1352
            int rgb = healthRgb(ratio);
1353
            renderer.quad(innerX, fillY, innerW, fillH, withAlpha(rgb, HEALTH_ALPHA));
1354
        }
1355
1356
        if (absorptionRatio > 0f) {
1357
            float totalRatio = clamp01(current / max);
1358
            double absorbH = innerH * Math.min(absorptionRatio, totalRatio);
1359
            if (absorbH > 0.0) {
1360
                double absorbY = innerY + (innerH - absorbH);
1361
                renderer.quad(innerX, absorbY, innerW, absorbH, withAlpha(ABSORB_RGB, HEALTH_ALPHA));
1362
            }
1363
        }
1364
    }
1365
1366
    private void drawOutline(Renderer2D renderer, double x1, double y1, double x2, double y2,
1367
                             double thickness, ColorResolver colors) {
1368
        double width = x2 - x1;
1369
        double height = y2 - y1;
1370
        if (width <= 0 || height <= 0 || thickness <= 0.0) return;
1371
1372
        if (isCornerBox()) {
1373
            drawOutlineCorners(renderer, x1, y1, x2, y2, thickness, colors);
1374
            return;
1375
        }
1376
1377
        drawGradientQuad(renderer, x1, y1, x2, y1 + thickness, x1, y1, x2, y2, colors);
1378
        drawGradientQuad(renderer, x1, y2 - thickness, x2, y2, x1, y1, x2, y2, colors);
1379
        drawGradientQuad(renderer, x1, y1, x1 + thickness, y2, x1, y1, x2, y2, colors);
1380
        drawGradientQuad(renderer, x2 - thickness, y1, x2, y2, x1, y1, x2, y2, colors);
1381
    }
1382
1383
    private void drawOutlineCorners(Renderer2D renderer, double x1, double y1, double x2, double y2,
1384
                                    double thickness, ColorResolver colors) {
1385
        double width = x2 - x1;
1386
        double height = y2 - y1;
1387
        if (width <= 0 || height <= 0) return;
1388
1389
        double seg = Math.min(width, height) * CORNER_SEGMENT_FRACTION;
1390
        double minSeg = thickness * 2.0;
1391
        double segX = Math.min(width * 0.5, Math.max(seg, minSeg));
1392
        double segY = Math.min(height * 0.5, Math.max(seg, minSeg));
1393
1394
        drawCornerSegment(renderer, x1, y1, x1 + segX, y1 + thickness, x1, y1, x2, y2, colors);
1395
        drawCornerSegment(renderer, x1, y1, x1 + thickness, y1 + segY, x1, y1, x2, y2, colors);
1396
1397
        drawCornerSegment(renderer, x2 - segX, y1, x2, y1 + thickness, x1, y1, x2, y2, colors);
1398
        drawCornerSegment(renderer, x2 - thickness, y1, x2, y1 + segY, x1, y1, x2, y2, colors);
1399
1400
        drawCornerSegment(renderer, x1, y2 - thickness, x1 + segX, y2, x1, y1, x2, y2, colors);
1401
        drawCornerSegment(renderer, x1, y2 - segY, x1 + thickness, y2, x1, y1, x2, y2, colors);
1402
1403
        drawCornerSegment(renderer, x2 - segX, y2 - thickness, x2, y2, x1, y1, x2, y2, colors);
1404
        drawCornerSegment(renderer, x2 - thickness, y2 - segY, x2, y2, x1, y1, x2, y2, colors);
1405
    }
1406
1407
    private void drawCornerSegment(Renderer2D renderer,
1408
                                   double sx1, double sy1, double sx2, double sy2,
1409
                                   double boxX1, double boxY1, double boxX2, double boxY2,
1410
                                   ColorResolver colors) {
1411
        drawGradientQuad(renderer, sx1, sy1, sx2, sy2, boxX1, boxY1, boxX2, boxY2, colors);
1412
    }
1413
1414
    private void drawGradientQuad(Renderer2D renderer,
1415
                                  double sx1, double sy1, double sx2, double sy2,
1416
                                  double boxX1, double boxY1, double boxX2, double boxY2,
1417
                                  ColorResolver colors) {
1418
        double width = sx2 - sx1;
1419
        double height = sy2 - sy1;
1420
        if (width <= 0.0 || height <= 0.0) return;
1421
1422
        if (colors instanceof AnimatedFrameGradient && usesAnimatedFrameColors()) {
1423
            double major = Math.max(width, height);
1424
            int steps = Math.max(1, Math.min(24, (int) Math.ceil(major / 6.0)));
1425
            if (steps > 1) {
1426
                if (width >= height) {
1427
                    for (int i = 0; i < steps; i++) {
1428
                        double ax1 = sx1 + width * (i / (double) steps);
1429
                        double ax2 = sx1 + width * ((i + 1.0) / steps);
1430
                        drawGradientQuadSingle(renderer, ax1, sy1, ax2, sy2,
1431
                                boxX1, boxY1, boxX2, boxY2, colors);
1432
                    }
1433
                } else {
1434
                    for (int i = 0; i < steps; i++) {
1435
                        double ay1 = sy1 + height * (i / (double) steps);
1436
                        double ay2 = sy1 + height * ((i + 1.0) / steps);
1437
                        drawGradientQuadSingle(renderer, sx1, ay1, sx2, ay2,
1438
                                boxX1, boxY1, boxX2, boxY2, colors);
1439
                    }
1440
                }
1441
                return;
1442
            }
1443
        }
1444
1445
        drawGradientQuadSingle(renderer, sx1, sy1, sx2, sy2,
1446
                boxX1, boxY1, boxX2, boxY2, colors);
1447
    }
1448
1449
    private static void drawGradientQuadSingle(Renderer2D renderer,
1450
                                               double sx1, double sy1, double sx2, double sy2,
1451
                                               double boxX1, double boxY1, double boxX2, double boxY2,
1452
                                               ColorResolver colors) {
1453
        renderer.quad(
1454
                sx1, sy1, sx2 - sx1, sy2 - sy1,
1455
                colors.colorAt(sx1, sy1, boxX1, boxY1, boxX2, boxY2),
1456
                colors.colorAt(sx2, sy1, boxX1, boxY1, boxX2, boxY2),
1457
                colors.colorAt(sx2, sy2, boxX1, boxY1, boxX2, boxY2),
1458
                colors.colorAt(sx1, sy2, boxX1, boxY1, boxX2, boxY2)
1459
        );
1460
    }
1461
1462
    private void add3DBox(MeshBuilder tris, MeshBuilder lines, AABB box, int argb) {
1463
        int rgb = argb & 0x00FFFFFF;
1464
        int fillAlpha = alpha255(box3dFillAlpha.get());
1465
        int outlineAlpha = alpha255(box3dOutlineAlpha.get());
1466
        float gradientStrength = Math.max(0.0f, Math.min(2.5f, box3dGradientStrength.get()));
1467
1468
        int c000 = boxGradientColor(rgb, box, box.minX, box.minY, box.minZ, fillAlpha, gradientStrength);
1469
        int c001 = boxGradientColor(rgb, box, box.minX, box.minY, box.maxZ, fillAlpha, gradientStrength);
1470
        int c010 = boxGradientColor(rgb, box, box.minX, box.maxY, box.minZ, fillAlpha, gradientStrength);
1471
        int c011 = boxGradientColor(rgb, box, box.minX, box.maxY, box.maxZ, fillAlpha, gradientStrength);
1472
        int c100 = boxGradientColor(rgb, box, box.maxX, box.minY, box.minZ, fillAlpha, gradientStrength);
1473
        int c101 = boxGradientColor(rgb, box, box.maxX, box.minY, box.maxZ, fillAlpha, gradientStrength);
1474
        int c110 = boxGradientColor(rgb, box, box.maxX, box.maxY, box.minZ, fillAlpha, gradientStrength);
1475
        int c111 = boxGradientColor(rgb, box, box.maxX, box.maxY, box.maxZ, fillAlpha, gradientStrength);
1476
1477
        addFilledBox(tris, box, c000, c001, c010, c011, c100, c101, c110, c111);
1478
        addOutlineBox(lines, box,
1479
                withAlpha(c000, outlineAlpha),
1480
                withAlpha(c001, outlineAlpha),
1481
                withAlpha(c010, outlineAlpha),
1482
                withAlpha(c011, outlineAlpha),
1483
                withAlpha(c100, outlineAlpha),
1484
                withAlpha(c101, outlineAlpha),
1485
                withAlpha(c110, outlineAlpha),
1486
                withAlpha(c111, outlineAlpha));
1487
    }
1488
1489
    public boolean shouldRenderHitboxReplacement(Entity entity) {
1490
        if (!isEnabled() || !is3DBox()) return false;
1491
        if (entity == null) return false;
1492
        if (entity instanceof Player player) {
1493
            return shouldRenderPlayer(player) && shouldUseHitboxExpansion(entity);
1494
        }
1495
        return false;
1496
    }
1497
1498
    private boolean shouldUseHitboxExpansion(Entity entity) {
1499
        Hitbox hitbox = Modules.get(Hitbox.class);
1500
        return hitbox != null && hitbox.isReplacementCandidate(entity);
1501
    }
1502
1503
    public boolean shouldLiftNameTagsSection(Player player) {
1504
        return isEnabled() && isNameTagsLiftBoxMode() && shouldRenderPlayer(player);
1505
    }
1506
1507
    private boolean isNameTagsLiftBoxMode() {
1508
        return MODE_FULL.equalsIgnoreCase(boxMode.get())
1509
                || MODE_CORNERS.equalsIgnoreCase(boxMode.get());
1510
    }
1511
1512
    private boolean isShaderSmokeFill() {
1513
        return SHADER_FILL_SMOKE.equalsIgnoreCase(shaderFillStyle.get());
1514
    }
1515
1516
    private boolean isCornerBox() {
1517
        return MODE_CORNERS.equalsIgnoreCase(boxMode.get());
1518
    }
1519
1520
    private boolean is3DBox() {
1521
        return MODE_3D.equalsIgnoreCase(boxMode.get());
1522
    }
1523
1524
    private boolean isShaderBox() {
1525
        return MODE_SHADER.equalsIgnoreCase(boxMode.get());
1526
    }
1527
1528
    @FunctionalInterface
1529
    private interface ColorResolver {
1530
        int colorAt(double x, double y, double boxX1, double boxY1, double boxX2, double boxY2);
1531
    }
1532
1533
    private record RenderEntry(Entity entity, int color, double distSq) {
1534
    }
1535
1536
    private record SearchLabelEntry(Entity entity, double distSq, ScreenSpaceOverlay2D.ScreenRect rect, int color,
1537
                                    ScreenSpaceOverlay2D.LabelEntry label) {
1538
    }
1539
1540
    private record ScreenBox(double minX, double minY, double maxX, double maxY) {
1541
    }
1542
1543
    private record SolidColor(int color) implements ColorResolver {
1544
        static SolidColor of(int color) {
1545
            return new SolidColor(color);
1546
        }
1547
1548
        @Override
1549
        public int colorAt(double x, double y, double boxX1, double boxY1, double boxX2, double boxY2) {
1550
            return color;
1551
        }
1552
    }
1553
1554
    private final class AnimatedFrameGradient implements ColorResolver {
1555
        private final int alpha;
1556
1557
        private AnimatedFrameGradient(int alpha) {
1558
            this.alpha = alpha;
1559
        }
1560
1561
        @Override
1562
        public int colorAt(double x, double y, double boxX1, double boxY1, double boxX2, double boxY2) {
1563
            double width = Math.max(1.0e-6, boxX2 - boxX1);
1564
            double height = Math.max(1.0e-6, boxY2 - boxY1);
1565
            double tx = (x - boxX1) / width;
1566
            double ty = (y - boxY1) / height;
1567
            return customPaletteColor(tx, ty, alpha);
1568
        }
1569
    }
1570
1571
    private record Gradient(int topLeft, int topRight, int bottomRight, int bottomLeft) implements ColorResolver {
1572
        private static double safeRatio(double value, double length) {
1573
            if (length <= 0.0001) return 0.0;
1574
            if (value <= 0.0) return 0.0;
1575
            if (value >= length) return 1.0;
1576
            return value / length;
1577
        }
1578
1579
        @Override
1580
        public int colorAt(double x, double y, double boxX1, double boxY1, double boxX2, double boxY2) {
1581
            double tx = safeRatio(x - boxX1, boxX2 - boxX1);
1582
            double ty = safeRatio(y - boxY1, boxY2 - boxY1);
1583
1584
            int top = mixArgb(topLeft, topRight, (float) tx);
1585
            int bottom = mixArgb(bottomLeft, bottomRight, (float) tx);
1586
            return mixArgb(top, bottom, (float) ty);
1587
        }
1588
    }
1589
1590
    private final class ShaderEspPass implements PostProcessPass, PostProcessBackendResourceOwner {
1591
        @Override
1592
        public boolean isActive() {
1593
            return ESP.this.isEnabled()
1594
                    && ESP.this.isShaderBox()
1595
                    && mc.player != null
1596
                    && mc.level != null;
1597
        }
1598
1599
        @Override
1600
        public Phase getPhase() {
1601
            return Phase.PRE_HAND;
1602
        }
1603
1604
        @Override
1605
        public boolean render(PostProcessExecutionContext execution) {
1606
            if (execution == null || execution.context() == null) return false;
1607
            return ESP.this.renderShaderEsp(
1608
                    execution.source(), execution.destination(), execution.context().tickDelta());
1609
        }
1610
1611
        @Override
1612
        public void releaseBackendResources(CombatantRhi owner) {
1613
            shaderEspComputeBlur.release(owner);
1614
        }
1615
    }
1616
}
1617
KiwiClientRENDERsrc/main/java/com/tangykiwi/kiwiclient/module/render/ESP.javaJava · 61 lines · 2.6 KB

Highlights entities

SettingsModeBoxFill
ESP.javaJava · Minecraft 26.2 · 61 lines · 2.6 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.render;
2
3
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
4
5
import com.google.common.eventbus.Subscribe;
6
import com.tangykiwi.kiwiclient.event.LevelRenderEvent;
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.EntityUtils;
12
import com.tangykiwi.kiwiclient.util.render.RenderUtils;
13
14
import net.minecraft.world.entity.Entity;
15
16
public class ESP extends Module {
17
    public ESP() {
18
        super("ESP", "Highlights entities", Category.RENDER,
19
                new ModeSetting("Mode", "ESP mode", "Shader", "Box+Fill", "Box", "Fill"),
20
                new SliderSetting("Box", "Box line thickness", 0.1, 4, 2, 1),
21
                new SliderSetting("Fill", "Fill opacity", 0, 1, 0.3, 2));
22
    }
23
24
    // shader handling done in MinecraftClientMixin, WorldRendererMixin
25
26
    @Subscribe
27
    public void onWorldRenderPost(LevelRenderEvent event) {
28
        if (getSetting("Mode").asMode().getValue() != 0) {
29
            float width = getSetting("Box").asSlider().getValueFloat();
30
            float fill = getSetting("Fill").asSlider().getValueFloat();
31
32
            for (Entity entity : mc.level.entitiesForRendering()) {
33
                if (entity == mc.player || entity == mc.player.getVehicle()) continue;
34
                int color = getColor(entity);
35
                if (color != -1) {
36
                    if (fill != 0 && (getSetting("Mode").asMode().getValue() == 1 || getSetting("Mode").asMode().getValue() == 3)) {
37
                        int fillColor = ((int)(fill * 255) << 24) | color;
38
                        RenderUtils.drawBoxFilled(event.getSubmitNodeStorage(), entity.getBoundingBox(), fillColor);
39
                    }
40
                    if (getSetting("Mode").asMode().getValue() == 1 || getSetting("Mode").asMode().getValue() == 2) {
41
                        int outlineColor = (255 << 24) | color;
42
                        RenderUtils.drawBoxOutline(event.getSubmitNodeStorage(), entity.getBoundingBox(), outlineColor, width);
43
                    }
44
45
                }
46
            }
47
        }
48
    }
49
50
    public int getColor(Entity entity) {
51
        if (EntityUtils.isPlayer(entity)) {
52
            return (255 << 16) | (255 << 8) | 255;
53
        } else if (EntityUtils.isMob(entity)) {
54
            return (255 << 16) | (0 << 8) | 0;
55
        } else if (EntityUtils.isAnimal(entity)) {
56
            return (77 << 16) | (255 << 8) | 77;
57
        }
58
        return (128 << 16) | (128 << 8) | 128;
59
    }
60
}
61
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/esp/ModuleESP.ktKotlin · 106 lines · 3.7 KB

Allows you to see targets through walls.

SettingsInvisibleFriendsMaximumDistance
ModuleESP.ktKotlin · Minecraft 26.2 · 106 lines · 3.7 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.esp
20
21
import net.ccbluex.liquidbounce.config.ConfigSystem
22
import net.ccbluex.liquidbounce.features.misc.FriendManager
23
import net.ccbluex.liquidbounce.features.module.ClientModule
24
import net.ccbluex.liquidbounce.features.module.ModuleCategories
25
import net.ccbluex.liquidbounce.features.module.modules.render.esp.modes.Esp2DMode
26
import net.ccbluex.liquidbounce.features.module.modules.render.esp.modes.EspBoxMode
27
import net.ccbluex.liquidbounce.features.module.modules.render.esp.modes.EspGlowMode
28
import net.ccbluex.liquidbounce.features.module.modules.render.esp.modes.EspLegacy2DMode
29
import net.ccbluex.liquidbounce.render.GenericDistanceHSBColorMode
30
import net.ccbluex.liquidbounce.render.GenericEntityHealthColorMode
31
import net.ccbluex.liquidbounce.render.GenericRainbowColorMode
32
import net.ccbluex.liquidbounce.render.GenericStaticColorMode
33
import net.ccbluex.liquidbounce.render.engine.type.Color4b
34
import net.ccbluex.liquidbounce.utils.combat.EntityTaggingManager
35
import net.ccbluex.liquidbounce.utils.combat.shouldBeShown
36
import net.ccbluex.liquidbounce.utils.entity.RenderedEntities
37
import net.minecraft.world.entity.LivingEntity
38
import net.minecraft.world.entity.player.Player
39
40
/**
41
 * ESP module
42
 *
43
 * Allows you to see targets through walls.
44
 */
45
object ModuleESP : ClientModule("ESP", ModuleCategories.RENDER) {
46
47
    override val baseKey: String
48
        get() = "${ConfigSystem.KEY_PREFIX}.module.esp"
49
50
    val modes = choices("Mode", EspGlowMode, arrayOf(
51
        EspBoxMode,
52
        Esp2DMode,
53
        EspLegacy2DMode,
54
//        EspOutlineMode,
55
        EspGlowMode
56
    ))
57
58
    private val colorModes = choices("ColorMode", 0) {
59
        arrayOf(
60
            GenericDistanceHSBColorMode.entity(it),
61
            GenericEntityHealthColorMode(it),
62
            GenericStaticColorMode(it, Color4b.WHITE.with(a = 100)),
63
            GenericRainbowColorMode(it)
64
        )
65
    }
66
    private val invisibleColor by color("Invisible", Color4b.ORANGE)
67
    private val friendColor by color("Friends", Color4b.GREEN)
68
69
    internal val maximumDistance by float("MaximumDistance", 128F, 1F..512F)
70
71
    override fun onEnabled() {
72
        RenderedEntities.subscribe(this)
73
    }
74
75
    override fun onDisabled() {
76
        RenderedEntities.unsubscribe(this)
77
    }
78
79
    fun getColor(entity: LivingEntity): Color4b {
80
        if (entity.hurtTime > 0) {
81
            return Color4b.RED
82
        }
83
84
        if (entity.isInvisible) {
85
            return invisibleColor
86
        }
87
88
        if (entity is Player) {
89
            if (FriendManager.isFriend(entity) && friendColor.a > 0) {
90
                return friendColor
91
            }
92
93
            EntityTaggingManager.getTag(entity).color?.let { return it }
94
        }
95
96
        return colorModes.activeMode.getColor(entity)
97
    }
98
99
    /**
100
     * Check if the entity requires true sight to be shown with the current ESP mode
101
     */
102
    fun requiresTrueSight(entity: LivingEntity) =
103
        modes.activeMode.requiresTrueSight && entity.shouldBeShown()
104
105
}
106