Predictions module

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

1 implementationVISUALS

Clients with this module

Full module source: 1 implementation

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

CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/Predictions.javaJava · 1,483 lines · 65.8 KB
Settingspred_line_colorpred_pearl_custom_colorpred_pearl_colorpred_max_tickspred_pearl_max_tickspred_max_projectilespred_pearl_max_projectilespred_show_timer_platepred_aim_trajectorypred_aim_indicatorpred_targethud_on_aimpred_glow_wallspred_tnt_timerpred_tnt_colorpred_kind_toggles
Predictions.javaJava · Minecraft 26.2 · 1,483 lines · 65.8 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.visuals;
9
10
import combatant.client.render.engine.text.BuiltinFontCatalog;
11
import com.mojang.blaze3d.pipeline.RenderPipeline;
12
import com.mojang.blaze3d.vertex.PoseStack;
13
import combatant.client.features.module.*;
14
import combatant.client.features.module.Module;
15
import net.minecraft.client.Minecraft;
16
import net.minecraft.client.multiplayer.ClientLevel;
17
import net.minecraft.client.renderer.SubmitNodeCollector;
18
import net.minecraft.resources.Identifier;
19
import net.minecraft.util.Mth;
20
import net.minecraft.world.InteractionHand;
21
import net.minecraft.world.entity.Entity;
22
import net.minecraft.world.entity.ExperienceOrb;
23
import net.minecraft.world.entity.LivingEntity;
24
import net.minecraft.world.entity.item.ItemEntity;
25
import net.minecraft.world.entity.item.PrimedTnt;
26
import net.minecraft.world.entity.player.Player;
27
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
28
import net.minecraft.world.entity.projectile.Projectile;
29
import net.minecraft.world.entity.projectile.ProjectileUtil;
30
import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
31
import net.minecraft.world.entity.projectile.arrow.ThrownTrident;
32
import net.minecraft.world.entity.projectile.hurtingprojectile.Fireball;
33
import net.minecraft.world.entity.projectile.hurtingprojectile.SmallFireball;
34
import net.minecraft.world.entity.projectile.hurtingprojectile.windcharge.WindCharge;
35
import net.minecraft.world.entity.projectile.throwableitemprojectile.*;
36
import net.minecraft.world.item.BowItem;
37
import net.minecraft.world.item.CrossbowItem;
38
import net.minecraft.world.item.ItemStack;
39
import net.minecraft.world.item.Items;
40
import net.minecraft.world.level.ClipContext;
41
import net.minecraft.world.phys.AABB;
42
import net.minecraft.world.phys.EntityHitResult;
43
import net.minecraft.world.phys.HitResult;
44
import net.minecraft.world.phys.Vec3;
45
import org.joml.Quaternionf;
46
import org.joml.Vector3f;
47
import combatant.client.config.values.BooleanMapValue;
48
import combatant.client.config.values.BooleanValue;
49
import combatant.client.config.values.NumberValue;
50
import combatant.client.config.values.RGBColorValue;
51
import combatant.client.features.module.*;
52
import combatant.client.mixins.accessors.PersistentProjectileEntityAccessor;
53
import combatant.client.render.engine.RenderState;
54
import combatant.client.render.engine.TextureStorage;
55
import combatant.client.render.engine.animation.AnimationUtility;
56
import combatant.client.render.engine.color.RenderColor;
57
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
58
import combatant.client.render.engine.renderer.Renderer2D;
59
import combatant.client.render.engine.renderer.Renderer3D;
60
import combatant.client.render.engine.text.TextRenderer;
61
import combatant.client.render.engine.uniform.MeshBuilder;
62
import combatant.client.render.helpers.MatteHudStyle;
63
import combatant.client.render.helpers.ScreenProjection;
64
import combatant.client.util.target.TargetManager;
65
66
import java.util.ArrayList;
67
import java.util.Collections;
68
import java.util.List;
69
import java.util.Locale;
70
71
//todo Description
72
@ModuleInfo(id = "predictions", displayName = "Predictions", category = ModuleCategory.VISUALS)
73
public class Predictions extends Module {
74
    private static final String SETTING_LINE_COLOR = "line_color";
75
    private static final String SETTING_PEARL_CUSTOM_COLOR = "pearl_custom_color";
76
    private static final String SETTING_PEARL_COLOR = "pearl_color";
77
    private static final String SETTING_MAX_SIM_TICKS = "max_sim_ticks";
78
    private static final String SETTING_PEARL_MAX_SIM_TICKS = "pearl_max_ticks";
79
    private static final String SETTING_MAX_PROJECTILES = "max_projectiles";
80
    private static final String SETTING_PEARL_MAX_PROJECTILES = "pearl_max_projectiles";
81
    private static final String SETTING_SHOW_TIMER_PLATE = "show_plate";
82
    private static final String SETTING_AIM_TRAJECTORY = "aim_trajectory";
83
    private static final String SETTING_AIM_INDICATOR = "aim_indicator";
84
    private static final String SETTING_TARGETHUD_ON_AIM = "targethud_on_aim";
85
    private static final String SETTING_GLOW_WALLS = "glow_walls";
86
    private static final String SETTING_TNT_TIMER = "tnt_timer";
87
    private static final String SETTING_TNT_COLOR = "tnt_color";
88
    private static final String SETTING_PROJECTILES = "projectiles";
89
90
    private static final int HIT_SELF_COLOR = 0xFFFF4444;
91
    private static final int HIT_ENTITY_COLOR = 0xFFFFCC44;
92
    private static final int GLOW_SUBSTEPS = 10;
93
    private static final float GLOW_CORE_SIZE = 0.085f;
94
    private static final float GLOW_SOFT_SIZE = 0.16f;
95
    private static final float GLOW_CORE_ALPHA = 0.74f;
96
    private static final float GLOW_SOFT_ALPHA = 0.32f;
97
    private static final float AIM_TRAJECTORY_LINE_WIDTH = 1.0f;
98
    private static final float AIM_TRAJECTORY_DASH_LENGTH = 0.17f;
99
    private static final float AIM_TRAJECTORY_DASH_GAP = 0.105f;
100
    private static final float AIM_TRAJECTORY_ALPHA_MIN = 0.08f;
101
    private static final float AIM_TRAJECTORY_ALPHA_MAX = 0.58f;
102
    private static final double AIM_TRAJECTORY_MIN_CAMERA_DISTANCE_SQ = 0.64;
103
    private static final double AIM_SMOOTH_RATE = 19.0;
104
    private static final double AIM_SMOOTH_MAX_DT = 0.05;
105
    private static final double AIM_SMOOTH_SNAP_DISTANCE_SQ = 9.0;
106
    private static final float IMPACT_CORE_SIZE = 0.24f;
107
    private static final float IMPACT_SOFT_SIZE = 0.48f;
108
    private static final float IMPACT_CORE_ALPHA = 0.95f;
109
    private static final float IMPACT_SOFT_ALPHA = 0.42f;
110
    private static final double IMPACT_BOX_EXPAND = 0.03;
111
    private static final int ENTITY_HIT_FILL_ALPHA = 34;
112
    private static final int ENTITY_HIT_LINE_ALPHA = 170;
113
    private static final float ENTITY_HIT_LINE_WIDTH = 1.5f;
114
    private static final float PLATE_RADIUS = 3.6f;
115
    private static final float PLATE_TEXT_SCALE = 0.84f;
116
    private static final float PLATE_HEIGHT = 19.0f;
117
    private static final float PLATE_PAD_X = 3.6f;
118
    private static final float PLATE_ICON_SIZE = 15.0f;
119
    private static final float PLATE_ICON_TEXT_GAP = 3.6f;
120
    private static final float PLATE_TEXT_OFFSET_Y = 0.0f;
121
    private static final float TRAJECTORY_LINE_WIDTH = 1.35f;
122
    private static final float TRAJECTORY_LINE_ALPHA_START = 0.16f;
123
    private static final float TRAJECTORY_LINE_ALPHA_END = 0.78f;
124
    private static final float ENTITY_HIT_OUTLINE_WIDTH = 1.2f;
125
    private static final float IMPACT_DECAL_RADIUS = 0.38f;
126
    private static final float IMPACT_DECAL_EDGE_SOFTNESS = 0.018f;
127
    private static final float IMPACT_DECAL_STROKE_WIDTH = 0.022f;
128
    private static final float IMPACT_DECAL_PATTERN_SCALE = 22.0f;
129
    private static final float IMPACT_DECAL_FILL_ALPHA = 0.07f;
130
    private static final float IMPACT_DECAL_STROKE_ALPHA = 0.90f;
131
    private static final float IMPACT_DECAL_PATTERN_STRENGTH = 0.68f;
132
    private static final float IMPACT_DECAL_QUAD_PADDING = 1.16f;
133
    private static final double IMPACT_DECAL_OFFSET = 0.004;
134
    private static final float AIM_DECAL_RADIUS = 0.48f;
135
    private static final float AIM_DECAL_EDGE_SOFTNESS = 0.014f;
136
    private static final float AIM_DECAL_LINE_WIDTH = 0.020f;
137
    private static final float AIM_DECAL_PRIMARY_ALPHA = 0.90f;
138
    private static final float AIM_DECAL_SECONDARY_ALPHA = 0.54f;
139
    private static final float AIM_DECAL_FILL_ALPHA = 0.035f;
140
    private static final float AIM_DECAL_QUAD_PADDING = 1.15f;
141
    private static final double AIM_DECAL_OFFSET = 0.0045;
142
143
    private final Minecraft mc = Minecraft.getInstance();
144
145
    private final RGBColorValue lineColorValue = colorNoAlpha("pred_line_color", SETTING_LINE_COLOR, "#11C7C7");
146
    private final BooleanValue pearlColorToggle = bool("pred_pearl_custom_color", SETTING_PEARL_CUSTOM_COLOR, false);
147
    private final RGBColorValue pearlColorValue =
148
            visibleWhen(colorNoAlpha("pred_pearl_color", SETTING_PEARL_COLOR, "#C68CFF"), pearlColorToggle::get);
149
    private final NumberValue<Integer> maxSimTicks =
150
            num("pred_max_ticks", SETTING_MAX_SIM_TICKS, 120, 20, 600);
151
    private final NumberValue<Integer> pearlMaxSimTicks =
152
            num("pred_pearl_max_ticks", SETTING_PEARL_MAX_SIM_TICKS, 160, 20, 1000);
153
    private final NumberValue<Integer> maxProjectiles =
154
            num("pred_max_projectiles", SETTING_MAX_PROJECTILES, 48, 1, 256);
155
    private final NumberValue<Integer> pearlMaxProjectiles =
156
            num("pred_pearl_max_projectiles", SETTING_PEARL_MAX_PROJECTILES, 12, 1, 128);
157
    private final BooleanValue showTimerPlateValue = bool("pred_show_timer_plate", SETTING_SHOW_TIMER_PLATE, true);
158
    private final BooleanValue aimTrajectoryValue = bool("pred_aim_trajectory", SETTING_AIM_TRAJECTORY, true);
159
    private final BooleanValue aimIndicatorValue = bool("pred_aim_indicator", SETTING_AIM_INDICATOR, false);
160
    private final BooleanValue targetHudOnAimValue = bool("pred_targethud_on_aim", SETTING_TARGETHUD_ON_AIM, false);
161
    private final BooleanValue glowWallsValue = bool("pred_glow_walls", SETTING_GLOW_WALLS, false);
162
    private final BooleanValue tntTimerValue = bool("pred_tnt_timer", SETTING_TNT_TIMER, true);
163
    private final RGBColorValue tntColorValue =
164
            visibleWhen(colorNoAlpha("pred_tnt_color", SETTING_TNT_COLOR, "#FF5555"), tntTimerValue::get);
165
    private final BooleanMapValue kindToggles = group("pred_kind_toggles", SETTING_PROJECTILES, new java.util.LinkedHashMap<>() {{
166
        put("arrow", true);
167
        put("trident", true);
168
        put("fireball", true);
169
        put("wind_charge", true);
170
        put("firework", true);
171
        put("snowball", true);
172
        put("egg", true);
173
        put("potion_splash", true);
174
        put("potion_lingering", true);
175
    }});
176
177
    private ItemStack tntTimerIcon = ItemStack.EMPTY;
178
    private final List<TimerPlate> timerPlates = new ArrayList<>();
179
    private List<Vec3> smoothedAimPoints = List.of();
180
    private Vec3 smoothedAimHitPos;
181
    private Vec3 smoothedAimNormal;
182
    private Kind smoothedAimKind;
183
    private Entity smoothedAimEntity;
184
    private long lastAimSmoothNanos;
185
186
    private static boolean canHitPredictedEntity(Entity projectile, Entity entity, AABB collisionBox) {
187
        if (projectile == null || entity == null || !entity.isAlive() || !entity.canBeHitByProjectile()) {
188
            return false;
189
        }
190
191
        if (projectile instanceof Projectile projectileEntity) {
192
            Entity owner = projectileEntity.getOwner();
193
            if (owner != null && !hasPredictedLeftOwner(owner, entity, collisionBox)) {
194
                return !owner.isPassengerOfSameVehicle(entity);
195
            }
196
        }
197
198
        return true;
199
    }
200
201
    private static boolean hasPredictedLeftOwner(Entity owner, Entity entity, AABB collisionBox) {
202
        if (owner == null || collisionBox == null) {
203
            return true;
204
        }
205
        return owner.getRootVehicle()
206
                .getSelfAndPassengers()
207
                .filter(Entity::isPickable)
208
                .noneMatch(passenger -> collisionBox.intersects(passenger.getBoundingBox()));
209
    }
210
211
    private static void addGradientLine(MeshBuilder mesh, Vec3 from, Vec3 to, int startColor, int endColor) {
212
        if (mesh == null || from == null || to == null) return;
213
        mesh.ensureLineCapacity();
214
        int i1 = mesh.vec3(from.x, from.y, from.z).color(new RenderColor(startColor)).next();
215
        int i2 = mesh.vec3(to.x, to.y, to.z).color(new RenderColor(endColor)).next();
216
        mesh.line(i1, i2);
217
    }
218
219
    private static Vec3 resolveDecalNormal(Vec3 normal) {
220
        return normal == null || normal.lengthSqr() < 1.0E-6
221
                ? new Vec3(0.0, 1.0, 0.0)
222
                : normal.normalize();
223
    }
224
225
    private static Vec3 resolveDecalTangent(Vec3 normal, Vec3 preferredDirection) {
226
        Vec3 useNormal = resolveDecalNormal(normal);
227
        if (preferredDirection != null && preferredDirection.lengthSqr() > 1.0E-6) {
228
            Vec3 projected = preferredDirection.subtract(useNormal.scale(preferredDirection.dot(useNormal)));
229
            if (projected.lengthSqr() > 1.0E-6) {
230
                return projected.normalize();
231
            }
232
        }
233
234
        Vec3 axis = Math.abs(useNormal.y) < 0.95
235
                ? new Vec3(0.0, 1.0, 0.0)
236
                : new Vec3(1.0, 0.0, 0.0);
237
        Vec3 tangent = useNormal.cross(axis);
238
        return tangent.lengthSqr() < 1.0E-6
239
                ? new Vec3(1.0, 0.0, 0.0)
240
                : tangent.normalize();
241
    }
242
243
    private static Vec3 impactDirection(TrajectoryResult result) {
244
        if (result == null || result.points() == null || result.points().size() < 2) return null;
245
        List<Vec3> points = result.points();
246
        Vec3 direction = points.getLast().subtract(points.get(points.size() - 2));
247
        return direction.lengthSqr() > 1.0E-6 ? direction.normalize() : null;
248
    }
249
250
    private static void addImpactDecal(MeshBuilder mesh, Vec3 center, Vec3 normal, Vec3 preferredDirection,
251
                                       float radius, int argb) {
252
        addDecalQuad(
253
                mesh, center, normal, preferredDirection, radius, IMPACT_DECAL_QUAD_PADDING, IMPACT_DECAL_OFFSET, argb,
254
                1.0f / IMPACT_DECAL_QUAD_PADDING, IMPACT_DECAL_EDGE_SOFTNESS, IMPACT_DECAL_STROKE_WIDTH, IMPACT_DECAL_PATTERN_SCALE,
255
                IMPACT_DECAL_FILL_ALPHA, IMPACT_DECAL_STROKE_ALPHA, IMPACT_DECAL_PATTERN_STRENGTH, 0.0f
256
        );
257
    }
258
259
    private static void addAimDecal(MeshBuilder mesh, Vec3 center, Vec3 normal, Vec3 preferredDirection,
260
                                    float radius, int argb, float pulse) {
261
        addDecalQuad(
262
                mesh, center, normal, preferredDirection, radius, AIM_DECAL_QUAD_PADDING, AIM_DECAL_OFFSET, argb,
263
                1.0f / AIM_DECAL_QUAD_PADDING, AIM_DECAL_EDGE_SOFTNESS, AIM_DECAL_LINE_WIDTH, pulse,
264
                AIM_DECAL_PRIMARY_ALPHA, AIM_DECAL_SECONDARY_ALPHA, AIM_DECAL_FILL_ALPHA, 0.0f
265
        );
266
    }
267
268
    private static void addDecalQuad(MeshBuilder mesh, Vec3 center, Vec3 normal, Vec3 preferredDirection,
269
                                     float radius, float quadPadding, double offset, int argb,
270
                                     float p0, float p1, float p2, float p3,
271
                                     float q0, float q1, float q2, float q3) {
272
        if (mesh == null || center == null || radius <= 0.0f) return;
273
274
        Vec3 useNormal = resolveDecalNormal(normal);
275
        Vec3 tangent = resolveDecalTangent(useNormal, preferredDirection);
276
        Vec3 bitangent = useNormal.cross(tangent);
277
        if (bitangent.lengthSqr() < 1.0E-6) return;
278
        bitangent = bitangent.normalize();
279
280
        Vec3 offsetCenter = center.add(useNormal.scale(offset));
281
        float quadRadius = radius * quadPadding;
282
        Vec3 tangentScaled = tangent.scale(quadRadius);
283
        Vec3 bitangentScaled = bitangent.scale(quadRadius);
284
        Vec3 p00 = offsetCenter.subtract(tangentScaled).subtract(bitangentScaled);
285
        Vec3 p10 = offsetCenter.add(tangentScaled).subtract(bitangentScaled);
286
        Vec3 p11 = offsetCenter.add(tangentScaled).add(bitangentScaled);
287
        Vec3 p01 = offsetCenter.subtract(tangentScaled).add(bitangentScaled);
288
289
        mesh.ensureQuadCapacity();
290
        int i1 = addDecalVertex(mesh, p00, 0.0f, 0.0f, argb, p0, p1, p2, p3, q0, q1, q2, q3);
291
        int i2 = addDecalVertex(mesh, p10, 1.0f, 0.0f, argb, p0, p1, p2, p3, q0, q1, q2, q3);
292
        int i3 = addDecalVertex(mesh, p11, 1.0f, 1.0f, argb, p0, p1, p2, p3, q0, q1, q2, q3);
293
        int i4 = addDecalVertex(mesh, p01, 0.0f, 1.0f, argb, p0, p1, p2, p3, q0, q1, q2, q3);
294
        mesh.quad(i1, i2, i3, i4);
295
    }
296
297
    private static int addDecalVertex(MeshBuilder mesh, Vec3 pos, float u, float v, int argb,
298
                                      float p0, float p1, float p2, float p3,
299
                                      float q0, float q1, float q2, float q3) {
300
        return mesh.vec3(pos.x, pos.y, pos.z)
301
                .vec2(u, v)
302
                .color(new RenderColor(argb))
303
                .vec4(p0, p1, p2, p3)
304
                .vec4(q0, q1, q2, q3)
305
                .next();
306
    }
307
308
    private static Vec3 resolveImpactNormal(HitResult hit, Vec3 velocity) {
309
        if (hit instanceof net.minecraft.world.phys.BlockHitResult blockHit) {
310
            return Vec3.atLowerCornerOf(blockHit.getDirection().getUnitVec3i());
311
        }
312
        if (velocity != null && velocity.lengthSqr() > 1.0E-6) {
313
            return velocity.normalize();
314
        }
315
        return new Vec3(0.0, 1.0, 0.0);
316
    }
317
318
    private static double partialStepProgress(Vec3 from, Vec3 hitPos, double segmentLengthSq) {
319
        if (from == null || hitPos == null || segmentLengthSq <= 1.0E-6) {
320
            return 1.0;
321
        }
322
        return Mth.clamp(from.distanceTo(hitPos) / Math.sqrt(segmentLengthSq), 0.0, 1.0);
323
    }
324
325
    private static Vec3 resolveEntityImpactNormal(AABB box, Vec3 hitPos, Vec3 fallbackVelocity) {
326
        if (box == null || hitPos == null) {
327
            return resolveImpactNormal(null, fallbackVelocity);
328
        }
329
330
        double dxMin = Math.abs(hitPos.x - box.minX);
331
        double dxMax = Math.abs(box.maxX - hitPos.x);
332
        double dyMin = Math.abs(hitPos.y - box.minY);
333
        double dyMax = Math.abs(box.maxY - hitPos.y);
334
        double dzMin = Math.abs(hitPos.z - box.minZ);
335
        double dzMax = Math.abs(box.maxZ - hitPos.z);
336
337
        double best = dxMin;
338
        Vec3 normal = new Vec3(-1.0, 0.0, 0.0);
339
        if (dxMax < best) {
340
            best = dxMax;
341
            normal = new Vec3(1.0, 0.0, 0.0);
342
        }
343
        if (dyMin < best) {
344
            best = dyMin;
345
            normal = new Vec3(0.0, -1.0, 0.0);
346
        }
347
        if (dyMax < best) {
348
            best = dyMax;
349
            normal = new Vec3(0.0, 1.0, 0.0);
350
        }
351
        if (dzMin < best) {
352
            best = dzMin;
353
            normal = new Vec3(0.0, 0.0, -1.0);
354
        }
355
        if (dzMax < best) {
356
            normal = new Vec3(0.0, 0.0, 1.0);
357
        }
358
        return normal;
359
    }
360
361
    private static void addBillboardQuad(MeshBuilder mesh, double cx, double cy, double cz,
362
                                         float size, Quaternionf camRot, int argb) {
363
        Vector3f right = new Vector3f(1.0f, 0.0f, 0.0f).rotate(camRot).mul(size);
364
        Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f).rotate(camRot).mul(size);
365
366
        double p1x = cx - right.x() - up.x();
367
        double p1y = cy - right.y() - up.y();
368
        double p1z = cz - right.z() - up.z();
369
        double p2x = cx + right.x() - up.x();
370
        double p2y = cy + right.y() - up.y();
371
        double p2z = cz + right.z() - up.z();
372
        double p3x = cx + right.x() + up.x();
373
        double p3y = cy + right.y() + up.y();
374
        double p3z = cz + right.z() + up.z();
375
        double p4x = cx - right.x() + up.x();
376
        double p4y = cy - right.y() + up.y();
377
        double p4z = cz - right.z() + up.z();
378
379
        mesh.ensureQuadCapacity();
380
        int i1 = mesh.vec3(p1x, p1y, p1z).vec2(0.0, 1.0).color(new RenderColor(argb)).next();
381
        int i2 = mesh.vec3(p2x, p2y, p2z).vec2(1.0, 1.0).color(new RenderColor(argb)).next();
382
        int i3 = mesh.vec3(p3x, p3y, p3z).vec2(1.0, 0.0).color(new RenderColor(argb)).next();
383
        int i4 = mesh.vec3(p4x, p4y, p4z).vec2(0.0, 0.0).color(new RenderColor(argb)).next();
384
        mesh.quad(i1, i2, i3, i4);
385
    }
