KillEffect module

KillEffect: Minecraft 26.3 cheat module, full source for every implementation (2 clients: MelaHack (ThunderHack fork), Combatant).

2 implementationsRENDERVISUALS

Full module source: 2 implementations

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

MelaHack (ThunderHack fork)RENDERsrc/main/java/thunder/hack/features/modules/render/KillEffect.javaJava · 106 lines · 4.8 KB

Draws cool effects when someone dies.

SettingsModeY SpeedVolumePlay SoundColorMobs
KillEffect.javaJava · Minecraft 26.2 · 106 lines · 4.8 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import thunder.hack.core.Managers;
4
import thunder.hack.features.modules.Module;
5
import thunder.hack.setting.Setting;
6
import thunder.hack.setting.impl.ColorSetting;
7
import thunder.hack.utility.render.Render3DEngine;
8
import com.mojang.blaze3d.vertex.PoseStack;
9
import java.awt.*;
10
import java.util.Map;
11
import java.util.concurrent.ConcurrentHashMap;
12
import net.minecraft.core.particles.ParticleTypes;
13
import net.minecraft.sounds.SoundSource;
14
import net.minecraft.world.entity.Entity;
15
import net.minecraft.world.entity.EntityType;
16
import net.minecraft.world.entity.EntityTypes;
17
import net.minecraft.world.entity.LightningBolt;
18
import net.minecraft.world.entity.LivingEntity;
19
import net.minecraft.world.entity.player.Player;
20
21
public class KillEffect extends Module {
22
    public KillEffect() {
23
        super("KillEffect", Category.RENDER);
24
    }
25
26
    private final Setting<Mode> mode = new Setting<>("Mode", Mode.Orthodox);
27
    private final Setting<Integer> speed = new Setting<>("Y Speed", 0, -10, 10, value -> mode.getValue() == Mode.Orthodox);
28
    public final Setting<Integer> volume = new Setting<>("Volume", 100, 0, 100);
29
    private final Setting<Boolean> playSound = new Setting<>("Play Sound", true, value -> mode.getValue() == Mode.Orthodox);
30
    private final Setting<ColorSetting> color = new Setting<>("Color", new ColorSetting(new Color(255, 255, 0, 150)), value -> mode.getValue() == Mode.Orthodox);
31
    private final Setting<Boolean> mobs = new Setting<>("Mobs", false);
32
33
    private final Map<Entity, Long> renderEntities = new ConcurrentHashMap<>();
34
    private final Map<Entity, Long> lightingEntities = new ConcurrentHashMap<>();
35
36
    private enum Mode {
37
        Orthodox,
38
        FallingLava,
39
        LightningBolt
40
    }
41
42
    @Override
43
    public void onRender3D(PoseStack stack) {
44
        if (mc.level == null) return;
45
46
        switch (mode.getValue()) {
47
            case Orthodox -> renderEntities.forEach((entity, time) -> {
48
                if (System.currentTimeMillis() - time > 3000) {
49
                    renderEntities.remove(entity);
50
                } else {
51
                    Render3DEngine.drawLine(entity.position().add(0, calculateSpeed(), 0), entity.position().add(0, 3 + calculateSpeed(), 0), color.getValue().getColorObject());
52
                    Render3DEngine.drawLine(entity.position().add(1, 2.3 + calculateSpeed(), 0), entity.position().add(-1, 2.3 + calculateSpeed(), 0), color.getValue().getColorObject());
53
                    Render3DEngine.drawLine(entity.position().add(0.5, 1.2 + calculateSpeed(), 0), entity.position().add(-0.5, 0.8 + calculateSpeed(), 0), color.getValue().getColorObject());
54
                }
55
            });
56
            case FallingLava -> renderEntities.keySet().forEach(entity -> {
57
                for (int i = 0; i < entity.getBbHeight() * 10; i++) {
58
                    for (int j = 0; j < entity.getBbWidth() * 10; j++) {
59
                        for (int k = 0; k < entity.getBbWidth() * 10; k++) {
60
                            mc.level.addParticle(ParticleTypes.FALLING_LAVA, entity.getX() + j * 0.1, entity.getY() + i * 0.1, entity.getZ() + k * 0.1, 0, 0, 0);
61
                        }
62
                    }
63
                }
64
65
                renderEntities.remove(entity);
66
            });
67
            case LightningBolt -> renderEntities.forEach((entity, time) -> {
68
                LightningBolt lightningEntity = new LightningBolt(EntityTypes.LIGHTNING_BOLT, mc.level);
69
                lightningEntity.snapTo(entity.getX(), entity.getY(), entity.getZ());
70
                mc.level.addEntity(lightningEntity);
71
                renderEntities.remove(entity);
72
                lightingEntities.put(entity, System.currentTimeMillis());
73
            });
74
        }
75
    }
76
77
    @Override
78
    public void onUpdate() {
79
        Managers.ASYNC.getAsyncEntities().forEach(entity -> {
80
            if (!(entity instanceof Player) && !mobs.getValue()) return;
81
            if (!(entity instanceof LivingEntity liv)) return;
82
83
            if (entity == mc.player || renderEntities.containsKey(entity) || lightingEntities.containsKey(entity))
84
                return;
85
            if (entity.isAlive() || liv.getHealth() != 0) return;
86
87
            if (playSound.getValue() && mode.getValue() == Mode.Orthodox)
88
                mc.level.playSound(mc.player, entity.blockPosition(), Managers.SOUND.ORTHODOX_SOUNDEVENT, SoundSource.BLOCKS, volume.getValue() / 100f, 1f);
89
90
            renderEntities.put(entity, System.currentTimeMillis());
91
        });
92
93
        if (!lightingEntities.isEmpty()) {
94
            lightingEntities.forEach((entity, time) -> {
95
                if (System.currentTimeMillis() - time > 5000) {
96
                    lightingEntities.remove(entity);
97
                }
98
            });
99
        }
100
    }
101
102
    private double calculateSpeed() {
103
        return (double) speed.getValue() / 100;
104
    }
105
}
106
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/KillEffect.javaJava · 698 lines · 28.7 KB
SettingskillEffectModekillEffectYSpeedkillEffectPlaySoundkillEffectSoundVolumekillEffectColorkillEffectMobskillEffectKillBlur
KillEffect.javaJava · Minecraft 26.2 · 698 lines · 28.7 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.textures.GpuTextureView;
11
import net.minecraft.client.Minecraft;
12
import net.minecraft.client.player.AbstractClientPlayer;
13
import net.minecraft.client.multiplayer.ClientLevel;
14
import net.minecraft.network.protocol.game.ClientboundDamageEventPacket;
15
import net.minecraft.world.damagesource.DamageSource;
16
import net.minecraft.world.entity.Entity;
17
import net.minecraft.core.particles.ParticleTypes;
18
import net.minecraft.world.entity.LivingEntity;
19
import net.minecraft.world.entity.player.Player;
20
import net.minecraft.world.phys.Vec3;
21
import org.joml.Quaternionf;
22
import org.joml.Vector3f;
23
import combatant.client.config.values.BooleanValue;
24
import combatant.client.events.EventHandler;
25
import combatant.client.events.impl.PacketEvent;
26
import combatant.client.config.values.ModeValue;
27
import combatant.client.config.values.NumberValue;
28
import combatant.client.config.values.RGBAColorValue;
29
import combatant.client.features.module.Module;
30
import combatant.client.features.module.ModuleCategory;
31
import combatant.client.features.module.ModuleInfo;
32
import combatant.client.features.module.WorldPhase;
33
import combatant.client.mixins.accessors.ClientLevelAccessor;
34
import combatant.client.render.engine.RenderState;
35
import combatant.client.render.engine.TextureStorage;
36
import combatant.client.render.engine.color.ColorUtils;
37
import combatant.client.render.engine.color.RenderColor;
38
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
39
import combatant.client.render.engine.postprocess.PostProcessManager;
40
import combatant.client.render.engine.postprocess.PostProcessExecutionContext;
41
import combatant.client.render.engine.postprocess.PostProcessPass;
42
import combatant.client.render.engine.renderer.FullScreenRenderer;
43
import combatant.client.render.engine.renderer.Renderer3D;
44
import combatant.client.render.effects.emitter.BoxSurfaceEmitter;
45
import combatant.client.render.effects.emitter.SurfaceEmitterSample;
46
import combatant.client.render.effects.particle.ParticleEmitterDescriptor;
47
import combatant.client.features.playeranimator.render.PlayerRigSurfaceEmitter;
48
import combatant.client.render.engine.uniform.MeshBuilder;
49
import combatant.client.render.engine.uniform.impl.PostProcessUniforms;
50
import combatant.client.util.time.Timer;
51
import combatant.client.util.sound.SoundAsset;
52
import combatant.client.util.sound.SoundCatalog;
53
import combatant.client.util.sound.SoundKey;
54
import combatant.client.util.sound.SoundOptions;
55
56
import java.awt.*;
57
import java.util.*;
58
import java.util.List;
59
60
//todo Description
61
@ModuleInfo(id = "killeffect", displayName = "KillEffect", category = ModuleCategory.VISUALS)
62
public class KillEffect extends Module implements PostProcessPass {
63
    private static final int MAX_EMBERS = 26;
64
    private static final int MIN_EMBERS = 16;
65
    private static final int LIGHTNING_POINTS = 200;
66
    private static final double LIGHTNING_STEP_Y = 0.25;
67
    private static final float LIGHTNING_STEP_SPREAD = 0.25f;
68
    private static final long LIGHTNING_APPEAR_MS = 1200L;
69
    private static final long LIGHTNING_FADE_MS = 250L;
70
    private static final long LIGHTNING_LIFE_MS = LIGHTNING_APPEAR_MS + LIGHTNING_FADE_MS;
71
    private static final float LIGHTNING_MIN_SIZE = 0.26f;
72
    private static final float LIGHTNING_MAX_SIZE = 0.78f;
73
    private static final float LIGHTNING_ALPHA = 0.40f;
74
    private static final long KILL_BLUR_ATTACK_MS = 55L;
75
    private static final int FALLING_LAVA_MIN_SAMPLES = 48;
76
    private static final int FALLING_LAVA_MAX_SAMPLES = 96;
77
    private static final long KILL_BLUR_DURATION_MS = 520L;
78
    private static final long DAMAGE_CREDIT_TTL_MS = 30_000L;
79
    private static final double EFFECT_DETECTION_RADIUS = 192.0;
80
    private static final String SETTING_MODE = "mode";
81
    private static final String SETTING_Y_SPEED = "y_speed";
82
    private static final String SETTING_PLAY_SOUND = "play_sound";
83
    private static final String SETTING_SOUND_VOLUME = "sound_volume";
84
    private static final String SETTING_COLOR = "color";
85
    private static final String SETTING_MOBS = "mobs";
86
    private static final String SETTING_KILL_BLUR = "kill_blur";
87
    private static final long EMBER_GROUND_EXTRA_MS = 0;
88
    private final Minecraft mc = Minecraft.getInstance();
89
    private final Random random = new Random();
90
    private final ModeValue mode =
91
            modeSetting("killEffectMode", SETTING_MODE, "Orthodox", "Orthodox", "FallingLava", "EmbersArc", "Lightning");
92
    private final NumberValue<Integer> ySpeed =
93
            visibleWhen(num("killEffectYSpeed", SETTING_Y_SPEED, 0, -10, 10), () -> "Orthodox".equals(mode.get()));
94
    private final BooleanValue playSound =
95
            visibleWhen(bool("killEffectPlaySound", SETTING_PLAY_SOUND, true), () -> "Orthodox".equals(mode.get()));
96
    private final NumberValue<Double> soundVolume =
97
            visibleWhen(num("killEffectSoundVolume", SETTING_SOUND_VOLUME, 1.0, 0.0, 2.0),
98
                    () -> "Orthodox".equals(mode.get()) && playSound.get());
99
    private final RGBAColorValue color =
100
            visibleWhen(color("killEffectColor", SETTING_COLOR, "#FFFF9600"),
101
                    () -> "Orthodox".equals(mode.get()) || "Lightning".equals(mode.get()));
102
    private final BooleanValue mobs = bool("killEffectMobs", SETTING_MOBS, false);
103
    private final BooleanValue killBlur = bool("killEffectKillBlur", SETTING_KILL_BLUR, true);
104
    private final Map<Integer, Long> handled = new HashMap<>();
105
    private final Map<Integer, DamageCredit> damageCredits = new HashMap<>();
106
    private final List<OrthodoxMark> orthodoxMarks = new ArrayList<>();
107
    private final List<Ember> embers = new ArrayList<>();
108
    private final List<FlashRing> flashes = new ArrayList<>();
109
    private final List<LightningStrike> lightningStrikes = new ArrayList<>();
110
    private volatile long killBlurStartedMs;
111
    private ClientLevel stateLevel;
112
    private volatile long stateGeneration;
113
    // Published frames contain values, never mutable simulation objects or live collections.
114
    private volatile EffectFrame publishedFrame = EffectFrame.EMPTY;
115
116
    private record EmberFrame(Vec3 previous, Vec3 current, float size, float life) {
117
        Vec3 interpolate(float delta) { return previous.lerp(current, delta); }
118
    }
119
    private record FlashFrame(Vec3 pos, float progress) { }
120
    private record LightningFrame(List<Vec3> points, int colorArgb, float alpha) { }
121
    private record EffectFrame(List<OrthodoxMark> marks, List<EmberFrame> embers,
122
                               List<FlashFrame> flashes, List<LightningFrame> lightning) {
123
        private static final EffectFrame EMPTY = new EffectFrame(List.of(), List.of(), List.of(), List.of());
124
    }
125
126
    private void resetState(ClientLevel nextLevel) {
127
        stateGeneration++;
128
        stateLevel = nextLevel;
129
        handled.clear();
130
        damageCredits.clear();
131
        orthodoxMarks.clear();
132
        embers.clear();
133
        flashes.clear();
134
        lightningStrikes.clear();
135
        killBlurStartedMs = 0L;
136
        publishedFrame = EffectFrame.EMPTY;
137
    }
138
139
    private void publishFrame() {
140
        List<EmberFrame> emberFrames = new ArrayList<>(embers.size());
141
        for (Ember e : embers) {
142
            emberFrames.add(new EmberFrame(e.prevPos, e.pos, e.size, e.getLifeProgress()));
143
        }
144
        List<FlashFrame> flashFrames = new ArrayList<>(flashes.size());
145
        for (FlashRing ring : flashes) {
146
            flashFrames.add(new FlashFrame(ring.pos, Math.min(1f, ring.timer.getPassedTimeMs() / (float) ring.lifeMs)));
147
        }
148
        List<LightningFrame> lightningFrames = new ArrayList<>(lightningStrikes.size());
149
        for (LightningStrike strike : lightningStrikes) {
150
            lightningFrames.add(new LightningFrame(List.copyOf(strike.points), strike.colorArgb, strike.getAlpha()));
151
        }
152
        publishedFrame = new EffectFrame(List.copyOf(orthodoxMarks), List.copyOf(emberFrames),
153
                List.copyOf(flashFrames), List.copyOf(lightningFrames));
154
    }
155
156
    {
157
        PostProcessManager.register(this);
158
    }
159
160
    private static void addBillboardQuad(MeshBuilder mesh, double cx, double cy, double cz,
161
                                         float size, Quaternionf camRot, int argb) {
162
        Vector3f right = new Vector3f(1, 0, 0).rotate(camRot).mul(size);
163
        Vector3f up = new Vector3f(0, 1, 0).rotate(camRot).mul(size);
164
165
        double p1x = cx - right.x() - up.x();
166
        double p1y = cy - right.y() - up.y();
167
        double p1z = cz - right.z() - up.z();
168
        double p2x = cx + right.x() - up.x();
169
        double p2y = cy + right.y() - up.y();
170
        double p2z = cz + right.z() - up.z();
171
        double p3x = cx + right.x() + up.x();
172
        double p3y = cy + right.y() + up.y();
173
        double p3z = cz + right.z() + up.z();
174
        double p4x = cx - right.x() + up.x();
175
        double p4y = cy - right.y() + up.y();
176
        double p4z = cz - right.z() + up.z();
177
178
        mesh.ensureQuadCapacity();
179
        int i1 = mesh.vec3(p1x, p1y, p1z).vec2(0, 1).color(new RenderColor(argb)).next();
180
        int i2 = mesh.vec3(p2x, p2y, p2z).vec2(1, 1).color(new RenderColor(argb)).next();
181
        int i3 = mesh.vec3(p3x, p3y, p3z).vec2(1, 0).color(new RenderColor(argb)).next();
182
        int i4 = mesh.vec3(p4x, p4y, p4z).vec2(0, 0).color(new RenderColor(argb)).next();
183
        mesh.quad(i1, i2, i3, i4);
184
    }
185
186
    private static void addGroundQuad(MeshBuilder mesh, Vec3 center, float size, float angleDeg, int argb) {
187
        double radians = Math.toRadians(angleDeg);
188
        float cos = (float) Math.cos(radians);
189
        float sin = (float) Math.sin(radians);
190
191
        Vec3 right = new Vec3(cos, 0.0, -sin);
192
        Vec3 forward = new Vec3(sin, 0.0, cos);
193
194
        Vec3 p1 = center.add(right.scale(-size)).add(forward.scale(size));
195
        Vec3 p2 = center.add(right.scale(size)).add(forward.scale(size));
196
        Vec3 p3 = center.add(right.scale(size)).add(forward.scale(-size));
197
        Vec3 p4 = center.add(right.scale(-size)).add(forward.scale(-size));
198
199
        mesh.ensureQuadCapacity();
200
        int i1 = mesh.vec3(p1.x, p1.y, p1.z).vec2(0, 1).color(new RenderColor(argb)).next();
201
        int i2 = mesh.vec3(p2.x, p2.y, p2.z).vec2(1, 1).color(new RenderColor(argb)).next();
202
        int i3 = mesh.vec3(p3.x, p3.y, p3.z).vec2(1, 0).color(new RenderColor(argb)).next();
203
        int i4 = mesh.vec3(p4.x, p4.y, p4.z).vec2(0, 0).color(new RenderColor(argb)).next();
204
        mesh.quad(i1, i2, i3, i4);
205
    }
206
207
    private static int withAlpha(int argb, int alpha) {
208
        int a = Math.max(0, Math.min(255, alpha));
209
        return (a << 24) | (argb & 0x00FFFFFF);
210
    }
211
212
    private static float smoothProgress(float value) {
213
        float clamped = Math.max(0f, Math.min(1f, value));
214
        return clamped * clamped * (3f - 2f * clamped);
215
    }
216
217
    @Override
218
    public WorldPhase getWorldPhase() {
219
        return WorldPhase.END_MAIN;
220
    }
221
222
    @Override
223
    public boolean isActive() {
224
        return isEnabled() && killBlur.get() && mc.player != null && mc.level != null
225
                && getKillBlurStrength(System.currentTimeMillis()) > 0.001f;
226
    }
227
228
    @Override
229
    public int getPriority() {
230
        return 15;
231
    }
232
233
    @Override
234
    public Phase getPhase() {
235
        return Phase.POST_HAND;
236
    }
237
238
    @Override
239
    public boolean render(PostProcessExecutionContext execution) {
240
        if (execution == null) return false;
241
        GpuTextureView src = execution.source();
242
        GpuTextureView dst = execution.destination();
243
        if (!isEnabled() || !killBlur.get() || src == null || dst == null) return false;
244
245
        float strength = getKillBlurStrength(System.currentTimeMillis());
246
        if (strength <= 0.001f) return false;
247
248
        PostProcessUniforms.update(strength, 0.0f, 0.0f, 0.0f);
249
        FullScreenRenderer.begin("Combatant Kill Blur")
250
                .attachment(dst)
251
                .pipeline(CombatantRenderPipelines.KILL_BLUR)
252
                .uniform("PostProcess", PostProcessUniforms.get())
253
                .sampler("u_Texture", src, PostProcessManager.getSampler())
254
                .end();
255
        return true;
256
    }
257
258
    @Override
259
    public void onEnable() {
260
        if (mc.isSameThread()) resetState(mc.level);
261
        else mc.execute(() -> { if (isEnabled()) resetState(mc.level); });
262
    }
263
264
    @Override
265
    public void onTick() {
266
        if (!mc.isSameThread()) {
267
            mc.execute(this::onTick);
268
            return;
269
        }
270
        if (!isEnabled()) return;
271
        if (mc.level == null || mc.player == null) {
272
            if (stateLevel != null) resetState(null);
273
            return;
274
        }
275
        if (stateLevel != mc.level) resetState(mc.level);
276
277
        long now = System.currentTimeMillis();
278
        handled.entrySet().removeIf(e -> now - e.getValue() > 6000);
279
        damageCredits.entrySet().removeIf(e -> now - e.getValue().recordedAtMs() > DAMAGE_CREDIT_TTL_MS);
280
281
        List<LivingEntity> candidates = new ArrayList<>(mc.level.getEntitiesOfClass(
282
                LivingEntity.class, mc.player.getBoundingBox().inflate(EFFECT_DETECTION_RADIUS), e -> true));
283
        for (LivingEntity entity : candidates) {
284
            if (entity == mc.player) continue;
285
            if (!mobs.get() && !(entity instanceof Player)) continue;
286
            if (entity.isAlive() || entity.getHealth() > 0) continue;
287
288
            int id = entity.getId();
289
            if (handled.containsKey(id)) continue;
290
            handled.put(id, now);
291
            DamageCredit damageCredit = damageCredits.remove(id);
292
            boolean killedByLocalPlayer = damageCredit != null
293
                    && damageCredit.byLocalPlayer()
294
                    && now - damageCredit.recordedAtMs() <= DAMAGE_CREDIT_TTL_MS;
295
            if (killBlur.get() && killedByLocalPlayer) {
296
                killBlurStartedMs = now;
297
            }
298
299
            Vec3 pos = entity.position();
300
301
            if ("Orthodox".equals(mode.get())) {
302
                orthodoxMarks.add(new OrthodoxMark(pos, now));
303
                if (playSound.get()) {
304
                    KillSound.ORTHODOX.play(SoundOptions.at(pos).withGain(soundVolume.get()));
305
                }
306
            } else if ("FallingLava".equals(mode.get())) {
307
                spawnFallingLava(entity);
308
            } else if ("EmbersArc".equals(mode.get())) {
309
                spawnEmbers(pos);
310
            } else if ("Lightning".equals(mode.get())) {
311
                lightningStrikes.add(new LightningStrike(pos, color.getArgb(), now));
312
            }
313
        }
314
315
        if (!embers.isEmpty()) {
316
            embers.removeIf(e -> e.update(mc.level));
317
        }
318
319
        if (!flashes.isEmpty()) {
320
            flashes.removeIf(f -> f.timer.passedMs(f.lifeMs));
321
        }
322
323
        if (!lightningStrikes.isEmpty()) {
324
            lightningStrikes.removeIf(LightningStrike::isExpired);
325
        }
326
327
        if (!orthodoxMarks.isEmpty()) {
328
            orthodoxMarks.removeIf(m -> now - m.createdAtMs > 3000);
329
        }
330
        publishFrame();
331
    }
332
333
    @SoundCatalog(namespace = "combatant", root = "sounds/misc", idPrefix = "kill_effect")
334
    private enum KillSound implements SoundKey {
335
        @SoundAsset(
336
                value = "orthodox.wav",
337
                gain = 4.5f,
338
                rolloff = 0.09f,
339
                referenceDistance = 10.0f,
340
                maxDistance = 192.0f
341
        )
342
        ORTHODOX
343
    }
344
345
    @EventHandler
346
    private void onDamagePacket(PacketEvent.Receive event) {
347
        if (!isEnabled() || event == null) return;
348
        if (!(event.getPacket() instanceof ClientboundDamageEventPacket packet)) return;
349
        ClientLevel level = mc.level;
350
        if (level == null) return;
351
        long generation = stateGeneration;
352
        long receivedAt = System.currentTimeMillis();
353
        // Packet callbacks are not guaranteed to originate on the client thread.
354
        // Never resolve world entities or mutate simulation maps from a network callback.
355
        if (!mc.isSameThread()) {
356
            mc.execute(() -> {
357
                if (isEnabled() && mc.level == level && stateGeneration == generation)
358
                    recordDamage(level, packet, receivedAt);
359
            });
360
        } else {
361
            recordDamage(level, packet, receivedAt);
362
        }
363
    }
364
365
    private void recordDamage(ClientLevel level, ClientboundDamageEventPacket packet, long receivedAt) {
366
        if (!isEnabled() || mc.level != level || mc.player == null) return;
367
        if (stateLevel != level) return;
368
        Entity damaged = level.getEntity(packet.entityId());
369
        if (!(damaged instanceof LivingEntity living) || living == mc.player) return;
370
371
        Entity sourceEntity = null;
372
        try {
373
            DamageSource source = packet.getSource(level);
374
            if (source != null) {
375
                sourceEntity = source.getEntity();
376
                if (sourceEntity == null) sourceEntity = source.getDirectEntity();
377
            }
378
        } catch (RuntimeException ignored) {
379
            // A missing/late source reference cannot safely be attributed to the local player.
380
        }
381
        damageCredits.put(living.getId(), new DamageCredit(sourceEntity == mc.player, receivedAt));
382
    }
383
384
    @Override
385
    public void onDisable() {
386
        if (mc.isSameThread()) resetState(null);
387
        else mc.execute(() -> { if (!isEnabled()) resetState(null); });
388
    }
389
390
    @Override
391
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
392
        if (!isEnabled() || mc.level == null || mc.player == null) return;
393
394
        EffectFrame frame = publishedFrame;
395
        if ("Orthodox".equals(mode.get())) {
396
            renderOrthodox(renderer, frame.marks());
397
        } else if ("Lightning".equals(mode.get())) {
398
            renderLightning(renderer, frame.lightning());
399
        } else if ("EmbersArc".equals(mode.get())) {
400
            renderEmbers(renderer, tickDelta, frame.embers());
401
            renderFlashRings(renderer, frame.flashes());
402
        }
403
    }
