Trails module

Trails: 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/Trails.javaJava · 482 lines · 25.9 KB

Shows the paths of arrows, pearls and players.

SettingsXpPearlsArrowsPlayersOnlySelfColorDownHeightSpeedModePhysicsScaleAmountLifeTimeColorModeColor2
Trails.javaJava · Minecraft 26.2 · 482 lines · 25.9 KB · complete file, verbatimOriginal ↗
1
package thunder.hack.features.modules.render;
2
3
import com.mojang.blaze3d.vertex.BufferBuilder;
4
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
5
import com.mojang.blaze3d.vertex.PoseStack;
6
import thunder.hack.utility.render.Tesselator;
7
import com.mojang.blaze3d.vertex.VertexFormat;
8
import com.mojang.math.Axis;
9
import com.mojang.blaze3d.platform.GlStateManager;
10
import thunder.hack.utility.render.compat.RenderSystem;
11
import net.minecraft.client.Camera;
12
import thunder.hack.utility.render.ShaderProgramKeys;
13
import thunder.hack.utility.render.BufferRenderer;
14
import net.minecraft.core.BlockPos;
15
import net.minecraft.world.entity.Entity;
16
import net.minecraft.world.entity.player.Player;
17
import net.minecraft.world.entity.projectile.arrow.Arrow;
18
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownEnderpearl;
19
import net.minecraft.world.entity.projectile.throwableitemprojectile.ThrownExperienceBottle;
20
import net.minecraft.world.level.ClipContext;
21
import net.minecraft.world.level.block.Block;
22
import net.minecraft.world.level.block.Blocks;
23
import net.minecraft.world.phys.HitResult;
24
import net.minecraft.world.phys.Vec3;
25
import org.joml.Matrix4f;
26
import org.lwjgl.opengl.GL11;
27
import thunder.hack.core.Managers;
28
import thunder.hack.features.modules.Module;
29
import thunder.hack.features.modules.client.HudEditor;
30
import thunder.hack.setting.Setting;
31
import thunder.hack.setting.impl.ColorSetting;
32
import thunder.hack.utility.interfaces.IEntity;
33
import thunder.hack.utility.math.MathUtility;
34
import thunder.hack.utility.render.Render2DEngine;
35
import thunder.hack.utility.render.Render3DEngine;
36
import thunder.hack.utility.render.TextureStorage;
37
38
import java.awt.*;
39
import java.util.ArrayList;
40
import java.util.List;
41
42
import static thunder.hack.utility.render.Render2DEngine.applyOpacity;
43
44
public class Trails extends Module {
45
    public Trails() {
46
        super("Trails", Category.RENDER);
47
    }
48
49
    private final Setting<Boolean> xp = new Setting<>("Xp", false);
50
    private final Setting<Particles> pearls = new Setting<>("Pearls", Particles.Particles);
51
    private final Setting<Particles> arrows = new Setting<>("Arrows", Particles.Particles);
52
    private final Setting<Players> players = new Setting<>("Players", Players.Particles);
53
    private final Setting<Boolean> onlySelf = new Setting<>("OnlySelf", false, v -> players.getValue() != Players.None);
54
    private final Setting<ColorSetting> color = new Setting<>("Color", new ColorSetting(0x8800FF00));
55
    private final Setting<Float> down = new Setting<>("Down", 0.5F, 0.0F, 2.0F);
56
    private final Setting<Float> width = new Setting<>("Height", 1.3F, 0.1F, 2.0F);
57
    private final Setting<Integer> speed = new Setting<>("Speed", 2, 1, 20, v -> players.is(Players.Particles) || arrows.is(Particles.Particles) || pearls.is(Particles.Particles));
58
    private final Setting<HitParticles.Mode> mode = new Setting<>("Mode", HitParticles.Mode.Stars);
59
    private final Setting<HitParticles.Physics> physics = new Setting<>("Physics", HitParticles.Physics.Fall, v -> players.is(Players.Particles) || arrows.is(Particles.Particles) || pearls.is(Particles.Particles));
60
    private final Setting<Integer> starsScale = new Setting<>("Scale", 3, 1, 10, v -> players.is(Players.Particles) || arrows.is(Particles.Particles) || pearls.is(Particles.Particles));
61
    private final Setting<Integer> amount = new Setting<>("Amount", 2, 1, 5, v -> players.is(Players.Particles) || arrows.is(Particles.Particles) || pearls.is(Particles.Particles));
62
    private final Setting<Integer> lifeTime = new Setting<>("LifeTime", 2, 1, 10, v -> players.is(Players.Particles) || arrows.is(Particles.Particles) || pearls.is(Particles.Particles));
63
    private final Setting<Mode> lmode = new Setting<>("ColorMode", Mode.Sync);
64
    private final Setting<ColorSetting> lcolor = new Setting<>("Color2", new ColorSetting(0x2250b4b4), v -> lmode.getValue() == Mode.Custom);
65
66
    private List<Particle> particles = new ArrayList<>();
67
68
    public void onRender3D(PoseStack stack) {
69
        for (Entity en : Managers.ASYNC.getAsyncEntities()) {
70
            if (en instanceof ThrownEnderpearl && pearls.is(Particles.Trail))
71
                calcTrajectory(en);
72
73
            if (en instanceof Arrow && arrows.is(Particles.Trail))
74
                calcTrajectory(en);
75
76
            if (en instanceof ThrownExperienceBottle && xp.getValue())
77
                calcTrajectory(en);
78
        }
79
        if (players.getValue() == Players.Trail) {
80
            for (Player entity : mc.level.players()) {
81
                if (entity != mc.player && onlySelf.getValue())
82
                    continue;
83
84
                float alpha = color.getValue().getAlpha() / 255f;
85
                if (!((IEntity) entity).getTrails().isEmpty()) {
86
                    stack.pushPose();
87
                    RenderSystem.disableCull();
88
                    RenderSystem.enableBlend();
89
                    RenderSystem.defaultBlendFunc();
90
                    RenderSystem.enableDepthTest();
91
                    RenderSystem.depthFunc(GL11.GL_LEQUAL);
92
93
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
94
                    BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
95
96
                    for (int i = 0; i < ((IEntity) entity).getTrails().size(); i++) {
97
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
98
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
99
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + down.getValue(), (float) pos.z).setColor(Render2DEngine.injectAlpha(((IEntity) entity).getTrails().get(i).color(), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
100
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + width.getValue() + down.getValue(), (float) pos.z).setColor(Render2DEngine.injectAlpha(((IEntity) entity).getTrails().get(i).color(), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
101
                    }
102
103
                    Render2DEngine.endBuilding(bufferBuilder);
104
105
                    Render3DEngine.endRender();
106
                    RenderSystem.enableCull();
107
                    RenderSystem.disableDepthTest();
108
                    stack.popPose();
109
                }
110
            }
111
        } else if (players.getValue() == Players.Tail) {
112
            for (Player entity : mc.level.players()) {
113
                if (entity != mc.player && onlySelf.getValue())
114
                    continue;
115
                float alpha = color.getValue().getAlpha();
116
                Camera camera = mc.gameRenderer.mainCamera();
117
                stack.pushPose();
118
                RenderSystem.setShaderTexture(0, TextureStorage.firefly);
119
                RenderSystem.enableBlend();
120
                RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
121
                RenderSystem.enableDepthTest();
122
                RenderSystem.depthMask(false);
123
                RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
124
                BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
125
126
                int size = ((IEntity) entity).getTrails().size();
127
                if (!((IEntity) entity).getTrails().isEmpty()) {
128
                    for (int i = 0; i < size; i++) {
129
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
130
                        PoseStack matrices = new PoseStack();
131
                        matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
132
                        matrices.mulPose(Axis.YP.rotationDegrees(camera.yRot() + 180.0F));
133
134
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
135
                        matrices.translate(pos.x, pos.y + 0.9f, pos.z);
136
137
                        matrices.mulPose(Axis.YP.rotationDegrees(-camera.yRot()));
138
                        matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
139
                        Matrix4f matrix = matrices.last().pose();
140
141
                        Color col = ctx.color();
142
143
                        float sc = 0.6f;
144
145
                        float colorFactor = (float) i / (float) size;
146
                        col = Render2DEngine.interpolateColorC(col, Color.WHITE, (float) Math.pow(1f - colorFactor, 2f));
147
                        float animPow = (float) ctx.animation(Render3DEngine.getTickDelta());
148
                        int animatedAlpha = (int) (alpha * animPow);
149
150
                        bufferBuilder.addVertex(matrix, -sc, sc, 0).setUv(0f, 1f).setColor(Render2DEngine.injectAlpha(col, animatedAlpha).getRGB());
151
                        bufferBuilder.addVertex(matrix, sc, sc, 0).setUv(1f, 1f).setColor(Render2DEngine.injectAlpha(col, animatedAlpha).getRGB());
152
                        bufferBuilder.addVertex(matrix, sc, -sc, 0).setUv(1f, 0).setColor(Render2DEngine.injectAlpha(col, animatedAlpha).getRGB());
153
                        bufferBuilder.addVertex(matrix, -sc, -sc, 0).setUv(0, 0).setColor(Render2DEngine.injectAlpha(col, animatedAlpha).getRGB());
154
                    }
155
                }
156
                Render2DEngine.endBuilding(bufferBuilder);
157
                RenderSystem.depthMask(true);
158
                RenderSystem.disableDepthTest();
159
                RenderSystem.disableBlend();
160
                stack.popPose();
161
            }
162
        } else if (players.getValue() == Players.Cute) {
163
            for (Player entity : mc.level.players()) {
164
                if (entity != mc.player && onlySelf.getValue())
165
                    continue;
166
167
                float alpha = color.getValue().getAlpha() / 255f;
168
                if (!((IEntity) entity).getTrails().isEmpty()) {
169
                    stack.pushPose();
170
                    RenderSystem.disableCull();
171
                    RenderSystem.enableBlend();
172
                    RenderSystem.defaultBlendFunc();
173
                    RenderSystem.enableDepthTest();
174
                    RenderSystem.depthFunc(GL11.GL_LEQUAL);
175
176
                    float step = (float) (mc.player.getBoundingBox().getYsize() / 5f);
177
178
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
179
                    BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
180
181
182
                    for (int i = 0; i < ((IEntity) entity).getTrails().size(); i++) {
183
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
184
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
185
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(69, 221, 255), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
186
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(69, 221, 255), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
187
                    }
188
                    Render2DEngine.endBuilding(bufferBuilder);
189
190
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
191
                    bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
192
                    for (int i = 0; i < ((IEntity) entity).getTrails().size(); i++) {
193
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
194
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
195
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(248, 139, 160), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
196
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 2, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(248, 139, 160), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
197
                    }
198
                    Render2DEngine.endBuilding(bufferBuilder);
199
200
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
201
                    bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
202
                    for (int i = 0; i < ((IEntity) entity).getTrails().size(); i++) {
203
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
204
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
205
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 2, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(255, 255, 255), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
206
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 3, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(255, 255, 255), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
207
                    }
208
                    Render2DEngine.endBuilding(bufferBuilder);
209
210
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
211
                    bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
212
                    for (int i = 0; i < ((IEntity) entity).getTrails().size(); i++) {
213
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
214
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
215
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 3, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(248, 139, 160), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
216
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 4, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(248, 139, 160), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
217
                    }
218
                    Render2DEngine.endBuilding(bufferBuilder);
219
220
                    RenderSystem.setShader(ShaderProgramKeys.POSITION_COLOR);
221
                    bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.TRIANGLE_STRIP, DefaultVertexFormat.POSITION_COLOR);
222
                    for (int i = 0; i < ((IEntity) entity).getTrails().size(); i++) {
223
                        Trail ctx = ((IEntity) entity).getTrails().get(i);
224
                        Vec3 pos = ctx.interpolate(Render3DEngine.getTickDelta());
225
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 4, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(69, 221, 255), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
226
                        bufferBuilder.addVertex(stack.last().pose(), (float) pos.x, (float) pos.y + step * 5, (float) pos.z).setColor(Render2DEngine.injectAlpha(new Color(69, 221, 255), (int) ((alpha * ctx.animation(Render3DEngine.getTickDelta())) * 255)).getRGB());
227
                    }
228
                    Render2DEngine.endBuilding(bufferBuilder);
229
230
                    Render3DEngine.endRender();
231
                    RenderSystem.enableCull();
232
                    RenderSystem.disableDepthTest();
233
                    stack.popPose();
234
                }
235
            }
236
        }
237
238
        if (!particles.isEmpty()) {
239
            RenderSystem.enableBlend();
240
            RenderSystem.enableDepthTest();
241
            RenderSystem.depthMask(false);
242
243
            RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE);
244
245
            switch (mode.getValue()) {
246
                case Stars -> RenderSystem.setShaderTexture(0, TextureStorage.star);
247
                case Bloom -> RenderSystem.setShaderTexture(0, TextureStorage.firefly);
248
                case Hearts -> RenderSystem.setShaderTexture(0, TextureStorage.heart);
249
                default -> {
250
                    return;
251
                }
252
            }
253
254
            RenderSystem.setShader(ShaderProgramKeys.POSITION_TEX_COLOR);
255
            BufferBuilder bufferBuilder = Tesselator.getInstance().begin(com.mojang.blaze3d.PrimitiveTopology.QUADS, DefaultVertexFormat.POSITION_TEX_COLOR);
256
257
            if (mc.player != null && mc.level != null)
258
                particles.forEach(p -> p.render(stack, bufferBuilder));
259
260
            Render2DEngine.endBuilding(bufferBuilder);
261
            RenderSystem.disableBlend();
262
            RenderSystem.depthMask(true);
263
            RenderSystem.disableDepthTest();
264
            RenderSystem.setShaderColor(1f, 1f, 1f, 1f);
265
        }
266
    }
267
268
    @Override
269
    public void onUpdate() {
270
        Color c = lmode.getValue() == Mode.Sync ? HudEditor.getColor(mc.player.tickCount % 360) : lcolor.getValue().getColorObject();
271
272
        for (Player player : mc.level.players()) {
273
            if (player.position().z != player.zo || player.position().x != player.xo && (!onlySelf.getValue())) {
274
                ((IEntity) player).getTrails().add(new Trail(new Vec3(player.xo, player.yo, player.zo), player.position(), c));
275
                if (players.is(Players.Particles)) {
276
                    for (int i = 0; i < amount.getValue(); i++) {
277
                        particles.add(new Particle(player.getX(), MathUtility.random((float) (player.getY() + player.getBbHeight()), (float) player.getY()), player.getZ(), c));
278
                    }
279
                }
280
            }
281
            ((IEntity) player).getTrails().removeIf(Trail::update);
282
283
        }
284
285
        for (Entity en : Managers.ASYNC.getAsyncEntities()) {
286
            if (en instanceof Arrow ae && (ae.yo != ae.getY()) && arrows.is(Particles.Particles))
287
                for (int i = 0; i < 5; i++)
288
                    particles.add(new Particle(en.getX(), en.getY(), en.getZ(), HudEditor.getColor(mc.player.tickCount)));
289
290
            if (en instanceof ThrownEnderpearl && pearls.is(Particles.Particles))
291
                for (int i = 0; i < 5; i++)
292
                    particles.add(new Particle(en.getX(), en.getY(), en.getZ(), HudEditor.getColor(mc.player.tickCount)));
293
        }
294
295
        if (Managers.PLAYER.currentPlayerSpeed != 0) {
296
            ((IEntity) mc.player).getTrails().add(new Trail(new Vec3(mc.player.xo, mc.player.yo, mc.player.zo), mc.player.position(), c));
297
            if (players.is(Players.Particles)) {
298
                for (int i = 0; i < amount.getValue(); i++) {
299
                    particles.add(new Particle(mc.player.getX(), MathUtility.random((float) (mc.player.getY() + mc.player.getBbHeight()), (float) mc.player.getY()), mc.player.getZ(), c));
300
                }
301
            }
302
        }
303
        particles.removeIf(particle -> System.currentTimeMillis() - particle.time > 1000f * lifeTime.getValue());
304
    }
305
306
    public static class Trail {
307
        private final Vec3 from;
308
        private final Vec3 to;
309
        private final Color color;
310
        private int ticks, prevTicks;
311
312
        public Trail(Vec3 from, Vec3 to, Color color) {
313
            this.from = from;
314
            this.to = to;
315
            this.ticks = 10;
316
            this.color = color;
317
        }
318
319
        public Vec3 interpolate(float pt) {
320
            double x = from.x + ((to.x - from.x) * pt) - mc.getEntityRenderDispatcher().camera.position().x;
321
            double y = from.y + ((to.y - from.y) * pt) - mc.getEntityRenderDispatcher().camera.position().y;
322
            double z = from.z + ((to.z - from.z) * pt) - mc.getEntityRenderDispatcher().camera.position().z;
323
            return new Vec3(x, y, z);
324
        }
325
326
        public double animation(float pt) {
327
            return (this.prevTicks + (this.ticks - this.prevTicks) * pt) / 10.;
328
        }
329
330
        public boolean update() {
331
            this.prevTicks = this.ticks;
332
            return this.ticks-- <= 0;
333
        }
334
335
        public Color color() {
336
            return color;
337
        }
338
    }
339
340
    private void calcTrajectory(Entity e) {
341
        double motionX = e.getDeltaMovement().x;
342
        double motionY = e.getDeltaMovement().y;
343
        double motionZ = e.getDeltaMovement().z;
344
        double x = e.getX();
345
        double y = e.getY();
346
        double z = e.getZ();
347
        Vec3 lastPos = new Vec3(x, y, z);
348
        for (int i = 0; i < 300; i++) {
349
            lastPos = new Vec3(x, y, z);
350
            x += motionX;
351
            y += motionY;
352
            z += motionZ;
353
            if (mc.level.getBlockState(new BlockPos((int) x, (int) y, (int) z)).getBlock() == Blocks.WATER) {
354
                motionX *= 0.8;
355
                motionY *= 0.8;
356
                motionZ *= 0.8;
357
            } else {
358
                motionX *= 0.99;
359
                motionY *= 0.99;
360
                motionZ *= 0.99;
361
            }
362
            if (e instanceof Arrow) {
363
                motionY -= 0.05000000074505806;
364
            } else {
365
                motionY -= 0.03f;
366
            }
367
            Vec3 pos = new Vec3(x, y, z);
368
369
            if (mc.level.clip(new ClipContext(lastPos, pos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)) != null) {
370
                if (mc.level.clip(new ClipContext(lastPos, pos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)).getType() == HitResult.Type.ENTITY)
371
                    break;
372
                if (mc.level.clip(new ClipContext(lastPos, pos, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, mc.player)).getType() == HitResult.Type.BLOCK)
373
                    break;
374
            }
375
376
            if (y <= -65) break;
377
            if (e.getDeltaMovement().x == 0 && e.getDeltaMovement().y == 0 && e.getDeltaMovement().z == 0) continue;
378
379
            int alpha = (int) MathUtility.clamp((255f * (i / 8f)), 0, 255);
380
381
            Render3DEngine.drawLine(lastPos, pos, lmode.getValue() == Mode.Sync ? Render2DEngine.injectAlpha(HudEditor.getColor(i * 5), alpha) : Render2DEngine.injectAlpha(lcolor.getValue().getColorObject(), alpha));
382
        }
383
    }
384
385
    public class Particle {
386
        double x;
387
        double y;
388
        double z;
389
        double motionX;
390
        double motionY;
391
        double motionZ;
392
        long time;
393
        Color color;
394
395
        public Particle(double x, double y, double z, Color color) {
396
            this.x = x;
397
            this.y = y;
398
            this.z = z;
399
            motionX = MathUtility.random(-(float) speed.getValue() / 200f, (float) speed.getValue() / 200f);
400
            motionY = MathUtility.random(-(float) speed.getValue() / 200f, (float) speed.getValue() / 200f);
401
            motionZ = MathUtility.random(-(float) speed.getValue() / 200f, (float) speed.getValue() / 200f);
402
            time = System.currentTimeMillis();
403
            this.color = color;
404
        }
405
406
        public void update() {
407
            double sp = starsScale.getValue() / 10f;
408
            x += motionX;
409
            y += motionY;
410
            z += motionZ;
411
412
            if (posBlock(x, y - starsScale.getValue() / 10f, z)) {
413
                motionY = -motionY / 1.1;
414
            } else {
415
                if (posBlock(x, y, z)
416
                        || posBlock(x - sp, y, z - sp)
417
                        || posBlock(x + sp, y, z + sp)
418
                        || posBlock(x + sp, y, z - sp)
419
                        || posBlock(x - sp, y, z + sp)
420
                        || posBlock(x + sp, y, z)
421
                        || posBlock(x - sp, y, z)
422
                        || posBlock(x, y, z - sp)
423
                        || posBlock(x, y, z + sp)
424
                ) {
425
                    motionX = -motionX;
426
                    motionZ = -motionZ;
427
                }
428
            }
429
430
            if (physics.getValue() == HitParticles.Physics.Fall) motionY -= 0.0005f;
431
            motionX /= 1.005;
432
            motionZ /= 1.005;
433
            motionY /= 1.005;
434
        }
435
436
        public void render(PoseStack matrixStack, BufferBuilder bufferBuilder) {
437
            update();
438
            float scale = starsScale.getValue() / 10f;
439
            final double posX = x - mc.getEntityRenderDispatcher().camera.position().x;
440
            final double posY = y - mc.getEntityRenderDispatcher().camera.position().y;
441
            final double posZ = z - mc.getEntityRenderDispatcher().camera.position().z;
442
443
            Camera camera = mc.gameRenderer.mainCamera();
444
445
            PoseStack matrices = new PoseStack();
446
            matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
447
            matrices.mulPose(Axis.YP.rotationDegrees(camera.yRot() + 180.0F));
448
            matrices.translate(posX, posY, posZ);
449
            matrices.mulPose(Axis.YP.rotationDegrees(-camera.yRot()));
450
            matrices.mulPose(Axis.XP.rotationDegrees(camera.xRot()));
451
452
            Matrix4f matrix = matrices.last().pose();
453
454
            float colorAnim = (float) (System.currentTimeMillis() - time) / (1000f * lifeTime.getValue());
455
456
            Color c = lmode.getValue() == Mode.Sync ? HudEditor.getColor((int) (360 * colorAnim)) : lcolor.getValue().getColorObject();
457
458
            bufferBuilder.addVertex(matrix, -scale / 2, scale, 0).setUv(0, 1).setColor(applyOpacity(c, 1f - colorAnim).getRGB());
459
            bufferBuilder.addVertex(matrix, scale, scale, 0).setUv(1, 1).setColor(applyOpacity(c, 1f - colorAnim).getRGB());
460
            bufferBuilder.addVertex(matrix, scale, -scale / 2, 0).setUv(1, 0).setColor(applyOpacity(c, 1f - colorAnim).getRGB());
461
            bufferBuilder.addVertex(matrix, -scale / 2, -scale / 2, 0).setUv(0, 0).setColor(applyOpacity(c, 1f - colorAnim).getRGB());
462
        }
463
464
        private boolean posBlock(double x, double y, double z) {
465
            Block b = mc.level.getBlockState(BlockPos.containing(x, y, z)).getBlock();
466
            return b != Blocks.AIR && b != Blocks.WATER && b != Blocks.LAVA;
467
        }
468
    }
469
470
    private enum Mode {
471
        Custom, Sync
472
    }
473
474
    private enum Players {
475
        Trail, Particles, Cute, Tail, None
476
    }
477
478
    private enum Particles {
479
        Trail, Particles, None
480
    }
481
}
482
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/Trails.javaJava · 678 lines · 30.3 KB
SettingstrailsOnlySelftrailsHideFirstPersontrailsDepthTesttrailsTrailModetrailsColortrailsColorModetrailsColor2trailsColorSpeedtrailsLifeTimeTickstrailsScaletrailsTrailDowntrailsTrailHeighttrailsTrailStroketrailsTrailStrokeWidthtrailsTrailStrokeAlphatrailsColorPhasetrailsColorLengthSpreadtrailsColorAgeSpreadtrailsParticlesEnabledtrailsParticlesHideFirstPersontrailsParticleTriggerstrailsParticleWalkCounttrailsParticleJumpCounttrailsParticleProjectileCounttrailsParticleTexturetrailsParticleRandomColortrailsParticleSizetrailsParticleLifeMstrailsConnectedPathtrailsConnectedStep
Trails.javaJava · Minecraft 26.2 · 678 lines · 30.3 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.*;
12
import net.minecraft.client.Minecraft;
13
import net.minecraft.world.entity.player.Player;
14
import net.minecraft.world.entity.projectile.Projectile;
15
import net.minecraft.world.entity.projectile.arrow.AbstractArrow;
16
import net.minecraft.world.phys.Vec3;
17
import org.joml.Quaternionf;
18
import org.joml.Vector3f;
19
import combatant.client.config.values.*;
20
import combatant.client.features.module.Module;
21
import combatant.client.features.module.ModuleCategory;
22
import combatant.client.features.module.ModuleInfo;
23
import combatant.client.features.module.WorldPhase;
24
import combatant.client.mixininterface.IEntity;
25
import combatant.client.mixins.accessors.PersistentProjectileEntityAccessor;
26
import combatant.client.render.engine.RenderState;
27
import combatant.client.render.engine.TextureStorage;
28
import combatant.client.render.engine.animation.AnimatedRenderColors;
29
import combatant.client.render.engine.color.RenderColor;
30
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
31
import combatant.client.render.engine.renderer.Renderer3D;
32
import combatant.client.render.engine.uniform.MeshBuilder;
33
import combatant.client.render.effects.particle.ParticleSimulationProfile;
34
import combatant.client.render.helpers.Particle3D;
35
import combatant.client.render.helpers.ParticleTextureMode;
36
import combatant.client.render.helpers.TrailPoint;
37
38
import java.awt.*;
39
import java.util.*;
40
import java.util.List;
41
42
//todo Description
43
@ModuleInfo(id = "trails", displayName = "Trails", category = ModuleCategory.VISUALS)
44
public class Trails extends Module {
45
    private static final String SETTING_ONLY_SELF = "only_self";
46
    private static final String SETTING_HIDE_FIRST_PERSON = "hide_first_person";
47
    private static final String SETTING_DEPTH_TEST = "depth_test";
48
    private static final String SETTING_TRAIL_MODE = "trail_mode";
49
    private static final String SETTING_LIFE_TIME_TICKS = "life_time_ticks";
50
    private static final String SETTING_SCALE = "scale";
51
    private static final String SETTING_TRAIL_DOWN = "trail_down";
52
    private static final String SETTING_TRAIL_HEIGHT = "trail_height";
53
    private static final String SETTING_TRAIL_STROKE = "trail_stroke";
54
    private static final String SETTING_TRAIL_STROKE_WIDTH = "trail_stroke_width";
55
    private static final String SETTING_TRAIL_STROKE_ALPHA = "trail_stroke_alpha";
56
    private static final String SETTING_COLOR = "color";
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_PHASE = "color_phase";
60
    private static final String SETTING_COLOR_LENGTH_SPREAD = "color_length_spread";
61
    private static final String SETTING_COLOR_AGE_SPREAD = "color_age_spread";
62
    private static final String SETTING_COLOR_2 = "color2";
63
    private static final String SETTING_PARTICLES_ENABLED = "particles_enabled";
64
    private static final String SETTING_PARTICLES_HIDE_FIRST_PERSON = "particles_hide_first_person";
65
    private static final String SETTING_PARTICLE_TRIGGERS = "particle_triggers";
66
    private static final String SETTING_PARTICLE_TEXTURE = "particle_texture";
67
    private static final String SETTING_PARTICLE_RANDOM_COLOR = "particle_random_color";
68
    private static final String SETTING_PARTICLE_SIZE = "particle_size";
69
    private static final String SETTING_PARTICLE_LIFE = "particle_life_ms";
70
    private static final String SETTING_PARTICLE_WALK_COUNT = "particle_walk_count";
71
    private static final String SETTING_PARTICLE_JUMP_COUNT = "particle_jump_count";
72
    private static final String SETTING_PARTICLE_PROJECTILE_COUNT = "particle_projectile_count";
73
    private static final String SETTING_CONNECTED_PATH = "connected_path";
74
    private static final String SETTING_CONNECT_STEP = "connected_step";
75
    private static final ParticleSimulationProfile PARTICLE_SIMULATION =
76
            ParticleSimulationProfile.dragGravity(0.96f, 0.96f, 0.01f);
77
    private static final int PARTICLE_MAX = 600;
78
    private static final int PROJECTILE_SCAN_RADIUS = 48;
79
    private static final int PROJECTILE_MAX_SPAWN = 140;
80
    private static final int CONNECT_MAX_STEPS = 6;
81
    private final Minecraft mc = Minecraft.getInstance();
82
    private final Random random = new Random();
83
    private final BooleanValue onlySelf = bool("trailsOnlySelf", SETTING_ONLY_SELF, false);
84
    private final BooleanValue hideFirstPerson = bool("trailsHideFirstPerson", SETTING_HIDE_FIRST_PERSON, true);
85
    private final BooleanValue depthTest = bool("trailsDepthTest", SETTING_DEPTH_TEST, true);
86
    private final ModeValue trailMode =
87
            modeSetting("trailsTrailMode", SETTING_TRAIL_MODE, "Tail", "Tail", "Trail");
88
    private final RGBAColorValue colorValue = color("trailsColor", SETTING_COLOR, "#8800FF00");
89
    private final ModeValue colorMode =
90
            modeSetting("trailsColorMode", SETTING_COLOR_MODE, "Static",
91
                    "Static", "Rainbow", "LightRainbow", "Sky", "Fade", "DoubleColor", "Analogous", "Theme");
92
    private final RGBAColorValue colorValue2 =
93
            visibleWhen(color("trailsColor2", SETTING_COLOR_2, "#FF55FFFF"), this::usesSecondaryColor);
94
    private final NumberValue<Integer> colorSpeed =
95
            num("trailsColorSpeed", SETTING_COLOR_SPEED, 18, 2, 54);
96
    private final NumberValue<Integer> lifeTimeTicks =
97
            num("trailsLifeTimeTicks", SETTING_LIFE_TIME_TICKS, 10, 1, 40);
98
    private final NumberValue<Float> trailScale =
99
            visibleWhen(num("trailsScale", SETTING_SCALE, 0.6f, 0.2f, 1.2f), this::isTailMode);
100
    private final NumberValue<Float> trailDown =
101
            visibleWhen(num("trailsTrailDown", SETTING_TRAIL_DOWN, 0.5f, 0.0f, 2.0f), this::isTrailDownVisible);
102
    private final NumberValue<Float> trailHeight =
103
            visibleWhen(num("trailsTrailHeight", SETTING_TRAIL_HEIGHT, 1.3f, 0.1f, 2.0f), this::isTrailDownVisible);
104
    private final BooleanValue trailStroke =
105
            visibleWhen(bool("trailsTrailStroke", SETTING_TRAIL_STROKE, true), this::isTrailMode);
106
    private final NumberValue<Float> trailStrokeWidth =
107
            visibleWhen(num("trailsTrailStrokeWidth", SETTING_TRAIL_STROKE_WIDTH, 2.0f, 0.5f, 8.0f),
108
                    () -> isTrailMode() && trailStroke.get());
109
    private final NumberValue<Float> trailStrokeAlpha =
110
            visibleWhen(num("trailsTrailStrokeAlpha", SETTING_TRAIL_STROKE_ALPHA, 0.75f, 0.05f, 1.0f),
111
                    () -> isTrailMode() && trailStroke.get());
112
    private final NumberValue<Integer> colorPhase =
113
            num("trailsColorPhase", SETTING_COLOR_PHASE, 0, 0, 360);
114
    private final NumberValue<Integer> colorLengthSpread =
115
            num("trailsColorLengthSpread", SETTING_COLOR_LENGTH_SPREAD, 180, -720, 720);
116
    private final NumberValue<Integer> colorAgeSpread =
117
            num("trailsColorAgeSpread", SETTING_COLOR_AGE_SPREAD, 90, -720, 720);
118
    private final BooleanValue particlesEnabled =
119
            bool("trailsParticlesEnabled", SETTING_PARTICLES_ENABLED, false);
120
    private final BooleanValue particlesHideFirstPerson =
121
            visibleWhen(bool("trailsParticlesHideFirstPerson", SETTING_PARTICLES_HIDE_FIRST_PERSON, false), particlesEnabled::get);
122
    private final BooleanMapValue particleTriggers = visibleWhen(group("trailsParticleTriggers", SETTING_PARTICLE_TRIGGERS, Map.of(
123
            "walk", true,
124
            "jump", true,
125
            "projectile", true
126
    )), particlesEnabled::get);
127
    private final NumberValue<Integer> particleWalkCount =
128
            visibleWhen(num("trailsParticleWalkCount", SETTING_PARTICLE_WALK_COUNT, 3, 1, 8),
129
                    () -> particlesEnabled.get() && particleTriggers.get("walk"));
130
    private final NumberValue<Integer> particleJumpCount =
131
            visibleWhen(num("trailsParticleJumpCount", SETTING_PARTICLE_JUMP_COUNT, 12, 1, 30),
132
                    () -> particlesEnabled.get() && particleTriggers.get("jump"));
133
    private final NumberValue<Integer> particleProjectileCount =
134
            visibleWhen(num("trailsParticleProjectileCount", SETTING_PARTICLE_PROJECTILE_COUNT, 3, 1, 10),
135
                    () -> particlesEnabled.get() && particleTriggers.get("projectile"));
136
    private final EnumValue<ParticleTextureMode> particleTexture =
137
            visibleWhen(enumSetting("trailsParticleTexture", SETTING_PARTICLE_TEXTURE, ParticleTextureMode.BLOOM, ParticleTextureMode.values()),
138
                    particlesEnabled::get);
139
    private final BooleanValue particleRandomColor =
140
            visibleWhen(bool("trailsParticleRandomColor", SETTING_PARTICLE_RANDOM_COLOR, false), particlesEnabled::get);
141
    private final NumberValue<Float> particleSize =
142
            visibleWhen(num("trailsParticleSize", SETTING_PARTICLE_SIZE, 0.12f, 0.04f, 0.4f), particlesEnabled::get);
143
    private final NumberValue<Integer> particleLifeMs =
144
            visibleWhen(num("trailsParticleLifeMs", SETTING_PARTICLE_LIFE, 1600, 200, 5000), particlesEnabled::get);
145
    private final BooleanValue connectedPath =
146
            visibleWhen(bool("trailsConnectedPath", SETTING_CONNECTED_PATH, true), this::isTailMode);
147
    private final NumberValue<Float> connectStep =
148
            visibleWhen(num("trailsConnectedStep", SETTING_CONNECT_STEP, 0.35f, 0.1f, 1.0f),
149
                    () -> isTailMode() && connectedPath.get());
150
    private final Map<UUID, Boolean> groundState = new HashMap<>();
151
    private final List<Particle3D> extraParticles = new ArrayList<>();
152
    private final List<Particle3D>[] particleBuckets = createBuckets();
153
154
    @SuppressWarnings("unchecked")
155
    private static List<Particle3D>[] createBuckets() {
156
        List<Particle3D>[] buckets = new List[TextureStorage.RANDOM_PARTICLES.length];
157
        for (int i = 0; i < buckets.length; i++) {
158
            buckets[i] = new ArrayList<>();
159
        }
160
        return buckets;
161
    }
162
163
    private static void clearBuckets(List<Particle3D>[] buckets) {
164
        for (List<Particle3D> bucket : buckets) {
165
            bucket.clear();
166
        }
167
    }
168
169
    private static void addBillboardQuad(MeshBuilder mesh, double cx, double cy, double cz,
170
                                         Vector3f right, Vector3f up, int argb) {
171
        double p1x = cx - right.x() - up.x();
172
        double p1y = cy - right.y() - up.y();
173
        double p1z = cz - right.z() - up.z();
174
        double p2x = cx + right.x() - up.x();
175
        double p2y = cy + right.y() - up.y();
176
        double p2z = cz + right.z() - up.z();
177
        double p3x = cx + right.x() + up.x();
178
        double p3y = cy + right.y() + up.y();
179
        double p3z = cz + right.z() + up.z();
180
        double p4x = cx - right.x() + up.x();
181
        double p4y = cy - right.y() + up.y();
182
        double p4z = cz - right.z() + up.z();
183
184
        mesh.ensureQuadCapacity();
185
        int i1 = mesh.vec3(p1x, p1y, p1z).vec2(0, 1).color(new RenderColor(argb)).next();
186
        int i2 = mesh.vec3(p2x, p2y, p2z).vec2(1, 1).color(new RenderColor(argb)).next();
187
        int i3 = mesh.vec3(p3x, p3y, p3z).vec2(1, 0).color(new RenderColor(argb)).next();
188
        int i4 = mesh.vec3(p4x, p4y, p4z).vec2(0, 0).color(new RenderColor(argb)).next();
189
        mesh.quad(i1, i2, i3, i4);
190
    }
191
192
    private static void addBillboardQuad(MeshBuilder mesh, double cx, double cy, double cz,
193
                                         float size, Quaternionf camRot, int argb) {
194
        Vector3f right = new Vector3f(1, 0, 0).rotate(camRot).mul(size);
195
        Vector3f up = new Vector3f(0, 1, 0).rotate(camRot).mul(size);
196
        addBillboardQuad(mesh, cx, cy, cz, right, up, argb);
197
    }
198
199
    private static void addVerticalQuad(MeshBuilder mesh, Vec3 p0, Vec3 p1,
200
                                        float down, float height, int argb0, int argb1) {
201
        double x1 = p0.x;
202
        double z1 = p0.z;
203
        double y1 = p0.y + down;
204
        double y2 = p0.y + down + height;
205
206
        double x2 = p1.x;
207
        double z2 = p1.z;
208
        double y3 = p1.y + down + height;
209
        double y4 = p1.y + down;
210
211
        mesh.ensureQuadCapacity();
212
        int i1 = mesh.vec3(x1, y1, z1).color(new RenderColor(argb0)).next();
213
        int i2 = mesh.vec3(x1, y2, z1).color(new RenderColor(argb0)).next();
214
        int i3 = mesh.vec3(x2, y3, z2).color(new RenderColor(argb1)).next();
215
        int i4 = mesh.vec3(x2, y4, z2).color(new RenderColor(argb1)).next();
216
        mesh.quad(i1, i2, i3, i4);
217
    }
218
219
    private static void addLine(MeshBuilder mesh, double x0, double y0, double z0,
220
                                double x1, double y1, double z1, int argb0, int argb1) {
221
        mesh.ensureLineCapacity();
222
        int i1 = mesh.vec3(x0, y0, z0).color(new RenderColor(argb0)).next();
223
        int i2 = mesh.vec3(x1, y1, z1).color(new RenderColor(argb1)).next();
224
        mesh.line(i1, i2);
225
    }
226
227
    private static int withAlpha(int argb, int alpha) {
228
        int a = Math.max(0, Math.min(255, alpha));
229
        return (a << 24) | (argb & 0x00FFFFFF);
230
    }
231
232
    @Override
233
    public WorldPhase getWorldPhase() {
234
        return WorldPhase.END_MAIN;
235
    }
236
237
    @Override
238
    public void onTick() {
239
        if (!isEnabled() || mc.level == null || mc.player == null) return;
240
241
        int colorIndex = mc.player.tickCount % 360;
242
        boolean particlesOn = particlesEnabled.get();
243
        boolean triggerWalk = particlesOn && particleTriggers.get("walk");
244
        boolean triggerJump = particlesOn && particleTriggers.get("jump");
245
        boolean triggerProjectile = particlesOn && particleTriggers.get("projectile");
246
247
        if (!extraParticles.isEmpty()) {
248
            extraParticles.removeIf(Particle3D::update);
249
        }
250
251
        java.util.Set<UUID> active = new java.util.HashSet<>();
252
253
        for (Player player : mc.level.players()) {
254
            if (onlySelf.get() && player != mc.player) continue;
255
            active.add(player.getUUID());
256
257
            List<TrailPoint> trails = ((IEntity) player).combatant$getTrails();
258
            Vec3 last = ((IEntity) player).get$InstantRenderPos();
259
260
            boolean skipSelfInFirstPerson = hideFirstPerson.get()
261
                    && player == mc.player
262
                    && mc.options.getCameraType().isFirstPerson();
263
            boolean moved = player.getX() != last.x || player.getZ() != last.z;
264
            if (!skipSelfInFirstPerson && moved) {
265
                int argb = getColorArgb(colorIndex);
266
                trails.add(new TrailPoint(
267
                        last,
268
                        player.position(),
269
                        argb,
270
                        lifeTimeTicks.get()
271
                ));
272
            }
273
274
            trails.removeIf(TrailPoint::update);
275
276
            boolean skipParticlesFirstPerson = particlesHideFirstPerson.get()
277
                    && player == mc.player
278
                    && mc.options.getCameraType().isFirstPerson();
279
            if (particlesOn && !skipParticlesFirstPerson) {
280
                if (triggerWalk && moved) {
281
                    spawnWalkParticles(player, colorIndex);
282
                }
283
284
                boolean prevGround = groundState.getOrDefault(player.getUUID(), player.onGround());
285
                boolean nowGround = player.onGround();
286
                if (triggerJump && prevGround && !nowGround) {
287
                    spawnJumpParticles(player, colorIndex);
288
                }
289
                groundState.put(player.getUUID(), nowGround);
290
            }
291
        }
292
293
        if (particlesOn && triggerProjectile) {
294
            spawnProjectileParticles(colorIndex);
295
        }
296
297
        groundState.keySet().removeIf(id -> !active.contains(id));
298
    }
299
300
    @Override
301
    public void onDisable() {
302
        if (mc.level == null) return;
303
        for (Player player : mc.level.players()) {
304
            ((IEntity) player).combatant$getTrails().clear();
305
        }
306
        extraParticles.clear();
307
        groundState.clear();
308
    }
309
310
    @Override
311
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
312
        if (!isEnabled() || mc.level == null || mc.player == null) return;
313
314
        boolean useDepth = depthTest.get();
315
        if (particlesEnabled.get() && !extraParticles.isEmpty()) {
316
            renderExtraParticles(renderer, tickDelta);
317
        }
318
319
        if (isTrailMode()) {
320
            renderRibbonTrails(renderer, tickDelta, useDepth);
321
            return;
322
        }
323
324
        RenderPipeline pipeline = useDepth
325
                ? CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE_LIQUID_IGNORE
326
                : CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE;
327
        Renderer3D.DepthMode depthMode = useDepth ? Renderer3D.DepthMode.PRE_DEPTH : Renderer3D.DepthMode.MAIN;
328
        MeshBuilder mesh = renderer.batchTextured(pipeline, TextureStorage.FIRE_FLY, depthMode);
329
        if (mesh == null) return;
330
331
        Quaternionf camRot = RenderState.cameraRotation;
332
        float scale = trailScale.get();
333
        Vector3f right = new Vector3f(1, 0, 0).rotate(camRot).mul(scale);
334
        Vector3f up = new Vector3f(0, 1, 0).rotate(camRot).mul(scale);
335
        boolean connect = connectedPath.get();
336
        float step = Math.max(0.05f, connectStep.get());
337
        int phaseBase = currentColorPhase(tickDelta);
338
339
        for (Player player : mc.level.players()) {
340
            if (onlySelf.get() && player != mc.player) continue;
341
            if (hideFirstPerson.get()
342
                    && player == mc.player
343
                    && mc.options.getCameraType().isFirstPerson()) {
344
                continue;
345
            }
346
347
            List<TrailPoint> trails = ((IEntity) player).combatant$getTrails();
348
            int size = trails.size();
349
            if (size == 0) continue;
350
351
            for (int i = 0; i < size; i++) {
352
                TrailPoint ctx = trails.get(i);
353
354
                int col = trailPointColor(ctx, i, size, tickDelta, phaseBase);
355
                float anim = ctx.animation(tickDelta);
356
                int alpha = (int) (((col >>> 24) & 0xFF) * anim);
357
                int argb = withAlpha(col, alpha);
358
359
                if (connect) {
360
                    Vec3 from = ctx.from();
361
                    Vec3 to = ctx.to();
362
                    double dist = from.distanceTo(to);
363
                    int steps = Math.min(CONNECT_MAX_STEPS, (int) Math.ceil(dist / step));
364
                    if (steps <= 1) {
365
                        Vec3 pos = ctx.interpolate(tickDelta);
366
                        addBillboardQuad(mesh, pos.x, pos.y + 0.9, pos.z, right, up, argb);
367
                    } else {
368
                        for (int s = 0; s <= steps; s++) {
369
                            float t = s / (float) steps;
370
                            Vec3 pos = from.lerp(to, t);
371
                            addBillboardQuad(mesh, pos.x, pos.y + 0.9, pos.z, right, up, argb);
372
                        }
373
                    }
374
                } else {
375
                    Vec3 pos = ctx.interpolate(tickDelta);
376
                    addBillboardQuad(mesh, pos.x, pos.y + 0.9, pos.z, right, up, argb);
377
                }
378
            }
379
        }
380
381
    }