386
387
    private static void addFilledBox(Renderer3D renderer, AABB box, int argb) {
388
        int a = (argb >>> 24) & 0xFF;
389
        int r = (argb >>> 16) & 0xFF;
390
        int g = (argb >>> 8) & 0xFF;
391
        int b = argb & 0xFF;
392
393
        double minX = box.minX;
394
        double minY = box.minY;
395
        double minZ = box.minZ;
396
        double maxX = box.maxX;
397
        double maxY = box.maxY;
398
        double maxZ = box.maxZ;
399
400
        renderer.quad(minX, minY, minZ, maxX, minY, minZ, maxX, minY, maxZ, minX, minY, maxZ, r, g, b, a);
401
        renderer.quad(minX, maxY, minZ, minX, maxY, maxZ, maxX, maxY, maxZ, maxX, maxY, minZ, r, g, b, a);
402
        renderer.quad(minX, minY, maxZ, maxX, minY, maxZ, maxX, maxY, maxZ, minX, maxY, maxZ, r, g, b, a);
403
        renderer.quad(minX, minY, minZ, minX, maxY, minZ, maxX, maxY, minZ, maxX, minY, minZ, r, g, b, a);
404
        renderer.quad(maxX, minY, minZ, maxX, maxY, minZ, maxX, maxY, maxZ, maxX, minY, maxZ, r, g, b, a);
405
        renderer.quad(minX, minY, minZ, minX, minY, maxZ, minX, maxY, maxZ, minX, maxY, minZ, r, g, b, a);
406
    }