404
405
    private void renderOrthodox(Renderer3D renderer, List<OrthodoxMark> marks) {
406
        int argb = color.getArgb();
407
        int r = (argb >> 16) & 255;
408
        int g = (argb >> 8) & 255;
409
        int b = argb & 255;
410
        int a = (argb >> 24) & 255;
411
412
        double offset = ySpeed.get() / 100.0;
413
414
        for (OrthodoxMark mark : marks) {
415
            Vec3 pos = mark.pos;
416
            renderer.line(pos.x, pos.y + offset, pos.z,
417
                    pos.x, pos.y + 3.0 + offset, pos.z, r, g, b, a);
418
            renderer.line(pos.x + 1.0, pos.y + 2.3 + offset, pos.z,
419
                    pos.x - 1.0, pos.y + 2.3 + offset, pos.z, r, g, b, a);
420
            renderer.line(pos.x + 0.5, pos.y + 1.2 + offset, pos.z,
421
                    pos.x - 0.5, pos.y + 0.8 + offset, pos.z, r, g, b, a);
422
        }
423
    }
424
425
    private void renderEmbers(Renderer3D renderer, float tickDelta, List<EmberFrame> emberFrames) {
426
        if (emberFrames.isEmpty()) return;
427
428
        MeshBuilder mesh = renderer.batchTextured(
429
                CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE,
430
                TextureStorage.FIRE_FLY,
431
                Renderer3D.DepthMode.MAIN
432
        );
433
        if (mesh == null) return;
434
435
        Quaternionf camRot = RenderState.cameraRotation;
436
437
        for (EmberFrame e : emberFrames) {
438
            Vec3 pos = e.interpolate(tickDelta);
439
            float lifeT = e.life();
440
            Color base = new Color(255, 20, 0, 255);
441
            Color hot = new Color(255, 220, 80, 255);
442
            Color col = ColorUtils.interpolateColorC(base, hot, 1f - lifeT);
443
444
            int alpha = (int) (255f * (1f - lifeT));
445
            int argb = withAlpha(col.getRGB(), alpha);
446
447
            float size = e.size() * (1f - lifeT);
448
            if (size <= 0.01f) continue;
449
450
            addBillboardQuad(mesh, pos.x, pos.y, pos.z, size, camRot, argb);
451
        }
452
453
    }
