HitEffect module

HitEffect: 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/HitEffect.javaJava · 591 lines · 24.0 KB
SettingshitEffectModehitEffectColorModehitEffectColorSpeedhitEffectColorhitEffectColor2hitEffectDepthTesthitEffectOnlyPlayershitEffectWaveRadiushitEffectWaveDurationhitEffectParticleCounthitEffectParticleSizehitEffectParticleLifeMshitEffectParticleTexturehitEffectParticleRandomColor
HitEffect.javaJava · Minecraft 26.2 · 591 lines · 24.0 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Combatant Client distribution.
3
 * Copyright (c) 2026 pivosos2007.
4
 *
5
 * Licensed under the GNU General Public License v3.0.
6
 */
7
8
package combatant.client.features.module.modules.visuals;
9
10
import com.mojang.blaze3d.pipeline.RenderPipeline;
11
import combatant.client.config.values.BooleanValue;
12
import combatant.client.config.values.EnumValue;
13
import combatant.client.config.values.ModeValue;
14
import combatant.client.config.values.NumberValue;
15
import combatant.client.config.values.RGBAColorValue;
16
import combatant.client.features.module.Module;
17
import combatant.client.features.module.ModuleCategory;
18
import combatant.client.features.module.ModuleInfo;
19
import combatant.client.features.module.WorldPhase;
20
import combatant.client.mixininterface.ILocalPlayer;
21
import combatant.client.render.engine.RenderState;
22
import combatant.client.render.engine.TextureStorage;
23
import combatant.client.render.engine.animation.AnimatedRenderColors;
24
import combatant.client.render.engine.color.RenderColor;
25
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
26
import combatant.client.render.engine.renderer.Renderer3D;
27
import combatant.client.render.effects.surface.CurrentSurfaceWaveRenderer;
28
import combatant.client.render.effects.surface.SurfaceWaveDescriptor;
29
import combatant.client.render.engine.uniform.MeshBuilder;
30
import combatant.client.render.helpers.Particle3D;
31
import combatant.client.render.helpers.ParticleTextureMode;
32
import net.minecraft.client.Minecraft;
33
import net.minecraft.util.Mth;
34
import net.minecraft.world.entity.Entity;
35
import net.minecraft.world.entity.LivingEntity;
36
import net.minecraft.world.entity.player.Player;
37
import net.minecraft.world.entity.projectile.ProjectileUtil;
38
import net.minecraft.world.phys.AABB;
39
import net.minecraft.world.phys.EntityHitResult;
40
import net.minecraft.world.phys.Vec3;
41
import org.joml.Quaternionf;
42
import org.joml.Vector3f;
43
44
import java.awt.Color;
45
import java.util.ArrayList;
46
import java.util.Iterator;
47
import java.util.List;
48
import java.util.Random;
49
50
//todo Description
51
@ModuleInfo(id = "hiteffect", displayName = "HitEffect", category = ModuleCategory.VISUALS)
52
public class HitEffect extends Module {
53
54
    private static final String SETTING_EFFECT_MODE = "effect_mode";
55
    private static final String SETTING_ONLY_PLAYERS = "only_players";
56
    private static final String SETTING_DEPTH_TEST = "depth_test";
57
    private static final String SETTING_COLOR_MODE = "color_mode";
58
    private static final String SETTING_COLOR_SPEED = "color_speed";
59
    private static final String SETTING_COLOR = "color";
60
    private static final String SETTING_COLOR2 = "color2";
61
    private static final String SETTING_WAVE_RADIUS = "wave_radius";
62
    private static final String SETTING_WAVE_DURATION = "wave_duration";
63
    private static final String SETTING_HIT_PARTICLE_COUNT = "hit_particle_count";
64
    private static final String SETTING_HIT_PARTICLE_SIZE = "hit_particle_size";
65
    private static final String SETTING_HIT_PARTICLE_LIFE = "hit_particle_life_ms";
66
    private static final String SETTING_HIT_PARTICLE_TEXTURE = "hit_particle_texture";
67
    private static final String SETTING_HIT_PARTICLE_RANDOM_COLOR = "hit_particle_random_color";
68
69
    private static final float CHARGED_THRESHOLD = 0.9f;
70
71
    private static final float WAVE_WIDTH = 3.15f;
72
    private static final float WAVE_FILL_TRAIL = 4.25f;
73
    private static final float WAVE_FILL_ALPHA = 0.18f;
74
    private static final float WAVE_TRAIL_ALPHA = 0.055f;
75
    private static final int WAVE_MAX_PER_FRAME = 400;
76
    private static final float WAVE_MIN_ALPHA = 0.012f;
77
78
    private static final float HIT_PARTICLE_GRAVITY_MIN = 0.006f;
79
    private static final float HIT_PARTICLE_GRAVITY_MAX = 0.012f;
80
    private static final float HIT_PARTICLE_DRAG_MIN = 0.90f;
81
    private static final float HIT_PARTICLE_DRAG_MAX = 0.94f;
82
    private static final int HIT_PARTICLE_MAX = 320;
83
    private static final int HIT_PARTICLE_SPAWN_CAP_PER_TICK = 48;
84
    private static final float HIT_PARTICLE_GLOW_ALPHA = 0.20f;
85
    private static final float HIT_PARTICLE_GLOW_SCALE = 1.45f;
86
87
    private final Minecraft mc = Minecraft.getInstance();
88
    private final Random random = new Random();
89
90
    private final EnumValue<EffectMode> effectMode =
91
            enumSetting("hitEffectMode", SETTING_EFFECT_MODE, EffectMode.PARTICLES, EffectMode.values());
92
    private final ModeValue colorMode =
93
            modeSetting("hitEffectColorMode", SETTING_COLOR_MODE, "Theme",
94
                    "Static", "Rainbow", "LightRainbow", "Sky", "Fade", "DoubleColor", "Analogous", "Theme");
95
    private final NumberValue<Integer> colorSpeed =
96
            num("hitEffectColorSpeed", SETTING_COLOR_SPEED, 18, 2, 54);
97
    private final RGBAColorValue colorValue = color("hitEffectColor", SETTING_COLOR, "#FF8ED4FF");
98
    private final RGBAColorValue colorValue2 =
99
            visibleWhen(color("hitEffectColor2", SETTING_COLOR2, "#FFFF7D9A"), this::usesSecondaryColor);
100
    private final BooleanValue depthTest = bool("hitEffectDepthTest", SETTING_DEPTH_TEST, true);
101
    private final BooleanValue onlyPlayers = bool("hitEffectOnlyPlayers", SETTING_ONLY_PLAYERS, true);
102
103
    private final NumberValue<Integer> waveRadius =
104
            visibleWhen(num("hitEffectWaveRadius", SETTING_WAVE_RADIUS, 12, 3, 32), this::isWaveMode);
105
    private final NumberValue<Integer> waveDurationMs =
106
            visibleWhen(num("hitEffectWaveDuration", SETTING_WAVE_DURATION, 1500, 200, 6000), this::isWaveMode);
107
108
    private final NumberValue<Integer> hitParticleCount =
109
            visibleWhen(num("hitEffectParticleCount", SETTING_HIT_PARTICLE_COUNT, 18, 1, 80), this::isParticleMode);
110
    private final NumberValue<Float> hitParticleSize =
111
            visibleWhen(num("hitEffectParticleSize", SETTING_HIT_PARTICLE_SIZE, 0.105f, 0.04f, 0.4f), this::isParticleMode);
112
    private final NumberValue<Integer> hitParticleLifeMs =
113
            visibleWhen(num("hitEffectParticleLifeMs", SETTING_HIT_PARTICLE_LIFE, 1250, 250, 4500), this::isParticleMode);
114
    private final EnumValue<ParticleTextureMode> hitParticleTexture =
115
            visibleWhen(enumSetting("hitEffectParticleTexture", SETTING_HIT_PARTICLE_TEXTURE,
116
                    ParticleTextureMode.RANDOM, ParticleTextureMode.values()), this::isParticleMode);
117
    private final BooleanValue hitParticleRandomColor =
118
            visibleWhen(bool("hitEffectParticleRandomColor", SETTING_HIT_PARTICLE_RANDOM_COLOR, false), this::isParticleMode);
119
120
    private final List<SurfaceWaveDescriptor> waves = new ArrayList<>();
121
    private final List<Particle3D> hitParticles = new ArrayList<>();
122
    private final List<Particle3D>[] hitParticleBuckets = createBuckets();
123
    private int lastHitParticleTick = Integer.MIN_VALUE;
124
    private int spawnedHitParticlesThisTick;
125
126
    @SuppressWarnings("unchecked")
127
    private static List<Particle3D>[] createBuckets() {
128
        List<Particle3D>[] buckets = new List[TextureStorage.RANDOM_PARTICLES.length];
129
        for (int i = 0; i < buckets.length; i++) {
130
            buckets[i] = new ArrayList<>();
131
        }
132
        return buckets;
133
    }
134
135
    private static void clearBuckets(List<Particle3D>[] buckets) {
136
        for (List<Particle3D> bucket : buckets) {
137
            bucket.clear();
138
        }
139
    }
140
141
    private static float smoothstep(float t) {
142
        t = Mth.clamp(t, 0.0f, 1.0f);
143
        return t * t * (3.0f - 2.0f * t);
144
    }
145
146
    private static int applyOpacity(int argb, float opacity) {
147
        opacity = Mth.clamp(opacity, 0.0f, 1.0f);
148
        int a = (argb >>> 24) & 0xFF;
149
        int na = Mth.clamp(Math.round(a * opacity), 0, 255);
150
        return (na << 24) | (argb & 0x00FFFFFF);
151
    }
152
153
    private static void addBillboardQuad(MeshBuilder mesh,
154
                                         double cx, double cy, double cz,
155
                                         float size,
156
                                         Quaternionf camRot,
157
                                         float rollRadians,
158
                                         int argb) {
159
        Vector3f baseRight = new Vector3f(1.0f, 0.0f, 0.0f).rotate(camRot);
160
        Vector3f baseUp = new Vector3f(0.0f, 1.0f, 0.0f).rotate(camRot);
161
162
        float cos = (float) Math.cos(rollRadians);
163
        float sin = (float) Math.sin(rollRadians);
164
        Vector3f right = new Vector3f(baseRight).mul(cos).fma(sin, baseUp).mul(size);
165
        Vector3f up = new Vector3f(baseUp).mul(cos).fma(-sin, baseRight).mul(size);
166
167
        double p1x = cx - right.x() - up.x();
168
        double p1y = cy - right.y() - up.y();
169
        double p1z = cz - right.z() - up.z();
170
        double p2x = cx + right.x() - up.x();
171
        double p2y = cy + right.y() - up.y();
172
        double p2z = cz + right.z() - up.z();
173
        double p3x = cx + right.x() + up.x();
174
        double p3y = cy + right.y() + up.y();
175
        double p3z = cz + right.z() + up.z();
176
        double p4x = cx - right.x() + up.x();
177
        double p4y = cy - right.y() + up.y();
178
        double p4z = cz - right.z() + up.z();
179
180
        mesh.ensureQuadCapacity();
181
        RenderColor color = new RenderColor(argb);
182
        int i1 = mesh.vec3(p1x, p1y, p1z).vec2(0, 1).color(color).next();
183
        int i2 = mesh.vec3(p2x, p2y, p2z).vec2(1, 1).color(color).next();
184
        int i3 = mesh.vec3(p3x, p3y, p3z).vec2(1, 0).color(color).next();
185
        int i4 = mesh.vec3(p4x, p4y, p4z).vec2(0, 0).color(color).next();
186
        mesh.quad(i1, i2, i3, i4);
187
    }
188
189
    @Override
190
    public WorldPhase getWorldPhase() {
191
        return WorldPhase.END_MAIN;
192
    }
193
194
    @Override
195
    public void onDisable() {
196
        waves.clear();
197
        hitParticles.clear();
198
        lastHitParticleTick = Integer.MIN_VALUE;
199
        spawnedHitParticlesThisTick = 0;
200
    }
201
202
    public void handleHit(Entity target) {
203
        if (!isEnabled() || mc.player == null || mc.level == null) return;
204
        if (!(target instanceof LivingEntity living)) return;
205
        if (onlyPlayers.get() && !(target instanceof Player)) return;
206
207
        if (isWaveMode()) {
208
            Vec3 pos = target.position().add(0.0, -0.1, 0.0);
209
            addWave(pos);
210
            return;
211
        }
212
213
        Vec3 hitPoint = resolveHitPoint(target);
214
        boolean critical = mc.player instanceof Player attacker && isCritical(attacker);
215
        spawnHitParticles(living, hitPoint, critical);
216
    }
217
218
    @Override
219
    public void onTick() {
220
        if (!isEnabled() || mc.player == null || mc.level == null) return;
221
222
        if (!isParticleMode()) {
223
            hitParticles.clear();
224
            return;
225
        }
226
227
        if (!hitParticles.isEmpty()) {
228
            hitParticles.removeIf(Particle3D::update);
229
        }
230
    }
231
232
    @Override
233
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
234
        if (!isEnabled() || mc.player == null || mc.level == null) return;
235
236
        if (isWaveMode()) {
237
            renderWaveEffect(renderer);
238
            return;
239
        }
240
241
        if (!hitParticles.isEmpty()) {
242
            renderHitParticles(renderer, tickDelta);
243
        }
244
    }