407
408
    private static void addOutlineBox(Renderer3D renderer, AABB box, int argb) {
409
        int a = (argb >>> 24) & 0xFF;
410
        int r = (argb >>> 16) & 0xFF;
411
        int g = (argb >>> 8) & 0xFF;
412
        int b = argb & 0xFF;
413
414
        double minX = box.minX;
415
        double minY = box.minY;
416
        double minZ = box.minZ;
417
        double maxX = box.maxX;
418
        double maxY = box.maxY;
419
        double maxZ = box.maxZ;
420
421
        renderer.line(minX, minY, minZ, maxX, minY, minZ, r, g, b, a);
422
        renderer.line(maxX, minY, minZ, maxX, minY, maxZ, r, g, b, a);
423
        renderer.line(maxX, minY, maxZ, minX, minY, maxZ, r, g, b, a);
424
        renderer.line(minX, minY, maxZ, minX, minY, minZ, r, g, b, a);
425
426
        renderer.line(minX, maxY, minZ, maxX, maxY, minZ, r, g, b, a);
427
        renderer.line(maxX, maxY, minZ, maxX, maxY, maxZ, r, g, b, a);
428
        renderer.line(maxX, maxY, maxZ, minX, maxY, maxZ, r, g, b, a);
429
        renderer.line(minX, maxY, maxZ, minX, maxY, minZ, r, g, b, a);
430
431
        renderer.line(minX, minY, minZ, minX, maxY, minZ, r, g, b, a);
432
        renderer.line(maxX, minY, minZ, maxX, maxY, minZ, r, g, b, a);
433
        renderer.line(maxX, minY, maxZ, maxX, maxY, maxZ, r, g, b, a);
434
        renderer.line(minX, minY, maxZ, minX, maxY, maxZ, r, g, b, a);
435
    }
436
437
    private static int multiplyAlpha(int argb, float alphaMultiplier) {
438
        int baseAlpha = (argb >>> 24) & 0xFF;
439
        int alpha = Math.max(0, Math.min(255, Math.round(baseAlpha * Math.max(0.0f, alphaMultiplier))));
440
        return (argb & 0x00FFFFFF) | (alpha << 24);
441
    }
442
443
    private static int withAlpha(int argb, int alpha) {
444
        return (argb & 0x00FFFFFF) | (Math.max(0, Math.min(255, alpha)) << 24);
445
    }
446
447
    private static Vec3 advanceTickVelocity(Entity entity, Vec3 velocity) {
448
        return velocity.scale(0.99).add(0.0, -entity.getGravity(), 0.0);
449
    }
450
451
    private static Kind kindFromParams(ItemStack stack) {
452
        if (stack == null) return Kind.ARROW;
453
        if (stack.is(Items.TRIDENT)) return Kind.TRIDENT;
454
        if (stack.is(Items.SPLASH_POTION)) return Kind.POTION_SPLASH;
455
        if (stack.is(Items.LINGERING_POTION)) return Kind.POTION_LINGERING;
456
        if (stack.is(Items.SNOWBALL)) return Kind.SNOWBALL;
457
        if (stack.is(Items.EGG)) return Kind.EGG;
458
        if (stack.is(Items.FIREWORK_ROCKET)) return Kind.FIREWORK;
459
        if (stack.is(Items.WIND_CHARGE)) return Kind.WIND_CHARGE;
460
        if (stack.is(Items.FIRE_CHARGE)) return Kind.FIREBALL;
461
        if (stack.is(Items.ENDER_PEARL)) return Kind.PEARL_ENTITY;
462
        return Kind.ARROW;
463
    }
464
465
    private static Kind kindFromProjectile(Entity entity) {
466
        if (entity instanceof ThrownTrident) return Kind.TRIDENT;
467
        if (entity instanceof AbstractThrownPotion potion) {
468
            return potion.getItem().is(Items.LINGERING_POTION) ? Kind.POTION_LINGERING : Kind.POTION_SPLASH;
469
        }
470
        if (entity instanceof Snowball) return Kind.SNOWBALL;
471
        if (entity instanceof ThrownEgg) return Kind.EGG;
472
        if (entity instanceof FireworkRocketEntity) return Kind.FIREWORK;
473
        if (entity instanceof WindCharge) return Kind.WIND_CHARGE;
474
        if (entity instanceof Fireball) return Kind.FIREBALL;
475
        if (entity instanceof ThrownEnderpearl) return Kind.PEARL_ENTITY;
476
        return Kind.ARROW;
477
    }
478
479
    @Override
480
    public WorldPhase getWorldPhase() {
481
        return WorldPhase.END_MAIN;
482
    }