454
455
    private void renderFlashRings(Renderer3D renderer, List<FlashFrame> flashFrames) {
456
        if (flashFrames.isEmpty()) return;
457
458
        MeshBuilder mesh = renderer.batchTextured(
459
                CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE,
460
                TextureStorage.DEFAULT_CIRCLE,
461
                Renderer3D.DepthMode.MAIN
462
        );
463
        if (mesh == null) return;
464
465
        for (FlashFrame ring : flashFrames) {
466
            float t = ring.progress();
467
            float size = 0.4f + t * 1.8f;
468
            float alpha = (float) Math.pow(1f - t, 1.6);
469
470
            Color base = new Color(255, 60, 0, 255);
471
            Color hot = new Color(255, 220, 120, 255);
472
            Color col = ColorUtils.interpolateColorC(hot, base, t);
473
            int argb = withAlpha(col.getRGB(), (int) (255f * alpha));
474
475
            float angle = t * 180f;
476
            addGroundQuad(mesh, ring.pos, size, angle, argb);
477
        }
478
479
    }
480
481
    private void renderLightning(Renderer3D renderer, List<LightningFrame> lightningFrames) {
482
        if (lightningFrames.isEmpty()) return;
483
484
        MeshBuilder mesh = renderer.batchTextured(
485
                CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE,
486
                TextureStorage.FIRE_FLY,
487
                Renderer3D.DepthMode.MAIN
488
        );
489
        if (mesh == null) return;
490
491
        Quaternionf camRot = RenderState.cameraRotation;
492
493
        for (LightningFrame strike : lightningFrames) {
494
            float alpha = strike.alpha();
495
            if (alpha <= 0.01f) continue;
496
497
            int colorArgb = withAlpha(strike.colorArgb, (int) (255f * alpha * LIGHTNING_ALPHA));
498
            int pointCount = Math.max(1, strike.points.size() - 1);
499
500
            for (int i = 0; i < strike.points.size(); i++) {
501
                float progress = i / (float) pointCount;
502
                float size = LIGHTNING_MIN_SIZE + (LIGHTNING_MAX_SIZE - LIGHTNING_MIN_SIZE) * progress;
503
                Vec3 point = strike.points.get(i);
504
                addBillboardQuad(mesh, point.x, point.y, point.z, size, camRot, colorArgb);
505
            }
506
        }
507
    }