382
383
    private void renderRibbonTrails(Renderer3D renderer, float tickDelta, boolean useDepth) {
384
        RenderPipeline pipeline = useDepth
385
                ? CombatantRenderPipelines.WORLD_COLORED_LIQUID_IGNORE
386
                : CombatantRenderPipelines.WORLD_COLORED;
387
        Renderer3D.DepthMode depthMode = useDepth ? Renderer3D.DepthMode.PRE_DEPTH : Renderer3D.DepthMode.MAIN;
388
        MeshBuilder mesh = renderer.batch(pipeline, depthMode);
389
        if (mesh == null) return;
390
391
        MeshBuilder strokeMesh = null;
392
        if (trailStroke.get()) {
393
            float previousLineWidth = RenderState.lineWidth;
394
            try {
395
                RenderState.lineWidth = Math.max(0.5f, trailStrokeWidth.get());
396
                strokeMesh = renderer.batch(
397
                        useDepth
398
                                ? CombatantRenderPipelines.WORLD_COLORED_LINES_LIQUID_IGNORE
399
                                : CombatantRenderPipelines.WORLD_COLORED_LINES,
400
                        depthMode
401
                );
402
            } finally {
403
                RenderState.lineWidth = previousLineWidth;
404
            }
405
        }
406
407
        float down = trailDown.get();
408
        float height = trailHeight.get();
409
        int phaseBase = currentColorPhase(tickDelta);
410
411
        for (Player player : mc.level.players()) {
412
            if (onlySelf.get() && player != mc.player) continue;
413
            if (hideFirstPerson.get()
414
                    && player == mc.player
415
                    && mc.options.getCameraType().isFirstPerson()) {
416
                continue;
417
            }
418
419
            List<TrailPoint> trails = ((IEntity) player).combatant$getTrails();
420
            int size = trails.size();
421
            if (size < 2) continue;
422
423
            for (int i = 1; i < size; i++) {
424
                TrailPoint prev = trails.get(i - 1);
425
                TrailPoint cur = trails.get(i);
426
427
                Vec3 p0 = prev.interpolate(tickDelta);
428
                Vec3 p1 = cur.interpolate(tickDelta);
429
430
                int col0 = trailPointColor(prev, i - 1, size, tickDelta, phaseBase);
431
                int col1 = trailPointColor(cur, i, size, tickDelta, phaseBase);
432
433
                int alpha0 = (int) (((col0 >>> 24) & 0xFF) * prev.animation(tickDelta));
434
                int alpha1 = (int) (((col1 >>> 24) & 0xFF) * cur.animation(tickDelta));
435
436
                int argb0 = withAlpha(col0, alpha0);
437
                int argb1 = withAlpha(col1, alpha1);
438
                addVerticalQuad(mesh, p0, p1, down, height, argb0, argb1);
439
                if (strokeMesh != null) {
440
                    int stroke0 = AnimatedRenderColors.scaleAlpha(argb0, trailStrokeAlpha.get());
441
                    int stroke1 = AnimatedRenderColors.scaleAlpha(argb1, trailStrokeAlpha.get());
442
                    addLine(strokeMesh, p0.x, p0.y + down, p0.z, p1.x, p1.y + down, p1.z, stroke0, stroke1);
443
                    addLine(strokeMesh, p0.x, p0.y + down + height, p0.z, p1.x, p1.y + down + height, p1.z, stroke0, stroke1);
444
                }
445
            }
446
        }
447
    }