483
484
    @Override
485
    public HudPhase getHudPhase() {
486
        return HudPhase.BEFORE_MISC_OVERLAYS;
487
    }
488
489
    @Override
490
    public void onDisable() {
491
        TargetManager.setPredictionTarget(null);
492
        resetAimSmoothing();
493
    }
494
495
    @Override
496
    public void onRenderWorld(PoseStack matrices, SubmitNodeCollector consumers, float tickDelta) {
497
    }
498
499
    @Override
500
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
501
        if (!isEnabled() || mc.level == null) {
502
            TargetManager.setPredictionTarget(null);
503
            resetAimSmoothing();
504
            return;
505
        }
506
507
        List<TrajectoryResult> results = simulateProjectiles(tickDelta);
508
        AimPrediction rawAim = mc.player != null ? computeAimPrediction(mc.player, tickDelta) : null;
509
        AimPrediction aim = smoothAimPrediction(rawAim);
510
        updatePredictionTarget(aim);
511
512
        int baseColor = lineColorValue.getArgb();
513
        if (aimTrajectoryValue.get()) {
514
            renderAimTrajectory(renderer, tickDelta, baseColor, aim);
515
        }
516
        if (aimIndicatorValue.get()) {
517
            renderAimIndicatorWorld(renderer, tickDelta, aim);
518
        }
519
520
        if (results.isEmpty()) return;
521
522
        renderLineTrajectories(renderer, results, baseColor);
523
        renderImpactEffects(renderer, results, baseColor, tickDelta);
524
    }
525
526
    @Override
527
    public void onRenderHudEngine(Renderer2D renderer, TextRenderer textRenderer, net.minecraft.client.gui.GuiGraphicsExtractor ctx, float tickDelta) {
528
        if (!isEnabled() || mc.level == null) return;
529
530
        boolean showPlate = showTimerPlateValue.get();
531
        timerPlates.clear();
532
        List<TrajectoryResult> results = showPlate ? simulateProjectiles(tickDelta) : Collections.emptyList();
533
        if (showPlate && !results.isEmpty()) {
534
            for (TrajectoryResult res : results) {
535
                if (res.points.isEmpty()) continue;
536
                Vec3 end = res.points.getLast();
537
                Vec3 screen = ScreenProjection.worldToScreen(end, tickDelta);
538
                if (screen == null) continue;
539
                drawTimerPlate(renderer, textRenderer, res, (float) screen.x, (float) screen.y);
540
            }
541
        }
542
543
        if (tntTimerValue.get()) {
544
            drawTntTimers(renderer, textRenderer, tickDelta);
545
        }
546
547
    }
548
549
    @Override
550
    public void onRenderHudEngineForeground(Renderer2D renderer, TextRenderer textRenderer, net.minecraft.client.gui.GuiGraphicsExtractor ctx, float tickDelta) {
551
        if (!isEnabled() || mc.level == null) return;
552
        if (timerPlates.isEmpty()) return;
553
554
        int seed = 0;
555
        List<TimerPlate> plates = timerPlates.isEmpty() ? List.of() : new ArrayList<>(timerPlates);
556
        for (TimerPlate plate : plates) {
557
            if (plate.iconStack().isEmpty()) continue;
558
            renderer.item(
559
                    plate.iconStack(),
560
                    plate.iconX(),
561
                    plate.iconY(),
562
                    plate.iconScale(),
563
                    seed++,
564
                    Renderer2D.ITEM_OVERLAY_NONE,
565
                    null
566
            );
567
        }
568
        if (!plates.isEmpty()) {
569
            TextRenderer tr = BuiltinFontCatalog.ONEST_MEDIUM.renderer(textRenderer);
570
            tr.begin(PLATE_TEXT_SCALE);
571
            for (TimerPlate plate : plates) {
572
                tr.render(plate.text(), plate.textX(), plate.textY(), new RenderColor(0xFFFFFFFF), false);
573
            }
574
            tr.end();
575
        }
576
    }
577
578
    private List<TrajectoryResult> simulateProjectiles(float tickDelta) {
579
        ClientLevel world = mc.level;
580
        if (world == null) return Collections.emptyList();
581
582
        List<TrajectoryResult> out = new ArrayList<>();
583
584
        List<Entity> candidates = new ArrayList<>();
585
        for (Entity e : world.entitiesForRendering()) {
586
            candidates.add(e);
587
        }
588
        candidates.sort((a, b) -> {
589
            double da = mc.player == null ? 0.0 : a.distanceToSqr(mc.player);
590
            double db = mc.player == null ? 0.0 : b.distanceToSqr(mc.player);
591
            return Double.compare(da, db);
592
        });
593
        int limit = Math.max(1, maxProjectiles.get());
594
        int processed = 0;
595
        int pearlProcessed = 0;
596
597
        for (Entity e : candidates) {
598
            if (!e.isAlive()) continue;
599
            if (!(e instanceof ThrownEnderpearl)) continue;
600
            if (pearlProcessed >= pearlMaxProjectiles.get()) break;
601
602
            TrajectoryResult res = simulateEntity(e, Kind.PEARL_ENTITY, tickDelta);
603
            if (res != null) out.add(res);
604
            pearlProcessed++;
605
        }
606
607
        for (Entity e : candidates) {
608
            if (!e.isAlive()) continue;
609
            if (e instanceof ThrownEnderpearl) continue;
610
            if (processed >= limit) break;
611
612
            switch (e) {
613
                case ThrownTrident trident -> {
614
                    if (isKindDisabled("trident")) continue;
615
                    if (trident.isNoPhysics() || isInGround(trident)) continue;
616
                    TrajectoryResult res = simulateEntity(trident, Kind.TRIDENT, tickDelta);
617
                    if (res != null) out.add(res);
618
                    processed++;
619
                }
620
                case AbstractArrow arrow -> {
621
                    if (isKindDisabled("arrow")) continue;
622
                    if (arrow.isNoPhysics() || isInGround(arrow)) continue;
623
                    TrajectoryResult res = simulateEntity(arrow, Kind.ARROW, tickDelta);
624
                    if (res != null) out.add(res);
625
                    processed++;
626
                }
627
                case Fireball fireball -> {
628
                    if (isKindDisabled("fireball")) continue;
629
                    TrajectoryResult res = simulateEntity(fireball, Kind.FIREBALL, tickDelta);
630
                    if (res != null) out.add(res);
631
                    processed++;
632
                }
633
                case WindCharge windCharge -> {
634
                    if (isKindDisabled("wind_charge")) continue;
635
                    TrajectoryResult res = simulateEntity(windCharge, Kind.WIND_CHARGE, tickDelta);
636
                    if (res != null) out.add(res);
637
                    processed++;
638
                }
639
                case FireworkRocketEntity firework -> {
640
                    if (isKindDisabled("firework")) continue;
641
                    TrajectoryResult res = simulateEntity(firework, Kind.FIREWORK, tickDelta);
642
                    if (res != null) out.add(res);
643
                    processed++;
644
                }
645
                case Snowball snowball -> {
646
                    if (isKindDisabled("snowball")) continue;
647
                    TrajectoryResult res = simulateEntity(snowball, Kind.SNOWBALL, tickDelta);
648
                    if (res != null) out.add(res);
649
                    processed++;
650
                }
651
                case ThrownEgg egg -> {
652
                    if (isKindDisabled("egg")) continue;
653
                    TrajectoryResult res = simulateEntity(egg, Kind.EGG, tickDelta);
654
                    if (res != null) out.add(res);
655
                    processed++;
656
                }
657
                case AbstractThrownPotion potion -> {
658
                    boolean lingering = potion.getItem().is(Items.LINGERING_POTION);
659
                    boolean splash = potion.getItem().is(Items.SPLASH_POTION) || !lingering;
660
                    if (lingering && isKindDisabled("potion_lingering")) continue;
661
                    if (splash && isKindDisabled("potion_splash")) continue;
662
                    Kind kind = lingering ? Kind.POTION_LINGERING : Kind.POTION_SPLASH;
663
                    TrajectoryResult res = simulateEntity(potion, kind, tickDelta);
664
                    if (res != null) out.add(res);
665
                    processed++;
666
                }
667
                default -> {
668
                }
669
            }
670
        }
671
672
        return out;
673
    }