508
509
    private void spawnEmbers(Vec3 pos) {
510
        int count = MIN_EMBERS + random.nextInt(MAX_EMBERS - MIN_EMBERS + 1);
511
        for (int i = 0; i < count; i++) {
512
            double angle = random.nextDouble() * Math.PI * 2.0;
513
            double speed = 0.18 + random.nextDouble() * 0.18;
514
            double vx = Math.cos(angle) * speed;
515
            double vz = Math.sin(angle) * speed;
516
            double vy = 0.28 + random.nextDouble() * 0.20;
517
518
            long life = 4000 + random.nextInt(401);
519
            float size = 0.24f + random.nextFloat() * 0.18f;
520
            embers.add(new Ember(pos, new Vec3(vx, vy, vz), life, size));
521
        }
522
        flashes.add(new FlashRing(pos, 240));
523
    }
524
525
    private void spawnFallingLava(LivingEntity entity) {
526
        if (mc.level == null || entity == null) return;
527
528
        int count = Math.max(FALLING_LAVA_MIN_SAMPLES, Math.min(FALLING_LAVA_MAX_SAMPLES,
529
                Math.round((entity.getBbHeight() + entity.getBbWidth() * 2.0f) * 24.0f)));
530
        long seed = random.nextLong() ^ ((long) entity.getId() << 32) ^ System.nanoTime();
531
        ParticleEmitterDescriptor emitter;
532
        if (entity instanceof AbstractClientPlayer player) {
533
            emitter = new ParticleEmitterDescriptor.RigSurface(
534
                    entity.getId(), PlayerRigSurfaceEmitter.SOURCE_ID, count, seed);
535
        } else {
536
            var box = entity.getBoundingBox();
537
            emitter = new ParticleEmitterDescriptor.AabbSurface(
538
                    new Vec3(box.minX, box.minY, box.minZ),
539
                    new Vec3(box.maxX, box.maxY, box.maxZ),
540
                    count, seed);
541
        }
542
543
        for (int i = 0; i < emitter.count(); i++) {
544
            SurfaceEmitterSample sample;
545
            if (emitter instanceof ParticleEmitterDescriptor.RigSurface rigSurface
546
                    && entity instanceof AbstractClientPlayer player) {
547
                sample = PlayerRigSurfaceEmitter.sample(player, rigSurface.seed(), i);
548
            } else if (emitter instanceof ParticleEmitterDescriptor.AabbSurface aabb) {
549
                sample = BoxSurfaceEmitter.sample(aabb.min(), aabb.max(), aabb.seed(), i);
550
            } else {
551
                continue;
552
            }
553
554
            Vec3 normal = sample.normal();
555
            Vec3 position = sample.position().add(normal.scale(0.015));
556
            double outward = 0.012 + random.nextDouble() * 0.018;
557
            ((ClientLevelAccessor) mc.level).invokeAddParticle(
558
                    ParticleTypes.FALLING_LAVA,
559
                    false,
560
                    true,
561
                    position.x, position.y, position.z,
562
                    normal.x * outward, -0.01 + normal.y * outward, normal.z * outward
563
            );
564
        }
565
    }