448
449
    private void spawnWalkParticles(Player player, int colorIndex) {
450
        int count = particleWalkCount.get();
451
        if (count <= 0) return;
452
        for (int i = 0; i < count; i++) {
453
            spawnParticleAround(player, colorIndex, 0.5, 0.4, 0.1);
454
        }
455
    }
456
457
    private void spawnJumpParticles(Player player, int colorIndex) {
458
        int count = particleJumpCount.get();
459
        if (count <= 0) return;
460
        for (int i = 0; i < count; i++) {
461
            spawnParticleAround(player, colorIndex, 0.4, 0.1, 0.2);
462
        }
463
    }
464
465
    private void spawnProjectileParticles(int colorIndex) {
466
        if (mc.player == null) return;
467
        int count = particleProjectileCount.get();
468
        if (count <= 0) return;
469
470
        int spawned = 0;
471
        var box = mc.player.getBoundingBox().inflate(PROJECTILE_SCAN_RADIUS);
472
        List<Projectile> projectiles = mc.level.getEntitiesOfClass(
473
                Projectile.class,
474
                box,
475
                e -> true
476
        );
477
478
        for (Projectile p : projectiles) {
479
            if (p instanceof AbstractArrow persistent && isInGround(persistent)) {
480
                continue;
481
            }
482
            if (spawned >= PROJECTILE_MAX_SPAWN) break;
483
            for (int i = 0; i < count && spawned < PROJECTILE_MAX_SPAWN; i++) {
484
                spawnParticleAt(
485
                        p.getX() + random.nextDouble() * 0.6 - 0.3,
486
                        p.getY() + random.nextDouble() * Math.max(0.2, p.getBbHeight()),
487
                        p.getZ() + random.nextDouble() * 0.6 - 0.3,
488
                        colorIndex
489
                );
490
                spawned++;
491
            }
492
        }
493
    }