245
246
    private void renderWaveEffect(Renderer3D renderer) {
247
        if (waves.isEmpty() || mc.level == null) return;
248
249
        long nowMs = System.currentTimeMillis();
250
        Iterator<SurfaceWaveDescriptor> iterator = waves.iterator();
251
        while (iterator.hasNext()) {
252
            SurfaceWaveDescriptor wave = iterator.next();
253
            if (wave.isExpired(nowMs)) {
254
                iterator.remove();
255
                continue;
256
            }
257
            CurrentSurfaceWaveRenderer.render(renderer, mc.level, wave, nowMs, this::getColorArgb);
258
        }
259
    }
260
261
    private void addWave(Vec3 pos) {
262
        if (mc.level == null || pos == null) return;
263
        waves.add(new SurfaceWaveDescriptor(
264
                pos,
265
                System.currentTimeMillis(),
266
                Math.max(1L, waveDurationMs.get()),
267
                Math.max(1, waveRadius.get()),
268
                WAVE_WIDTH,
269
                WAVE_FILL_TRAIL,
270
                WAVE_FILL_ALPHA,
271
                WAVE_TRAIL_ALPHA,
272
                WAVE_MAX_PER_FRAME,
273
                WAVE_MIN_ALPHA,
274
                depthTest.get()
275
        ));
276
    }