566
567
    private float getKillBlurStrength(long nowMs) {
568
        if (killBlurStartedMs <= 0L) return 0.0f;
569
        long age = nowMs - killBlurStartedMs;
570
        if (age < 0L || age >= KILL_BLUR_DURATION_MS) return 0.0f;
571
572
        if (age < KILL_BLUR_ATTACK_MS) {
573
            return smoothProgress(age / (float) KILL_BLUR_ATTACK_MS);
574
        }
575
576
        float release = (age - KILL_BLUR_ATTACK_MS)
577
                / (float) Math.max(1L, KILL_BLUR_DURATION_MS - KILL_BLUR_ATTACK_MS);
578
        float eased = 1.0f - smoothProgress(release);
579
        return (float) Math.pow(Math.max(0.0f, eased), 1.25);
580
    }
581
582
    private float randomRange(float min, float max) {
583
        return min + random.nextFloat() * (max - min);
584
    }
585
586
    // textured rendering handled by Renderer3D batching
587
588
    private record OrthodoxMark(Vec3 pos, long createdAtMs) {
589
    }
590
591
    private static class Ember {
592
        private final Timer timer;
593
        private final long lifeMs;
594
        private final float size;
595
        private Vec3 pos;
596
        private Vec3 prevPos;
597
        private Vec3 velocity;
598
        private boolean grounded;
599
        private long groundExtraMs;
600
601
        private Ember(Vec3 pos, Vec3 velocity, long lifeMs, float size) {
602
            this.pos = pos;
603
            this.prevPos = pos;
604
            this.velocity = velocity;
605
            this.timer = new Timer();
606
            this.lifeMs = lifeMs;
607
            this.size = size;
608
        }
609
610
        private boolean update(ClientLevel world) {
611
            prevPos = pos;
612
            pos = pos.add(velocity);
613
614
            if (!grounded && world != null) {
615
                var blockPos = net.minecraft.core.BlockPos.containing(pos.x, pos.y - 0.02, pos.z);
616
                boolean solid = !world.getBlockState(blockPos).isAir();
617
                if (solid) {
618
                    grounded = true;
619
                    velocity = new Vec3(0.0, 0.0, 0.0);
620
                    groundExtraMs = EMBER_GROUND_EXTRA_MS;
621
                    pos = new Vec3(pos.x, blockPos.getY() + 1.001, pos.z);
622
                }
623
            }
624
625
            if (!grounded) {
626
                velocity = velocity.multiply(0.97, 0.97, 0.97).add(0.0, -0.055, 0.0);
627
            }
628
629
            long totalLife = lifeMs + groundExtraMs;
630
            return timer.passedMs(totalLife);
631
        }
632
633
        private Vec3 interpolate(float tickDelta) {
634
            return prevPos.lerp(pos, tickDelta);
635
        }
636
637
        private float getLifeProgress() {
638
            long totalLife = lifeMs + groundExtraMs;
639
            return Math.min(1f, timer.getPassedTimeMs() / (float) totalLife);
640
        }
641
    }