494
495
    private boolean isInGround(AbstractArrow projectile) {
496
        if (projectile == null) return false;
497
        try {
498
            return ((PersistentProjectileEntityAccessor) projectile).combatant$isInGround();
499
        } catch (Throwable t) {
500
            return false;
501
        }
502
    }
503
504
    private void spawnParticleAround(Player player, int colorIndex, double radius, double height, double motionScale) {
505
        double px = player.getX() + random.nextDouble() * radius - radius * 0.5;
506
        double py = player.getY() + random.nextDouble() * Math.max(0.1, height);
507
        double pz = player.getZ() + random.nextDouble() * radius - radius * 0.5;
508
        spawnParticleAt(px, py, pz, colorIndex, motionScale);
509
    }
510
511
    private void spawnParticleAt(double x, double y, double z, int colorIndex) {
512
        spawnParticleAt(x, y, z, colorIndex, 0.12);
513
    }
514
515
    private void spawnParticleAt(double x, double y, double z, int colorIndex, double motionScale) {
516
        if (extraParticles.size() >= PARTICLE_MAX) {
517
            extraParticles.remove(0);
518
        }
519
520
        double motion = 0.06 * motionScale;
521
        Vec3 vel = new Vec3(
522
                random.nextDouble() * motion * 2 - motion,
523
                random.nextDouble() * 0.03 - 0.015,
524
                random.nextDouble() * motion * 2 - motion
525
        );
526
527
        int color = particleRandomColor.get() ? randomColor() : getColorArgb(colorIndex);
528
        ParticleTexture tex = resolveParticleTexture();
529
        long life = particleLifeMs.get();
530
        long fadeIn = Math.min(200L, life / 4L);
531
        long fadeOut = Math.min(700L, life / 2L);
532
533
        extraParticles.add(new Particle3D(
534
                new Vec3(x, y, z),
535
                vel,
536
                life,
537
                fadeIn,
538
                fadeOut,
539
                particleSize.get(),
540
                color,
541
                tex.texture(),
542
                tex.index(),
543
                PARTICLE_SIMULATION.linearDrag(),
544
                PARTICLE_SIMULATION.gravity(),
545
                (random.nextFloat() - 0.5f) * 8f
546
        ));
547
    }