277
278
    private void spawnHitParticles(LivingEntity target, Vec3 hitPoint, boolean critical) {
279
        int requested = Math.max(0, hitParticleCount.get());
280
        if (critical) {
281
            requested = Math.max(requested, Math.round(requested * 1.35f));
282
        }
283
284
        int count = reserveHitParticleBudget(requested);
285
        if (count <= 0) return;
286
287
        Vec3 center = target.position().add(0.0, target.getBbHeight() * 0.52, 0.0);
288
        Vec3 normal = hitPoint.subtract(center);
289
        if (normal.lengthSqr() < 1.0e-6) {
290
            normal = center.subtract(mc.player.getEyePosition());
291
        }
292
        if (normal.lengthSqr() < 1.0e-6) {
293
            normal = new Vec3(0.0, 1.0, 0.0);
294
        } else {
295
            normal = normal.normalize();
296
        }
297
298
        float configuredSize = hitParticleSize.get();
299
        long configuredLife = Math.max(250L, hitParticleLifeMs.get());
300
301
        for (int i = 0; i < count; i++) {
302
            if (hitParticles.size() >= HIT_PARTICLE_MAX) {
303
                hitParticles.remove(0);
304
            }
305
306
            Vec3 tangent = randomTangent(normal);
307
            double jitter = randomRange(0.010, 0.055);
308
            Vec3 pos = hitPoint
309
                    .add(tangent.scale(jitter))
310
                    .add(normal.scale(randomRange(-0.015, 0.025)));
311
312
            double normalSpeed = randomRange(0.075, critical ? 0.175 : 0.145);
313
            double spreadSpeed = randomRange(0.025, critical ? 0.105 : 0.085);
314
            Vec3 velocity = normal.scale(normalSpeed)
315
                    .add(tangent.scale(spreadSpeed))
316
                    .add(0.0, randomRange(0.018, critical ? 0.075 : 0.060), 0.0);
317
318
            long life = Math.max(250L, Math.round(configuredLife * randomRange(0.78, 1.18)));
319
            long fadeIn = Math.min(95L, Math.max(35L, life / 10L));
320
            long fadeOut = Math.min(620L, Math.max(220L, life / 2L));
321
            float size = configuredSize * (float) randomRange(0.78, critical ? 1.35 : 1.22);
322
323
            int phase = target.getId() * 31 + i * 29 + (critical ? 47 : 0);
324
            int baseColor = getColorArgb(phase);
325
            int color = hitParticleRandomColor.get() ? harmonizedRandomColor(baseColor) : baseColor;
326
            ParticleTexture tex = resolveParticleTexture();
327
328
            float drag = (float) randomRange(HIT_PARTICLE_DRAG_MIN, HIT_PARTICLE_DRAG_MAX);
329
            float gravity = (float) randomRange(HIT_PARTICLE_GRAVITY_MIN, HIT_PARTICLE_GRAVITY_MAX);
330
            float rotationSpeed = (float) randomRange(-14.0, 14.0);
331
332
            hitParticles.add(new Particle3D(
333
                    pos,
334
                    velocity,
335
                    life,
336
                    fadeIn,
337
                    fadeOut,
338
                    size,
339
                    color,
340
                    tex.texture(),
341
                    tex.index(),
342
                    drag,
343
                    gravity,
344
                    rotationSpeed
345
            ));
346
        }
347
    }