674
675
    private TrajectoryResult simulateEntity(Entity e, Kind kind, float tickDelta) {
676
        ClientLevel world = mc.level;
677
        if (world == null) return null;
678
679
        Vec3 pos = e.position();
680
        Vec3 vel = e.getDeltaMovement();
681
682
        List<Vec3> points = new ArrayList<>();
683
        points.add(pos);
684
685
        double t = 0.0;
686
        int baseMaxTicks = Math.max(1, maxSimTicks.get());
687
        int maxTicks = kind == Kind.PEARL_ENTITY
688
                ? Math.max(1, pearlMaxSimTicks.get())
689
                : baseMaxTicks;
690
        int hitColor = 0;
691
        long impactTick = world.getGameTime();
692
        Vec3 impactPos = null;
693
        Vec3 impactNormal = null;
694
        Entity hitEntity = null;
695
        boolean hitBlock = false;
696
697
        for (int i = 0; i < maxTicks; i++) {
698
            Vec3 segmentStart = pos;
699
            Vec3 simulatedVelocity = advanceTickVelocity(e, vel);
700
            Vec3 simulatedPos = pos.add(simulatedVelocity);
701
            double segmentLengthSq = segmentStart.distanceToSqr(simulatedPos);
702
703
            HitResult hit = world.clip(new ClipContext(
704
                    segmentStart,
705
                    simulatedPos,
706
                    ClipContext.Block.COLLIDER,
707
                    ClipContext.Fluid.NONE,
708
                    e
709
            ));
710
711
            EntityCollision entityCollision = getEntityCollision(e, segmentStart, simulatedPos);
712
            boolean hasBlockHit = hit.getType() != HitResult.Type.MISS;
713
            boolean useEntityHit = entityCollision != null
714
                    && (!hasBlockHit || segmentStart.distanceToSqr(entityCollision.hitPos()) <= segmentStart.distanceToSqr(hit.getLocation()));
715
716
            if (useEntityHit) {
717
                hitColor = (entityCollision.entity() == mc.player) ? HIT_SELF_COLOR : HIT_ENTITY_COLOR;
718
                Vec3 entityHitPos = entityCollision.hitPos();
719
                t += partialStepProgress(segmentStart, entityHitPos, segmentLengthSq);
720
                points.add(entityHitPos);
721
                impactTick = world.getGameTime() + (long) Math.ceil(t);
722
                impactPos = entityHitPos;
723
                impactNormal = entityCollision.hitNormal();
724
                hitEntity = entityCollision.entity();
725
                break;
726
            } else if (hasBlockHit) {
727
                Vec3 blockHitPos = hit.getLocation();
728
                t += partialStepProgress(segmentStart, blockHitPos, segmentLengthSq);
729
                points.add(blockHitPos);
730
                impactTick = world.getGameTime() + (long) Math.ceil(t);
731
                impactPos = blockHitPos;
732
                impactNormal = resolveImpactNormal(hit, simulatedVelocity);
733
                hitBlock = true;
734
                break;
735
            }
736
737
            pos = simulatedPos;
738
            vel = simulatedVelocity;
739
            t += 1.0;
740
            points.add(pos);
741
            impactTick = world.getGameTime() + (long) Math.ceil(t);
742
        }
743
744
        ItemStack icon = switch (kind) {
745
            case PEARL_ENTITY -> new ItemStack(Items.ENDER_PEARL);
746
            case TRIDENT -> new ItemStack(Items.TRIDENT);
747
            case FIREBALL -> new ItemStack(Items.FIRE_CHARGE);
748
            case WIND_CHARGE -> new ItemStack(Items.WIND_CHARGE);
749
            case FIREWORK -> new ItemStack(Items.FIREWORK_ROCKET);
750
            case SNOWBALL -> new ItemStack(Items.SNOWBALL);
751
            case EGG -> new ItemStack(Items.EGG);
752
            case POTION_SPLASH -> new ItemStack(Items.SPLASH_POTION);
753
            case POTION_LINGERING -> new ItemStack(Items.LINGERING_POTION);
754
            default -> new ItemStack(Items.ARROW);
755
        };
756
757
        int color = hitColor;
758
        if (color == 0 && kind == Kind.PEARL_ENTITY && pearlColorToggle.get()) {
759
            color = pearlColorValue.getArgb();
760
        }
761
762
        return new TrajectoryResult(points, t, impactTick, icon, color, kind, impactPos, impactNormal, hitEntity, hitBlock);
763
    }
764
765
    private EntityCollision getEntityCollision(Entity movingEntity, Vec3 startPos, Vec3 endPos) {
766
        Vec3 direction = endPos.subtract(startPos);
767
        if (direction.lengthSqr() == 0.0) {
768
            return null;
769
        }
770
771
        AABB projectileBox = movingEntity.getBoundingBox().move(startPos.subtract(movingEntity.position()));
772
        AABB collisionBox = projectileBox.expandTowards(direction).inflate(0.5);
773
        EntityHitResult hitResult = ProjectileUtil.getEntityHitResult(
774
                movingEntity,
775
                startPos,
776
                endPos,
777
                collisionBox,
778
                entity -> canHitPredictedEntity(movingEntity, entity, collisionBox)
779
                        && entity instanceof LivingEntity
780
                        && !(entity instanceof ItemEntity)
781
                        && !(entity instanceof ExperienceOrb)
782
                        && entity != movingEntity,
783
                direction.lengthSqr()
784
        );
785
        if (hitResult == null) {
786
            return null;
787
        }
788
789
        return new EntityCollision(
790
                hitResult.getEntity(),
791
                hitResult.getLocation(),
792
                resolveEntityImpactNormal(hitResult.getEntity().getBoundingBox(), hitResult.getLocation(), direction)
793
        );
794
    }
795
796
    private AimPrediction computeAimPrediction(Player player, float tickDelta) {
797
        Projectile projectile = createHeldProjectile(player, tickDelta);
798
        if (projectile == null) {
799
            return null;
800
        }
801
802
        Kind kind = kindFromProjectile(projectile);
803
        TrajectoryResult result = simulateEntity(projectile, kind, tickDelta);
804
        if (result == null || result.points().isEmpty()) {
805
            return null;
806
        }
807
808
        Vec3 hitPos = result.impactPos() != null ? result.impactPos() : result.points().getLast();
809
        Entity hitEntity = result.hitEntity();
810
        Vec3 anchorPos;
811
        if (hitEntity instanceof LivingEntity living) {
812
            anchorPos = living.getPosition(tickDelta).add(0.0, living.getBbHeight() * 0.5, 0.0);
813
        } else if (hitEntity != null) {
814
            anchorPos = hitEntity.getBoundingBox().getCenter();
815
        } else {
816
            anchorPos = hitPos;
817
        }
818
819
        return new AimPrediction(hitEntity, hitPos, anchorPos, result.impactNormal(), result.iconStack(), result);
820
    }
821
822
    private AimPrediction smoothAimPrediction(AimPrediction raw) {
823
        if (raw == null || raw.trajectory() == null || raw.trajectory().points().isEmpty()) {
824
            resetAimSmoothing();
825
            return null;
826
        }
827
828
        long now = System.nanoTime();
829
        List<Vec3> rawPoints = raw.trajectory().points();
830
        boolean snap = smoothedAimPoints.isEmpty()
831
                || smoothedAimKind != raw.trajectory().kind()
832
                || smoothedAimEntity != raw.entity()
833
                || smoothedAimPoints.getFirst().distanceToSqr(rawPoints.getFirst()) > AIM_SMOOTH_SNAP_DISTANCE_SQ;
834
835
        if (snap) {
836
            smoothedAimPoints = List.copyOf(rawPoints);
837
            smoothedAimHitPos = raw.hitPos();
838
            smoothedAimNormal = raw.hitNormal();
839
            smoothedAimKind = raw.trajectory().kind();
840
            smoothedAimEntity = raw.entity();
841
            lastAimSmoothNanos = now;
842
            return raw;
843
        }
844
845
        double dt = lastAimSmoothNanos == 0L
846
                ? (1.0 / 60.0)
847
                : Math.min(AIM_SMOOTH_MAX_DT, Math.max(1.0 / 240.0, (now - lastAimSmoothNanos) * 1.0E-9));
848
        lastAimSmoothNanos = now;
849
        double alpha = 1.0 - Math.exp(-AIM_SMOOTH_RATE * dt);
850
851
        List<Vec3> nextPoints = new ArrayList<>(rawPoints.size());
852
        int count = rawPoints.size();
853
        for (int i = 0; i < count; i++) {
854
            double t = count <= 1 ? 0.0 : i / (double) (count - 1);
855
            Vec3 previous = samplePathByIndex(smoothedAimPoints, t);
856
            Vec3 current = rawPoints.get(i);
857
            double pointAlpha = Mth.clamp(alpha * (0.92 + 0.18 * t), 0.0, 1.0);
858
            nextPoints.add(previous.lerp(current, pointAlpha));
859
        }
860
861
        Vec3 nextHit = smoothedAimHitPos == null
862
                ? raw.hitPos()
863
                : smoothedAimHitPos.lerp(raw.hitPos(), Mth.clamp(alpha * 1.08, 0.0, 1.0));
864
        Vec3 nextNormal = smoothNormal(smoothedAimNormal, raw.hitNormal(), alpha);
865
        if (!nextPoints.isEmpty()) {
866
            nextPoints.set(nextPoints.size() - 1, nextHit);
867
        }
868
869
        smoothedAimPoints = List.copyOf(nextPoints);
870
        smoothedAimHitPos = nextHit;
871
        smoothedAimNormal = nextNormal;
872
        smoothedAimKind = raw.trajectory().kind();
873
        smoothedAimEntity = raw.entity();
874
875
        TrajectoryResult rawTrajectory = raw.trajectory();
876
        TrajectoryResult smoothedTrajectory = new TrajectoryResult(
877
                smoothedAimPoints,
878
                rawTrajectory.flightTicks(),
879
                rawTrajectory.impactTick(),
880
                rawTrajectory.iconStack(),
881
                rawTrajectory.argb(),
882
                rawTrajectory.kind(),
883
                nextHit,
884
                nextNormal,
885
                rawTrajectory.hitEntity(),
886
                rawTrajectory.hitBlock()
887
        );
888
        return new AimPrediction(raw.entity(), nextHit, raw.anchorPos(), nextNormal, raw.displayStack(), smoothedTrajectory);
889
    }
890
891
    private static Vec3 samplePathByIndex(List<Vec3> points, double t) {
892
        if (points == null || points.isEmpty()) return Vec3.ZERO;
893
        if (points.size() == 1) return points.getFirst();
894
895
        double scaled = Mth.clamp(t, 0.0, 1.0) * (points.size() - 1);
896
        int index = Math.min(points.size() - 2, Math.max(0, (int) Math.floor(scaled)));
897
        double local = scaled - index;
898
        return points.get(index).lerp(points.get(index + 1), local);
899
    }
900
901
    private static Vec3 smoothNormal(Vec3 previous, Vec3 current, double alpha) {
902
        if (current == null || current.lengthSqr() < 1.0E-6) return previous;
903
        Vec3 normalizedCurrent = current.normalize();
904
        if (previous == null || previous.lengthSqr() < 1.0E-6) return normalizedCurrent;
905
        Vec3 mixed = previous.normalize().lerp(normalizedCurrent, Mth.clamp(alpha, 0.0, 1.0));
906
        return mixed.lengthSqr() < 1.0E-6 ? normalizedCurrent : mixed.normalize();
907
    }
908
909
    private void resetAimSmoothing() {
910
        smoothedAimPoints = List.of();
911
        smoothedAimHitPos = null;
912
        smoothedAimNormal = null;
913
        smoothedAimKind = null;
914
        smoothedAimEntity = null;
915
        lastAimSmoothNanos = 0L;
916
    }