548
549
    private void renderExtraParticles(Renderer3D renderer, float tickDelta) {
550
        boolean useDepth = depthTest.get();
551
        RenderPipeline pipeline = useDepth
552
                ? CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE_LIQUID_IGNORE
553
                : CombatantRenderPipelines.WORLD_TEXTURED_ADDITIVE;
554
        Renderer3D.DepthMode depthMode = useDepth ? Renderer3D.DepthMode.PRE_DEPTH : Renderer3D.DepthMode.MAIN;
555
        Quaternionf camRot = RenderState.cameraRotation;
556
557
        if (particleTexture.get() == ParticleTextureMode.BLOOM) {
558
            MeshBuilder mesh = renderer.batchTextured(pipeline, TextureStorage.FIRE_FLY, depthMode);
559
            if (mesh == null) return;
560
            for (Particle3D p : extraParticles) {
561
                renderParticle(mesh, p, tickDelta, camRot);
562
            }
563
            return;
564
        }
565
566
        clearBuckets(particleBuckets);
567
        for (Particle3D p : extraParticles) {
568
            int idx = p.textureIndex();
569
            if (idx >= 0 && idx < particleBuckets.length) {
570
                particleBuckets[idx].add(p);
571
            }
572
        }
573
574
        for (int i = 0; i < particleBuckets.length; i++) {
575
            List<Particle3D> bucket = particleBuckets[i];
576
            if (bucket.isEmpty()) continue;
577
            MeshBuilder mesh = renderer.batchTextured(pipeline, TextureStorage.RANDOM_PARTICLES[i], depthMode);
578
            if (mesh == null) continue;
579
            for (Particle3D p : bucket) {
580
                renderParticle(mesh, p, tickDelta, camRot);
581
            }
582
        }
583
    }