348
349
    private Vec3 randomTangent(Vec3 normal) {
350
        Vec3 sample = new Vec3(
351
                randomRange(-1.0, 1.0),
352
                randomRange(-0.65, 1.0),
353
                randomRange(-1.0, 1.0)
354
        );
355
        Vec3 tangent = sample.subtract(normal.scale(sample.dot(normal)));
356
        if (tangent.lengthSqr() < 1.0e-6) {
357
            tangent = Math.abs(normal.y) < 0.9
358
                    ? normal.cross(new Vec3(0.0, 1.0, 0.0))
359
                    : normal.cross(new Vec3(1.0, 0.0, 0.0));
360
        }
361
        return tangent.normalize();
362
    }
363
364
    private double randomRange(double min, double max) {
365
        return min + random.nextDouble() * (max - min);
366
    }
367
368
    private int reserveHitParticleBudget(int requested) {
369
        if (requested <= 0 || mc.player == null) {
370
            return 0;
371
        }
372
373
        int tick = mc.player.tickCount;
374
        if (tick != lastHitParticleTick) {
375
            lastHitParticleTick = tick;
376
            spawnedHitParticlesThisTick = 0;
377
        }
378
379
        int remaining = HIT_PARTICLE_SPAWN_CAP_PER_TICK - spawnedHitParticlesThisTick;
380
        if (remaining <= 0) {
381
            return 0;
382
        }
383
384
        int granted = Math.min(requested, remaining);
385
        spawnedHitParticlesThisTick += granted;
386
        return granted;
387
    }