917
918
    private Projectile createHeldProjectile(Player player, float tickDelta) {
919
        if (mc.level == null) {
920
            return null;
921
        }
922
923
        InteractionHand hand = null;
924
        ItemStack handStack = ItemStack.EMPTY;
925
926
        ItemStack mainHand = player.getItemInHand(InteractionHand.MAIN_HAND);
927
        if (isAimUsable(player, mainHand, InteractionHand.MAIN_HAND)) {
928
            hand = InteractionHand.MAIN_HAND;
929
            handStack = mainHand;
930
        } else {
931
            ItemStack offHand = player.getItemInHand(InteractionHand.OFF_HAND);
932
            if (isAimUsable(player, offHand, InteractionHand.OFF_HAND)) {
933
                hand = InteractionHand.OFF_HAND;
934
                handStack = offHand;
935
            }
936
        }
937
938
        if (hand == null || handStack.isEmpty()) {
939
            return null;
940
        }
941
942
        Projectile projectile = null;
943
        float speed = 0.0f;
944
        float roll = 0.0f;
945
946
        if (handStack.is(Items.ENDER_PEARL)) {
947
            projectile = new ThrownEnderpearl(mc.level, player, handStack);
948
            speed = 1.5f;
949
        } else if (handStack.is(Items.SNOWBALL)) {
950
            projectile = new Snowball(mc.level, player, handStack);
951
            speed = 1.5f;
952
        } else if (handStack.is(Items.EGG)) {
953
            projectile = new ThrownEgg(mc.level, player, handStack);
954
            speed = 1.5f;
955
        } else if (handStack.is(Items.SPLASH_POTION) || handStack.is(Items.LINGERING_POTION)) {
956
            projectile = handStack.is(Items.LINGERING_POTION)
957
                    ? new ThrownLingeringPotion(mc.level, player, handStack)
958
                    : new ThrownSplashPotion(mc.level, player, handStack);
959
            speed = 0.5f;
960
            roll = -20.0f;
961
        } else if (handStack.is(Items.EXPERIENCE_BOTTLE)) {
962
            projectile = new ThrownExperienceBottle(mc.level, player, handStack);
963
            speed = 0.7f;
964
            roll = -20.0f;
965
        } else if (handStack.is(Items.WIND_CHARGE)) {
966
            projectile = new WindCharge(player, mc.level, player.position().x, player.getEyePosition().y, player.position().z);
967
            speed = 1.5f;
968
        } else if (handStack.is(Items.FIRE_CHARGE)) {
969
            projectile = new SmallFireball(mc.level, player, Vec3.ZERO);
970
            speed = 1.0f;
971
        } else if (handStack.is(Items.TRIDENT) && player.isUsingItem() && player.getUsedItemHand() == hand) {
972
            projectile = new ThrownTrident(mc.level, player, handStack);
973
            speed = 2.5f;
974
        } else if (handStack.is(Items.BOW) && player.isUsingItem() && player.getUsedItemHand() == hand) {
975
            float pull = BowItem.getPowerForTime(player.getTicksUsingItem());
976
            if (pull <= 0.0f) {
977
                return null;
978
            }
979
            ItemStack arrowStack = new ItemStack(Items.ARROW);
980
            projectile = new net.minecraft.world.entity.projectile.arrow.Arrow(mc.level, player, arrowStack, handStack);
981
            speed = 3.0f * pull;
982
        } else if (handStack.getItem() instanceof CrossbowItem && CrossbowItem.isCharged(handStack)) {
983
            ItemStack arrowStack = new ItemStack(Items.ARROW);
984
            projectile = new net.minecraft.world.entity.projectile.arrow.Arrow(mc.level, player, arrowStack, handStack);
985
            speed = 3.15f;
986
        }
987
988
        if (projectile == null) {
989
            return null;
990
        }
991
992
        Vec3 eye = player.getEyePosition(tickDelta);
993
        projectile.absSnapTo(eye.x, eye.y, eye.z);
994
        float viewPitch = player.getViewXRot(tickDelta);
995
        float viewYaw = player.getViewYRot(tickDelta);
996
        setHeldProjectileVelocity(projectile, player, viewPitch, viewYaw, roll, speed);
997
        return projectile;
998
    }
999
1000
    private void setHeldProjectileVelocity(Projectile projectile, Entity shooter, float pitch, float yaw, float roll, float speed) {
1001
        float x = -Mth.sin(yaw * ((float) Math.PI / 180.0f)) * Mth.cos(pitch * ((float) Math.PI / 180.0f));
1002
        float y = -Mth.sin((pitch + roll) * ((float) Math.PI / 180.0f));
1003
        float z = Mth.cos(yaw * ((float) Math.PI / 180.0f)) * Mth.cos(pitch * ((float) Math.PI / 180.0f));
1004
1005
        Vec3 velocity = new Vec3(x, y, z).normalize().scale(speed);
1006
        projectile.setDeltaMovement(velocity);
1007
1008
        Vec3 movement = shooter.getKnownMovement();
1009
        projectile.setDeltaMovement(projectile.getDeltaMovement().add(movement.x, shooter.onGround() ? 0.0 : movement.y, movement.z));
1010
    }
1011
1012
    private boolean isAimUsable(Player player, ItemStack stack, InteractionHand hand) {
1013
        if (stack == null || stack.isEmpty()) {
1014
            return false;
1015
        }
1016
1017
        if (stack.is(Items.BOW) || stack.is(Items.TRIDENT)) {
1018
            return player.isUsingItem() && player.getUsedItemHand() == hand && player.getUseItem() == stack;
1019
        }
1020
1021
        if (stack.is(Items.CROSSBOW)) {
1022
            return net.minecraft.world.item.CrossbowItem.isCharged(stack);
1023
        }
1024
1025
        return stack.is(Items.ENDER_PEARL)
1026
                || stack.is(Items.SNOWBALL)
1027
                || stack.is(Items.EGG)
1028
                || stack.is(Items.SPLASH_POTION)
1029
                || stack.is(Items.LINGERING_POTION)
1030
                || stack.is(Items.EXPERIENCE_BOTTLE)
1031
                || stack.is(Items.FIRE_CHARGE)
1032
                || stack.is(Items.WIND_CHARGE);
1033
    }
1034
1035
    private boolean isKindDisabled(String key) {
1036
        // Ender pearls are always shown; caller must skip check for them.
1037
        return !kindToggles.get(key);
1038
    }
1039
1040
    private boolean isInGround(AbstractArrow arrow) {
1041
        if (arrow == null) return false;
1042
        try {
1043
            return ((PersistentProjectileEntityAccessor) arrow).combatant$isInGround();
1044
        } catch (Throwable t) {
1045
            return false;
1046
        }
1047
    }
1048
1049
    private void drawTimerPlate(Renderer2D renderer, TextRenderer textRenderer, TrajectoryResult res, float sx, float sy) {
1050
        double seconds = res.flightTicks / 20.0;
1051
        if (seconds <= 0.0) return;
1052
1053
        ItemStack iconStack = useItemIcon(res.kind) ? resolveTimerItem(res.kind) : ItemStack.EMPTY;
1054
        Identifier iconId = iconStack.isEmpty() ? resolveTimerIcon(res.kind) : null;
1055
        drawTimerPlate(renderer, textRenderer, formatTime(seconds), sx, sy, res.argb, iconStack, iconId);
1056
    }
1057
1058
    private void drawTntTimers(Renderer2D renderer, TextRenderer textRenderer, float tickDelta) {
1059
        ClientLevel world = mc.level;
1060
        if (world == null) return;
1061
1062
        int plateColor = tntColorValue.getArgb();
1063
        for (Entity entity : world.entitiesForRendering()) {
1064
            if (!(entity instanceof PrimedTnt tnt) || !tnt.isAlive() || tnt.isRemoved()) continue;
1065
1066
            int fuse = tnt.getFuse();
1067
            if (fuse < 0) continue;
1068
1069
            Vec3 anchor = tnt.getPosition(tickDelta).add(0.0, tnt.getBbHeight() + 0.5, 0.0);
1070
            Vec3 screen = ScreenProjection.worldToScreen(anchor, tickDelta);
1071
            if (screen == null) continue;
1072
1073
            double seconds = Math.max(0.0, (fuse - tickDelta) / 20.0);
1074
            drawTimerPlate(
1075
                    renderer,
1076
                    textRenderer,
1077
                    formatTime(seconds),
1078
                    (float) screen.x,
1079
                    (float) screen.y,
1080
                    plateColor,
1081
                    tntTimerIcon(),
1082
                    null
1083
            );
1084
        }
1085
    }
1086
1087
    private ItemStack tntTimerIcon() {
1088
        if (tntTimerIcon.isEmpty()) {
1089
            tntTimerIcon = new ItemStack(Items.TNT);
1090
        }
1091
        return tntTimerIcon;
1092
    }
1093
1094
    private void drawTimerPlate(Renderer2D renderer,
1095
                                TextRenderer textRenderer,
1096
                                String txt,
1097
                                float sx,
1098
                                float sy,
1099
                                int argb,
1100
                                ItemStack iconStack,
1101
                                Identifier iconId) {
1102
        if (txt == null || txt.isEmpty()) return;
1103
1104
        TextRenderer tr = BuiltinFontCatalog.ONEST_MEDIUM.renderer(textRenderer);
1105
        float textW = (float) tr.getWidth(txt) * PLATE_TEXT_SCALE;
1106
        float contentW = PLATE_ICON_SIZE + PLATE_ICON_TEXT_GAP + textW;
1107
        float plateW = PLATE_PAD_X * 2.0f + contentW;
1108
        float plateX = sx - plateW * 0.5f;
1109
        float plateY = sy;
1110
1111
        MatteHudStyle.drawEspMattePlate(
1112
                renderer,
1113
                plateX,
1114
                plateY,
1115
                plateW,
1116
                PLATE_HEIGHT,
1117
                PLATE_RADIUS,
1118
                1.0f
1119
        );
1120
1121
        float iconX = plateX + PLATE_PAD_X;
1122
        float iconY = plateY + (PLATE_HEIGHT - PLATE_ICON_SIZE) * 0.5f;
1123
        float iconScale = PLATE_ICON_SIZE / 16.0f;
1124
        if (iconStack == null || iconStack.isEmpty()) {
1125
            iconStack = ItemStack.EMPTY;
1126
            drawTimerIcon(iconId, iconX, iconY, PLATE_ICON_SIZE);
1127
        }
1128
1129
        float textX = iconX + PLATE_ICON_SIZE + PLATE_ICON_TEXT_GAP;
1130
        float textH = (float) tr.getHeight() * PLATE_TEXT_SCALE;
1131
        float textY = plateY + (PLATE_HEIGHT - textH) * 0.5f + PLATE_TEXT_OFFSET_Y;
1132
        timerPlates.add(new TimerPlate(textX, textY, txt, iconX, iconY, iconScale, iconStack));
1133
    }