642
643
    private static class FlashRing {
644
        private final Vec3 pos;
645
        private final Timer timer;
646
        private final long lifeMs;
647
648
        private FlashRing(Vec3 pos, long lifeMs) {
649
            this.pos = pos;
650
            this.timer = new Timer();
651
            this.lifeMs = lifeMs;
652
        }
653
    }
654
655
    private class LightningStrike {
656
        private final List<Vec3> points;
657
        private final int colorArgb;
658
        private final long createdAtMs;
659
660
        private LightningStrike(Vec3 startPos, int colorArgb, long createdAtMs) {
661
            this.colorArgb = colorArgb;
662
            this.createdAtMs = createdAtMs;
663
            List<Vec3> points = new ArrayList<>(LIGHTNING_POINTS);
664
665
            Vec3 current = startPos;
666
            for (int i = 0; i < LIGHTNING_POINTS; i++) {
667
                current = current.add(
668
                        randomRange(-LIGHTNING_STEP_SPREAD, LIGHTNING_STEP_SPREAD),
669
                        LIGHTNING_STEP_Y,
670
                        randomRange(-LIGHTNING_STEP_SPREAD, LIGHTNING_STEP_SPREAD)
671
                );
672
                points.add(current);
673
            }
674
            this.points = List.copyOf(points);
675
        }
676
677
        private boolean isExpired() {
678
            return System.currentTimeMillis() - createdAtMs > LIGHTNING_LIFE_MS;
679
        }
680
681
        private float getAlpha() {
682
            long age = System.currentTimeMillis() - createdAtMs;
683
            float appear = smoothProgress(Math.min(1f, age / (float) LIGHTNING_APPEAR_MS));
684
            float fade = 1f;
685
            if (age > LIGHTNING_APPEAR_MS) {
686
                float fadeProgress = Math.min(1f, (age - LIGHTNING_APPEAR_MS) / (float) LIGHTNING_FADE_MS);
687
                fade = 1f - smoothProgress(fadeProgress);
688
            }
689
            return Math.max(0f, Math.min(1f, appear * fade));
690
        }
691
    }
692
693
    private record DamageCredit(boolean byLocalPlayer, long recordedAtMs) {
694
    }
695
696
}
697
698