388
389
    private int harmonizedRandomColor(int baseArgb) {
390
        int alpha = (baseArgb >>> 24) & 0xFF;
391
        int r = (baseArgb >>> 16) & 0xFF;
392
        int g = (baseArgb >>> 8) & 0xFF;
393
        int b = baseArgb & 0xFF;
394
395
        float[] hsb = Color.RGBtoHSB(r, g, b, null);
396
        float hue = hsb[0] + (random.nextFloat() - 0.5f) * 0.18f;
397
        hue -= (float) Math.floor(hue);
398
        float saturation = Mth.clamp(hsb[1] * (0.82f + random.nextFloat() * 0.28f), 0.35f, 1.0f);
399
        float brightness = Mth.clamp(hsb[2] * (0.92f + random.nextFloat() * 0.16f), 0.55f, 1.0f);
400
        int rgb = Color.HSBtoRGB(hue, saturation, brightness) & 0x00FFFFFF;
401
        return (alpha << 24) | rgb;
402
    }
403
404
    private void renderHitParticles(Renderer3D renderer, float tickDelta) {
405
        boolean useDepth = depthTest.get();
406
        RenderPipeline pipeline = useDepth
407
                ? CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE_LIQUID_IGNORE
408
                : CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE;
409
        Renderer3D.DepthMode depthMode = useDepth ? Renderer3D.DepthMode.PRE_DEPTH : Renderer3D.DepthMode.MAIN;
410
        Quaternionf camRot = RenderState.cameraRotation;
411
412
        if (hitParticleTexture.get() == ParticleTextureMode.BLOOM) {
413
            MeshBuilder mesh = renderer.batchTextured(pipeline, TextureStorage.FIRE_FLY, depthMode);
414
            if (mesh == null) return;
415
            for (Particle3D particle : hitParticles) {
416
                renderParticle(mesh, particle, tickDelta, camRot, 1.0f, 1.0f);
417
            }
418
            return;
419
        }
420
421
        MeshBuilder glowMesh = renderer.batchTextured(pipeline, TextureStorage.FIRE_FLY, depthMode);
422
        if (glowMesh != null) {
423
            for (Particle3D particle : hitParticles) {
424
                renderParticle(glowMesh, particle, tickDelta, camRot, HIT_PARTICLE_GLOW_ALPHA, HIT_PARTICLE_GLOW_SCALE);
425
            }
426
        }
427
428
        clearBuckets(hitParticleBuckets);
429
        for (Particle3D particle : hitParticles) {
430
            int idx = particle.textureIndex();
431
            if (idx >= 0 && idx < hitParticleBuckets.length) {
432
                hitParticleBuckets[idx].add(particle);
433
            }
434
        }
435
436
        for (int i = 0; i < hitParticleBuckets.length; i++) {
437
            List<Particle3D> bucket = hitParticleBuckets[i];
438
            if (bucket.isEmpty()) continue;
439
            MeshBuilder mesh = renderer.batchTextured(pipeline, TextureStorage.RANDOM_PARTICLES[i], depthMode);
440
            if (mesh == null) continue;
441
            for (Particle3D particle : bucket) {
442
                renderParticle(mesh, particle, tickDelta, camRot, 0.92f, 1.0f);
443
            }
444
        }
445
    }