584
585
    private void renderParticle(MeshBuilder mesh, Particle3D particle, float tickDelta, Quaternionf camRot) {
586
        Vec3 pos = particle.interpolate(tickDelta);
587
        float alpha = particle.alpha();
588
        if (alpha <= 0.01f) return;
589
        int argb = withAlpha(particle.color(), (int) (((particle.color() >>> 24) & 0xFF) * alpha));
590
        addBillboardQuad(mesh, pos.x, pos.y, pos.z, particle.size(), camRot, argb);
591
    }
592
593
    private int randomColor() {
594
        float h = random.nextFloat();
595
        float s = 0.7f + random.nextFloat() * 0.3f;
596
        float v = 0.8f + random.nextFloat() * 0.2f;
597
        return Color.HSBtoRGB(h, s, v) | 0xFF000000;
598
    }
599
600
    private ParticleTexture resolveParticleTexture() {
601
        if (particleTexture.get() == ParticleTextureMode.BLOOM) {
602
            return new ParticleTexture(TextureStorage.FIRE_FLY, -1);
603
        }
604
        int idx = random.nextInt(TextureStorage.RANDOM_PARTICLES.length);
605
        return new ParticleTexture(TextureStorage.RANDOM_PARTICLES[idx], idx);
606
    }
607
608
    private boolean usesSecondaryColor() {
609
        return AnimatedRenderColors.usesSecondary(animatedColorMode());
610
    }