1134
1135
    private void drawTimerIcon(Identifier iconId, float x, float y, float size) {
1136
        if (iconId == null) return;
1137
        Renderer2D.TEXTURE.roundedTexRect(
1138
                x,
1139
                y,
1140
                size,
1141
                size,
1142
                1.5f,
1143
                1.0f,
1144
                0,
1145
                0,
1146
                1,
1147
                1,
1148
                0xFFFFFFFF,
1149
                iconId
1150
        );
1151
    }
1152
1153
    private boolean useItemIcon(Kind kind) {
1154
        return kind == Kind.SNOWBALL
1155
                || kind == Kind.EGG
1156
                || kind == Kind.FIREBALL
1157
                || kind == Kind.FIREWORK
1158
                || kind == Kind.WIND_CHARGE;
1159
    }
1160
1161
    private ItemStack resolveTimerItem(Kind kind) {
1162
        return switch (kind) {
1163
            case SNOWBALL -> new ItemStack(Items.SNOWBALL);
1164
            case EGG -> new ItemStack(Items.EGG);
1165
            case FIREBALL -> new ItemStack(Items.FIRE_CHARGE);
1166
            case FIREWORK -> new ItemStack(Items.FIREWORK_ROCKET);
1167
            case WIND_CHARGE -> new ItemStack(Items.WIND_CHARGE);
1168
            default -> ItemStack.EMPTY;
1169
        };
1170
    }
1171
1172
    private Identifier resolveTimerIcon(Kind kind) {
1173
        return switch (kind) {
1174
            case PEARL_ENTITY -> Identifier.fromNamespaceAndPath("combatant", "textures/timers/pearl.png");
1175
            case TRIDENT -> Identifier.fromNamespaceAndPath("combatant", "textures/timers/trident.png");
1176
            case POTION_SPLASH, POTION_LINGERING ->
1177
                    Identifier.fromNamespaceAndPath("combatant", "textures/timers/potion.png");
1178
            case ARROW -> Identifier.fromNamespaceAndPath("combatant", "textures/timers/arrow.png");
1179
            case FIREBALL, FIREWORK, WIND_CHARGE, SNOWBALL, EGG -> null;
1180
        };
1181
    }
1182
1183
    private void renderAimTrajectory(Renderer3D renderer, float tickDelta, int baseColor, AimPrediction pred) {
1184
        Player player = mc.player;
1185
        if (player == null || pred == null || pred.trajectory() == null) return;
1186
1187
        List<Vec3> points = pred.trajectory().points();
1188
        if (points.size() < 2) return;
1189
1190
        boolean walls = glowWallsValue.get();
1191
        RenderPipeline pipeline = walls
1192
                ? CombatantRenderPipelines.WORLD_COLORED_LINES_LIQUID_BLEND
1193
                : CombatantRenderPipelines.WORLD_COLORED_LINES_LIQUID_IGNORE;
1194
        Renderer3D.DepthMode depthMode = walls ? Renderer3D.DepthMode.MAIN : Renderer3D.DepthMode.PRE_DEPTH;
1195
1196
        float prevWidth = RenderState.lineWidth;
1197
        RenderState.lineWidth = AIM_TRAJECTORY_LINE_WIDTH;
1198
        try {
1199
            MeshBuilder mesh = renderer.batch(pipeline, depthMode);
1200
            if (mesh == null) return;
1201
1202
            int color = pred.entity() != null
1203
                    ? HIT_ENTITY_COLOR
1204
                    : pred.trajectory().argb() != 0 ? pred.trajectory().argb() : baseColor;
1205
            Vec3 cameraPos = RenderState.cameraPos != null ? RenderState.cameraPos : player.getEyePosition(tickDelta);
1206
            addDashedAimPath(mesh, points, cameraPos, color);
1207
        } finally {
1208
            RenderState.lineWidth = prevWidth;
1209
        }
1210
    }
1211
1212
    private static void addDashedAimPath(MeshBuilder mesh, List<Vec3> points, Vec3 cameraPos, int color) {
1213
        if (mesh == null || points == null || points.size() < 2) return;
1214
1215
        double totalLength = 0.0;
1216
        for (int i = 1; i < points.size(); i++) {
1217
            totalLength += points.get(i - 1).distanceTo(points.get(i));
1218
        }
1219
        if (totalLength <= 1.0E-6) return;
1220
1221
        double patternLength = AIM_TRAJECTORY_DASH_LENGTH + AIM_TRAJECTORY_DASH_GAP;
1222
        double travelled = 0.0;
1223
        for (int i = 1; i < points.size(); i++) {
1224
            Vec3 from = points.get(i - 1);
1225
            Vec3 to = points.get(i);
1226
            double segmentLength = from.distanceTo(to);
1227
            if (segmentLength <= 1.0E-6) continue;
1228
1229
            double local = 0.0;
1230
            while (local < segmentLength - 1.0E-6) {
1231
                double phase = (travelled + local) % patternLength;
1232
                boolean inDash = phase < AIM_TRAJECTORY_DASH_LENGTH;
1233
                double phaseRemaining = inDash
1234
                        ? AIM_TRAJECTORY_DASH_LENGTH - phase
1235
                        : patternLength - phase;
1236
                double run = Math.min(segmentLength - local, Math.max(1.0E-5, phaseRemaining));
1237
1238
                if (inDash) {
1239
                    double t0 = local / segmentLength;
1240
                    double t1 = (local + run) / segmentLength;
1241
                    Vec3 p0 = from.lerp(to, t0);
1242
                    Vec3 p1 = from.lerp(to, t1);
1243
                    if (cameraPos == null
1244
                            || (p0.distanceToSqr(cameraPos) >= AIM_TRAJECTORY_MIN_CAMERA_DISTANCE_SQ
1245
                            && p1.distanceToSqr(cameraPos) >= AIM_TRAJECTORY_MIN_CAMERA_DISTANCE_SQ)) {
1246
                        float progress0 = (float) ((travelled + local) / totalLength);
1247
                        float progress1 = (float) ((travelled + local + run) / totalLength);
1248
                        float alpha0 = aimTrajectoryAlpha(progress0);
1249
                        float alpha1 = aimTrajectoryAlpha(progress1);
1250
                        addGradientLine(mesh, p0, p1, multiplyAlpha(color, alpha0), multiplyAlpha(color, alpha1));
1251
                    }
1252
                }
1253
                local += run;
1254
            }
1255
            travelled += segmentLength;
1256
        }
1257
    }
1258
1259
    private static float aimTrajectoryAlpha(float progress) {
1260
        float t = Mth.clamp(progress, 0.0f, 1.0f);
1261
        float headFade = AnimationUtility.smoothstep(Mth.clamp(t / 0.14f, 0.0f, 1.0f));
1262
        float tailFade = AnimationUtility.smoothstep(Mth.clamp((1.0f - t) / 0.12f, 0.0f, 1.0f));
1263
        float body = Mth.lerp(AnimationUtility.easeOutCubic(t), AIM_TRAJECTORY_ALPHA_MIN, AIM_TRAJECTORY_ALPHA_MAX);
1264
        return body * headFade * tailFade;
1265
    }
1266
1267
    private void renderAimIndicatorWorld(Renderer3D renderer, float tickDelta, AimPrediction pred) {
1268
        if (pred == null || mc.level == null) return;
1269
1270
        boolean walls = glowWallsValue.get();
1271
        RenderPipeline pipeline = walls
1272
                ? CombatantRenderPipelines.WORLD_AIM_DECAL
1273
                : CombatantRenderPipelines.WORLD_AIM_DECAL_DEPTH;
1274
        Renderer3D.DepthMode depthMode = walls ? Renderer3D.DepthMode.NONE : Renderer3D.DepthMode.PRE_DEPTH;
1275
        MeshBuilder mesh = renderer.batch(pipeline, depthMode);
1276
        if (mesh == null) return;
1277
1278
        int color = pred.entity() != null ? HIT_ENTITY_COLOR : lineColorValue.getArgb();
1279
        float pulseTime = (mc.level.getGameTime() + tickDelta) * 0.075f;
1280
        float pulse01 = (float) ((Math.sin(pulseTime) + 1.0) * 0.5);
1281
        float pulse = 0.965f + 0.035f * AnimationUtility.smoothstep(pulse01);
1282
        Vec3 normal = pred.hitNormal() != null ? pred.hitNormal() : new Vec3(0.0, 1.0, 0.0);
1283
        Vec3 incoming = impactDirection(pred.trajectory());
1284
        addAimDecal(mesh, pred.hitPos(), normal, incoming, AIM_DECAL_RADIUS * pulse, color, pulse01);
1285
    }
1286
1287
    private void updatePredictionTarget(AimPrediction pred) {
1288
        if (!targetHudOnAimValue.get()) {
1289
            TargetManager.setPredictionTarget(null);
1290
            return;
1291
        }
1292
1293
        if (pred != null && pred.entity() instanceof LivingEntity living && living.isAlive() && !living.isRemoved()) {
1294
            TargetManager.setPredictionTarget(living);
1295
            return;
1296
        }
1297
1298
        TargetManager.setPredictionTarget(null);
1299
    }