446
447
    private void renderParticle(MeshBuilder mesh,
448
                                Particle3D particle,
449
                                float tickDelta,
450
                                Quaternionf camRot,
451
                                float alphaMultiplier,
452
                                float sizeMultiplier) {
453
        Vec3 pos = particle.interpolate(tickDelta);
454
        float alpha = particle.alpha() * alphaMultiplier;
455
        if (alpha <= 0.008f) return;
456
457
        float t = particle.lifeProgress();
458
        float appear = smoothstep(t / 0.14f);
459
        float disappear = 1.0f - smoothstep((t - 0.70f) / 0.30f);
460
        float scaleEnvelope = (0.54f + appear * 0.54f) * (0.30f + disappear * 0.70f);
461
        float size = particle.size() * sizeMultiplier * scaleEnvelope;
462
        if (size <= 0.003f) return;
463
464
        int argb = applyOpacity(particle.color(), alpha);
465
        float rollRadians = (float) Math.toRadians(particle.rotation());
466
        addBillboardQuad(mesh, pos.x, pos.y, pos.z, size, camRot, rollRadians, argb);
467
    }
468
469
    private ParticleTexture resolveParticleTexture() {
470
        if (hitParticleTexture.get() == ParticleTextureMode.BLOOM) {
471
            return new ParticleTexture(TextureStorage.FIRE_FLY, -1);
472
        }
473
        int idx = random.nextInt(TextureStorage.RANDOM_PARTICLES.length);
474
        return new ParticleTexture(TextureStorage.RANDOM_PARTICLES[idx], idx);
475
    }
476
477
    private boolean isParticleMode() {
478
        return effectMode.get() == EffectMode.PARTICLES;
479
    }
480
481
    private boolean isWaveMode() {
482
        return effectMode.get() == EffectMode.WAVE;
483
    }
484
485
    private boolean usesSecondaryColor() {
486
        return AnimatedRenderColors.usesSecondary(animatedColorMode());
487
    }
488
489
    private int getColorArgb(int count) {
490
        return AnimatedRenderColors.resolve(
491
                animatedColorMode(),
492
                colorSpeed.get(),
493
                count,
494
                colorValue.getArgb(),
495
                colorValue2.getArgb()
496
        );
497
    }