611
612
    private boolean isTailMode() {
613
        return "Tail".equals(trailMode.get());
614
    }
615
616
    private boolean isTrailMode() {
617
        return "Trail".equals(trailMode.get());
618
    }
619
620
    private boolean isTrailDownVisible() {
621
        return isTrailMode();
622
    }
623
624
    private int getColorArgb(int count) {
625
        return AnimatedRenderColors.resolve(
626
                animatedColorMode(),
627
                colorSpeed.get(),
628
                count,
629
                colorValue.getArgb(),
630
                colorValue2.getArgb(),
631
                true
632
        );
633
    }
634
635
    private int currentColorPhase(float tickDelta) {
636
        if (mc.player == null) return colorPhase.get();
637
        return Math.round((mc.player.tickCount + tickDelta) * 4.0f) + colorPhase.get();
638
    }
639
640
    private int trailPointColor(TrailPoint point, int index, int size, float tickDelta, int phaseBase) {
641
        float position = size <= 1 ? 0.0f : index / (float) (size - 1);
642
        float age = 1.0f - point.animation(tickDelta);
643
        int phase = phaseBase
644
                + Math.round(position * colorLengthSpread.get())
645
                + Math.round(age * colorAgeSpread.get());
646
647
        int animated = getColorArgb(phase);
648
        if (animatedColorMode() == AnimatedRenderColors.Mode.STATIC) {
649
            animated = point.color();
650
        }
651
652
        float lift = (float) Math.pow(1.0f - position, 2.0f) * 0.45f;
653
        return AnimatedRenderColors.mixArgb(
654
                animated,
655
                (animated & 0xFF000000) | 0x00FFFFFF,
656
                lift
657
        );
658
    }
659
660
    private AnimatedRenderColors.Mode animatedColorMode() {
661
        return switch (colorMode.get()) {
662
            case "Rainbow" -> AnimatedRenderColors.Mode.RAINBOW;
663
            case "LightRainbow" -> AnimatedRenderColors.Mode.LIGHT_RAINBOW;
664
            case "Sky" -> AnimatedRenderColors.Mode.SKY;
665
            case "Fade" -> AnimatedRenderColors.Mode.FADE;
666
            case "DoubleColor" -> AnimatedRenderColors.Mode.DOUBLE_COLOR;
667
            case "Analogous" -> AnimatedRenderColors.Mode.ANALOGOUS;
668
            case "Theme" -> AnimatedRenderColors.Mode.THEME;
669
            default -> AnimatedRenderColors.Mode.STATIC;
670
        };
671
    }
672
673
    private record ParticleTexture(net.minecraft.resources.Identifier texture, int index) {
674
    }
675
676
    // textured rendering handled by Renderer3D batching
677
}
678