1300
1301
    private String formatTime(double seconds) {
1302
        String s = String.format(Locale.US, "%.1f", seconds);
1303
        s = s.replace('.', ',');
1304
        return s + " s";
1305
    }
1306
1307
    private void renderGlowTrajectories(Renderer3D renderer, List<TrajectoryResult> results, int baseColor) {
1308
        boolean walls = glowWallsValue.get();
1309
        RenderPipeline pipeline = walls
1310
                ? CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE
1311
                : CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE_LIQUID_IGNORE;
1312
        Renderer3D.DepthMode depthMode = walls ? Renderer3D.DepthMode.MAIN : Renderer3D.DepthMode.PRE_DEPTH;
1313
        MeshBuilder mesh = renderer.batchTextured(pipeline, TextureStorage.BLOOM, depthMode);
1314
        if (mesh == null) return;
1315
1316
        Quaternionf camRot = RenderState.cameraRotation;
1317
        for (TrajectoryResult res : results) {
1318
            List<Vec3> points = res.points();
1319
            if (points.size() < 2) continue;
1320
1321
            int color = res.argb() != 0 ? res.argb() : baseColor;
1322
            int totalSegments = points.size() - 1;
1323
1324
            for (int i = 1; i < points.size(); i++) {
1325
                Vec3 from = points.get(i - 1);
1326
                Vec3 to = points.get(i);
1327
1328
                for (int step = 0; step <= GLOW_SUBSTEPS; step++) {
1329
                    float stepT = step / (float) GLOW_SUBSTEPS;
1330
                    Vec3 pos = from.lerp(to, stepT);
1331
                    float segmentProgress = ((i - 1) + stepT) / Math.max(1.0f, totalSegments);
1332
                    float strength = 0.45f + 0.55f * AnimationUtility.easeOutCubic(segmentProgress);
1333
                    float sizeBoost = 0.92f + 0.25f * strength;
1334
1335
                    addBillboardQuad(
1336
                            mesh,
1337
                            pos.x, pos.y, pos.z,
1338
                            GLOW_CORE_SIZE * sizeBoost,
1339
                            camRot,
1340
                            multiplyAlpha(color, GLOW_CORE_ALPHA * strength)
1341
                    );
1342
                    addBillboardQuad(
1343
                            mesh,
1344
                            pos.x, pos.y, pos.z,
1345
                            GLOW_SOFT_SIZE * sizeBoost,
1346
                            camRot,
1347
                            multiplyAlpha(color, GLOW_SOFT_ALPHA * strength)
1348
                    );
1349
                }
1350
            }
1351
        }
1352
    }
1353
1354
    private void renderLineTrajectories(Renderer3D renderer, List<TrajectoryResult> results, int baseColor) {
1355
        boolean walls = glowWallsValue.get();
1356
        RenderPipeline pipeline = walls
1357
                ? CombatantRenderPipelines.WORLD_COLORED_LINES_LIQUID_BLEND
1358
                : CombatantRenderPipelines.WORLD_COLORED_LINES_LIQUID_IGNORE;
1359
        Renderer3D.DepthMode depthMode = walls ? Renderer3D.DepthMode.MAIN : Renderer3D.DepthMode.PRE_DEPTH;
1360
1361
        float prevWidth = RenderState.lineWidth;
1362
        RenderState.lineWidth = TRAJECTORY_LINE_WIDTH;
1363
        try {
1364
            MeshBuilder mesh = renderer.batch(pipeline, depthMode);
1365
            if (mesh == null) return;
1366
1367
            for (TrajectoryResult res : results) {
1368
                List<Vec3> points = res.points();
1369
                if (points.size() < 2) continue;
1370
1371
                int color = res.argb() != 0 ? res.argb() : baseColor;
1372
                int totalSegments = points.size() - 1;
1373
                for (int i = 1; i < points.size(); i++) {
1374
                    Vec3 from = points.get(i - 1);
1375
                    Vec3 to = points.get(i);
1376
1377
                    float startT = (i - 1) / (float) totalSegments;
1378
                    float endT = i / (float) totalSegments;
1379
                    float startAlpha = Mth.lerp(AnimationUtility.easeOutCubic(startT), TRAJECTORY_LINE_ALPHA_START, TRAJECTORY_LINE_ALPHA_END);
1380
                    float endAlpha = Mth.lerp(AnimationUtility.easeOutCubic(endT), TRAJECTORY_LINE_ALPHA_START, TRAJECTORY_LINE_ALPHA_END);
1381
1382
                    addGradientLine(mesh, from, to, multiplyAlpha(color, startAlpha), multiplyAlpha(color, endAlpha));
1383
                }
1384
            }
1385
        } finally {
1386
            RenderState.lineWidth = prevWidth;
1387
        }
1388
    }
1389
1390
    private void renderImpactEffects(Renderer3D renderer, List<TrajectoryResult> results, int baseColor, float tickDelta) {
1391
        boolean walls = glowWallsValue.get();
1392
        RenderPipeline decalPipeline = walls
1393
                ? CombatantRenderPipelines.WORLD_DECAL_SDF
1394
                : CombatantRenderPipelines.WORLD_DECAL_SDF_DEPTH;
1395
        Renderer3D.DepthMode decalDepthMode = walls ? Renderer3D.DepthMode.NONE : Renderer3D.DepthMode.PRE_DEPTH;
1396
        float prevWidth = RenderState.lineWidth;
1397
        RenderState.lineWidth = ENTITY_HIT_OUTLINE_WIDTH;
1398
        try {
1399
            MeshBuilder decalMesh = renderer.batch(decalPipeline, decalDepthMode);
1400
            for (TrajectoryResult res : results) {
1401
                Vec3 impact = res.impactPos();
1402
                if (impact != null && decalMesh != null) {
1403
                    int color = res.argb() != 0 ? res.argb() : baseColor;
1404
                    float pulseTime = (mc.level.getGameTime() + tickDelta) * 0.085f;
1405
                    float pulse = 0.85f + 0.15f * AnimationUtility.smoothstep((float) ((Math.sin(pulseTime) + 1.0) * 0.5));
1406
                    Vec3 normal = res.impactNormal() != null ? res.impactNormal() : new Vec3(0.0, 1.0, 0.0);
1407
                    addImpactDecal(decalMesh, impact, normal, impactDirection(res), IMPACT_DECAL_RADIUS * pulse, color);
1408
                }
1409
1410
                if (res.hitEntity() != null && res.hitEntity().isAlive()) {
1411
                    int color = res.argb() != 0 ? res.argb() : baseColor;
1412
                    AABB box = res.hitEntity().getBoundingBox().inflate(IMPACT_BOX_EXPAND);
1413
                    addFilledBox(renderer, box, withAlpha(color, ENTITY_HIT_FILL_ALPHA));
1414
                    addOutlineBox(renderer, box, withAlpha(color, ENTITY_HIT_LINE_ALPHA));
1415
                }
1416
            }
1417
        } finally {
1418
            RenderState.lineWidth = prevWidth;
1419
        }
1420
    }
1421
1422
    private enum Kind {
1423
        PEARL_ENTITY,
1424
        ARROW,
1425
        TRIDENT,
1426
        FIREBALL,
1427
        WIND_CHARGE,
1428
        FIREWORK,
1429
        SNOWBALL,
1430
        EGG,
1431
        POTION_SPLASH,
1432
        POTION_LINGERING
1433
    }
1434
1435
    private record AimPrediction(Entity entity, Vec3 hitPos, Vec3 anchorPos, Vec3 hitNormal, ItemStack displayStack,
1436
                                 TrajectoryResult trajectory) {
1437
        private AimPrediction(Entity entity, Vec3 hitPos, Vec3 anchorPos, Vec3 hitNormal, ItemStack displayStack,
1438
                              TrajectoryResult trajectory) {
1439
            this.entity = entity;
1440
            this.hitPos = hitPos;
1441
            this.anchorPos = anchorPos;
1442
            this.hitNormal = hitNormal;
1443
            this.displayStack = displayStack == null ? ItemStack.EMPTY : displayStack;
1444
            this.trajectory = trajectory;
1445
        }
1446
    }
1447
1448
    private record TrajectoryResult(List<Vec3> points, double flightTicks, long impactTick, ItemStack iconStack,
1449
                                    int argb, Kind kind, Vec3 impactPos, Vec3 impactNormal, Entity hitEntity,
1450
                                    boolean hitBlock) {
1451
        private TrajectoryResult(List<Vec3> points, double flightTicks, long impactTick, ItemStack iconStack,
1452
                                 int argb, Kind kind, Vec3 impactPos, Vec3 impactNormal, Entity hitEntity, boolean hitBlock) {
1453
            this.points = points;
1454
            this.flightTicks = flightTicks;
1455
            this.impactTick = impactTick;
1456
            this.iconStack = iconStack == null ? ItemStack.EMPTY : iconStack;
1457
            this.argb = argb;
1458
            this.kind = kind;
1459
            this.impactPos = impactPos;
1460
            this.impactNormal = impactNormal;
1461
            this.hitEntity = hitEntity;
1462
            this.hitBlock = hitBlock;
1463
        }
1464
    }
1465
1466
    private record EntityCollision(Entity entity, Vec3 hitPos, Vec3 hitNormal) {
1467
    }
1468
1469
    private record TimerPlate(float textX, float textY, String text,
1470
                              float iconX, float iconY, float iconScale, ItemStack iconStack) {
1471
        private TimerPlate(float textX, float textY, String text,
1472
                           float iconX, float iconY, float iconScale, ItemStack iconStack) {
1473
            this.textX = textX;
1474
            this.textY = textY;
1475
            this.text = text;
1476
            this.iconX = iconX;
1477
            this.iconY = iconY;
1478
            this.iconScale = iconScale;
1479
            this.iconStack = iconStack == null ? ItemStack.EMPTY : iconStack;
1480
        }
1481
    }
1482
}
1483