498
499
    private AnimatedRenderColors.Mode animatedColorMode() {
500
        return switch (colorMode.get()) {
501
            case "Rainbow" -> AnimatedRenderColors.Mode.RAINBOW;
502
            case "LightRainbow" -> AnimatedRenderColors.Mode.LIGHT_RAINBOW;
503
            case "Sky" -> AnimatedRenderColors.Mode.SKY;
504
            case "Fade" -> AnimatedRenderColors.Mode.FADE;
505
            case "DoubleColor" -> AnimatedRenderColors.Mode.DOUBLE_COLOR;
506
            case "Analogous" -> AnimatedRenderColors.Mode.ANALOGOUS;
507
            case "Theme" -> AnimatedRenderColors.Mode.THEME;
508
            default -> AnimatedRenderColors.Mode.STATIC;
509
        };
510
    }
511
512
    private boolean isCritical(Player attacker) {
513
        if (!(attacker instanceof combatant.client.mixininterface.IPlayerAttackCooldown cooldownAccess)) return false;
514
        float cooldown = cooldownAccess.combatant$getAttackCooldownProgress(0.0f);
515
        if (cooldown < CHARGED_THRESHOLD) return false;
516
        if (attacker.onGround()) return false;
517
        if (attacker.onClimbable()) return false;
518
        if (attacker.isInWater()) return false;
519
        if (attacker.isPassenger()) return false;
520
        return attacker.fallDistance > 0.0f;
521
    }
522
523
    private Vec3 resolveHitPoint(Entity target) {
524
        ILocalPlayer access = (ILocalPlayer) mc.player;
525
        float yaw = access.combatant$getLastYaw();
526
        float pitch = access.combatant$getLastPitch();
527
        double distance = mc.player.distanceTo(target) + 1.0;
528
        Vec3 point = getRtxPoint(target, yaw, pitch, distance);
529
        if (point != null) return point;
530
        return target.position().add(0.0, target.getBbHeight() * 0.52, 0.0);
531
    }
532
533
    private Vec3 getRtxPoint(Entity target, float yaw, float pitch, double distance) {
534
        if (mc.player == null) return null;
535
536
        Vec3 start = mc.player.position().add(0, mc.player.getEyeHeight(mc.player.getPose()), 0);
537
        Vec3 rot = getRotationVector(pitch, yaw);
538
        Vec3 end = start.add(rot.scale(distance));
539
        AABB box = mc.player.getBoundingBox().expandTowards(rot.scale(distance)).inflate(1.0, 1.0, 1.0);
540
541
        EntityHitResult hit = ProjectileUtil.getEntityHitResult(
542
                mc.player,
543
                start,
544
                end,
545
                box,
546
                e -> !e.isSpectator() && e.isPickable() && e == target,
547
                distance * distance
548
        );
549
550
        return hit != null ? hit.getLocation() : null;
551
    }
552
553
    private Vec3 getRotationVector(float pitch, float yaw) {
554
        float yawRad = -yaw * ((float) Math.PI / 180F);
555
        float pitchRad = pitch * ((float) Math.PI / 180F);
556
        float cosYaw = Mth.cos(yawRad);
557
        float sinYaw = Mth.sin(yawRad);
558
        float cosPitch = Mth.cos(pitchRad);
559
        float sinPitch = Mth.sin(pitchRad);
560
        return new Vec3(sinYaw * cosPitch, -sinPitch, cosYaw * cosPitch);
561
    }
562
563
    public enum EffectMode implements EnumValue.IdProvider, EnumValue.AliasProvider {
564
        PARTICLES("particles", List.of("bubbles")),
565
        WAVE("wave", List.of());
566
567
        private final String id;
568
        private final List<String> aliases;
569
570
        EffectMode(String id, List<String> aliases) {
571
            this.id = id;
572
            this.aliases = aliases;
573
        }
574
575
        @Override
576
        public String id() {
577
            return id;
578
        }
579
580
        @Override
581
        public List<String> aliases() {
582
            return aliases;
583
        }
584
    }
585
586
    private record ParticleTexture(net.minecraft.resources.Identifier texture, int index) {
587
    }
588
589
590
}
591