tracers module

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

6 implementationsRenderRENDERVISUALS

Full module source: 6 implementations

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

Meteor ClientRendersrc/main/java/meteordevelopment/meteorclient/systems/modules/render/Tracers.javaJava · 382 lines · 14.1 KB

Displays tracer lines to specified entities.

Settingsentitiesignore-selfignore-friendsshow-invisiblestyletargetstemmax-distancedistance-offscreensize-offscreenblink-offscreenblink-offscreen-speeddistance-colorsshow-friend-colorsplayers-colorsanimals-colorwater-animals-colormonsters-colorambient-colormisc-color
Tracers.javaJava · Minecraft 26.2 · 382 lines · 14.1 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
3
 * Copyright (c) Meteor Development.
4
 */
5
6
package meteordevelopment.meteorclient.systems.modules.render;
7
8
import meteordevelopment.meteorclient.events.render.Render2DEvent;
9
import meteordevelopment.meteorclient.events.render.Render3DEvent;
10
import meteordevelopment.meteorclient.renderer.Renderer2D;
11
import meteordevelopment.meteorclient.settings.*;
12
import meteordevelopment.meteorclient.systems.config.Config;
13
import meteordevelopment.meteorclient.systems.friends.Friends;
14
import meteordevelopment.meteorclient.systems.modules.Categories;
15
import meteordevelopment.meteorclient.systems.modules.Module;
16
import meteordevelopment.meteorclient.systems.modules.Modules;
17
import meteordevelopment.meteorclient.utils.entity.EntityUtils;
18
import meteordevelopment.meteorclient.utils.entity.Target;
19
import meteordevelopment.meteorclient.utils.player.PlayerUtils;
20
import meteordevelopment.meteorclient.utils.render.NametagUtils;
21
import meteordevelopment.meteorclient.utils.render.RenderUtils;
22
import meteordevelopment.meteorclient.utils.render.color.Color;
23
import meteordevelopment.meteorclient.utils.render.color.SettingColor;
24
import meteordevelopment.orbit.EventHandler;
25
import net.minecraft.world.entity.Entity;
26
import net.minecraft.world.entity.EntityType;
27
import net.minecraft.world.entity.EntityTypes;
28
import net.minecraft.world.entity.player.Player;
29
import net.minecraft.world.phys.Vec2;
30
import org.joml.Vector2f;
31
import org.joml.Vector3d;
32
33
import java.time.Duration;
34
import java.time.Instant;
35
import java.util.Set;
36
37
public class Tracers extends Module {
38
    private final SettingGroup sgGeneral = settings.getDefaultGroup();
39
    private final SettingGroup sgAppearance = settings.createGroup("Appearance");
40
    private final SettingGroup sgColors = settings.createGroup("Colors");
41
42
    public enum TracerStyle {
43
        Lines,
44
        Offscreen
45
    }
46
47
    // General
48
49
    private final Setting<Set<EntityType<?>>> entities = sgGeneral.add(new EntityTypeListSetting.Builder()
50
        .name("entities")
51
        .description("Select specific entities.")
52
        .defaultValue(EntityTypes.PLAYER)
53
        .build()
54
    );
55
56
    private final Setting<Boolean> ignoreSelf = sgGeneral.add(new BoolSetting.Builder()
57
        .name("ignore-self")
58
        .description("Doesn't draw tracers to yourself when in third person or freecam.")
59
        .defaultValue(false)
60
        .build()
61
    );
62
63
    public final Setting<Boolean> ignoreFriends = sgGeneral.add(new BoolSetting.Builder()
64
        .name("ignore-friends")
65
        .description("Doesn't draw tracers to friends.")
66
        .defaultValue(false)
67
        .build()
68
    );
69
70
    public final Setting<Boolean> showInvis = sgGeneral.add(new BoolSetting.Builder()
71
        .name("show-invisible")
72
        .description("Shows invisible entities.")
73
        .defaultValue(true)
74
        .build()
75
    );
76
77
    // Appearance
78
79
    private final Setting<TracerStyle> style = sgAppearance.add(new EnumSetting.Builder<TracerStyle>()
80
        .name("style")
81
        .description("What display mode should be used")
82
        .defaultValue(TracerStyle.Lines)
83
        .build()
84
    );
85
86
    private final Setting<Target> target = sgAppearance.add(new EnumSetting.Builder<Target>()
87
        .name("target")
88
        .description("What part of the entity to target.")
89
        .defaultValue(Target.Body)
90
        .visible(() -> style.get() == TracerStyle.Lines)
91
        .build()
92
    );
93
94
    private final Setting<Boolean> stem = sgAppearance.add(new BoolSetting.Builder()
95
        .name("stem")
96
        .description("Draw a line through the center of the tracer target.")
97
        .defaultValue(true)
98
        .visible(() -> style.get() == TracerStyle.Lines)
99
        .build()
100
    );
101
102
    private final Setting<Integer> maxDist = sgAppearance.add(new IntSetting.Builder()
103
        .name("max-distance")
104
        .description("Maximum distance for tracers to show.")
105
        .defaultValue(256)
106
        .min(0)
107
        .sliderMax(256)
108
        .build()
109
    );
110
111
    private final Setting<Integer> distanceOffscreen = sgAppearance.add(new IntSetting.Builder()
112
        .name("distance-offscreen")
113
        .description("Offscreen's distance from center.")
114
        .defaultValue(200)
115
        .min(0)
116
        .sliderMax(500)
117
        .visible(() -> style.get() == TracerStyle.Offscreen)
118
        .build()
119
    );
120
121
    private final Setting<Integer> sizeOffscreen = sgAppearance.add(new IntSetting.Builder()
122
        .name("size-offscreen")
123
        .description("Offscreen's size.")
124
        .defaultValue(10)
125
        .min(2)
126
        .sliderMax(50)
127
        .visible(() -> style.get() == TracerStyle.Offscreen)
128
        .build()
129
    );
130
131
    private final Setting<Boolean> blinkOffscreen = sgAppearance.add(new BoolSetting.Builder()
132
        .name("blink-offscreen")
133
        .description("Make offscreen Blink.")
134
        .defaultValue(true)
135
        .visible(() -> style.get() == TracerStyle.Offscreen)
136
        .build()
137
    );
138
139
    private final Setting<Double> blinkOffscreenSpeed = sgAppearance.add(new DoubleSetting.Builder()
140
        .name("blink-offscreen-speed")
141
        .description("Offscreen's blink speed.")
142
        .defaultValue(4)
143
        .min(1)
144
        .sliderMax(15)
145
        .visible(() -> style.get() == TracerStyle.Offscreen && blinkOffscreen.get())
146
        .build()
147
    );
148
149
    // Colors
150
151
    public final Setting<Boolean> distance = sgColors.add(new BoolSetting.Builder()
152
        .name("distance-colors")
153
        .description("Changes the color of tracers depending on distance.")
154
        .defaultValue(false)
155
        .build()
156
    );
157
158
    public final Setting<Boolean> friendOverride = sgColors.add(new BoolSetting.Builder()
159
        .name("show-friend-colors")
160
        .description("Whether or not to override the distance color of friends with the friend color.")
161
        .defaultValue(true)
162
        .visible(() -> distance.get() && !ignoreFriends.get())
163
        .build()
164
    );
165
166
    private final Setting<SettingColor> playersColor = sgColors.add(new ColorSetting.Builder()
167
        .name("players-colors")
168
        .description("The player's color.")
169
        .defaultValue(new SettingColor(205, 205, 205, 127))
170
        .visible(() -> !distance.get())
171
        .build()
172
    );
173
174
    private final Setting<SettingColor> animalsColor = sgColors.add(new ColorSetting.Builder()
175
        .name("animals-color")
176
        .description("The animal's color.")
177
        .defaultValue(new SettingColor(145, 255, 145, 127))
178
        .visible(() -> !distance.get())
179
        .build()
180
    );
181
182
    private final Setting<SettingColor> waterAnimalsColor = sgColors.add(new ColorSetting.Builder()
183
        .name("water-animals-color")
184
        .description("The water animal's color.")
185
        .defaultValue(new SettingColor(145, 145, 255, 127))
186
        .visible(() -> !distance.get())
187
        .build()
188
    );
189
190
    private final Setting<SettingColor> monstersColor = sgColors.add(new ColorSetting.Builder()
191
        .name("monsters-color")
192
        .description("The monster's color.")
193
        .defaultValue(new SettingColor(255, 145, 145, 127))
194
        .visible(() -> !distance.get())
195
        .build()
196
    );
197
198
    private final Setting<SettingColor> ambientColor = sgColors.add(new ColorSetting.Builder()
199
        .name("ambient-color")
200
        .description("The ambient color.")
201
        .defaultValue(new SettingColor(75, 75, 75, 127))
202
        .visible(() -> !distance.get())
203
        .build()
204
    );
205
206
    private final Setting<SettingColor> miscColor = sgColors.add(new ColorSetting.Builder()
207
        .name("misc-color")
208
        .description("The misc color.")
209
        .defaultValue(new SettingColor(145, 145, 145, 127))
210
        .visible(() -> !distance.get())
211
        .build()
212
    );
213
214
    private int count;
215
    private final Instant initTimer = Instant.now();
216
217
    public Tracers() {
218
        super(Categories.Render, "tracers", "Displays tracer lines to specified entities.");
219
    }
220
221
    private boolean shouldBeIgnored(Entity entity) {
222
        return !PlayerUtils.isWithin(entity, maxDist.get()) || (!Modules.get().isActive(Freecam.class) && entity == mc.player) || !entities.get().contains(entity.getType()) || (ignoreSelf.get() && entity == mc.player) || (ignoreFriends.get() && entity instanceof Player player && Friends.get().isFriend(player)) || (!showInvis.get() && entity.isInvisible()) || !EntityUtils.isInRenderDistance(entity);
223
    }
224
225
    private Color getEntityColor(Entity entity) {
226
        Color color;
227
228
        if (distance.get()) {
229
            if (friendOverride.get() && entity instanceof Player player && Friends.get().isFriend(player)) {
230
                color = Config.get().friendColor.get();
231
            } else color = EntityUtils.getColorFromDistance(entity);
232
        } else if (entity instanceof Player player) {
233
            color = PlayerUtils.getPlayerColor(player, playersColor.get());
234
        } else {
235
            color = switch (entity.getType().getCategory()) {
236
                case CREATURE -> animalsColor.get();
237
                case WATER_AMBIENT, WATER_CREATURE, UNDERGROUND_WATER_CREATURE, AXOLOTLS -> waterAnimalsColor.get();
238
                case MONSTER -> monstersColor.get();
239
                case AMBIENT -> ambientColor.get();
240
                default -> miscColor.get();
241
            };
242
        }
243
244
        return new Color(color);
245
    }
246
247
    @EventHandler
248
    private void onRender(Render3DEvent event) {
249
        if (mc.gameRenderer.gameRenderState().guiRenderState.isHudHidden || style.get() == TracerStyle.Offscreen)
250
            return;
251
        count = 0;
252
253
        for (Entity entity : mc.level.entitiesForRendering()) {
254
            if (shouldBeIgnored(entity)) continue;
255
256
            Color color = getEntityColor(entity);
257
258
            double x = entity.xo + (entity.getX() - entity.xo) * event.tickDelta;
259
            double y = entity.yo + (entity.getY() - entity.yo) * event.tickDelta;
260
            double z = entity.zo + (entity.getZ() - entity.zo) * event.tickDelta;
261
262
            double height = entity.getBoundingBox().maxY - entity.getBoundingBox().minY;
263
            if (target.get() == Target.Head) y += height;
264
            else if (target.get() == Target.Body) y += height / 2;
265
266
            event.renderer.line(RenderUtils.center.x, RenderUtils.center.y, RenderUtils.center.z, x, y, z, color);
267
            if (stem.get()) event.renderer.line(x, entity.getY(), z, x, entity.getY() + height, z, color);
268
269
            count++;
270
        }
271
    }
272
273
    @EventHandler
274
    public void onRender2D(Render2DEvent event) {
275
        if (mc.gameRenderer.gameRenderState().guiRenderState.isHudHidden || style.get() != TracerStyle.Offscreen)
276
            return;
277
        count = 0;
278
279
        Renderer2D.COLOR.begin();
280
281
        for (Entity entity : mc.level.entitiesForRendering()) {
282
            if (shouldBeIgnored(entity)) continue;
283
284
            Color color = getEntityColor(entity);
285
286
            if (blinkOffscreen.get())
287
                color.a = (int) (color.a * getAlpha());
288
289
            Vec2 screenCenter = new Vec2(mc.getWindow().getWidth() / 2.f, mc.getWindow().getHeight() / 2.f);
290
291
            Vector3d projection = new Vector3d(entity.xo, entity.yo, entity.zo);
292
            boolean projSucceeded = NametagUtils.to2D(projection, 1, false, false);
293
294
            if (projSucceeded && projection.x > 0.f && projection.x < mc.getWindow().getWidth() && projection.y > 0.f && projection.y < mc.getWindow().getHeight())
295
                continue;
296
297
            projection = new Vector3d(entity.xo, entity.yo, entity.zo);
298
            NametagUtils.to2D(projection, 1, false, true);
299
300
            Vector2f angle = vectorAngles(new Vector3d(screenCenter.x - projection.x, screenCenter.y - projection.y, 0));
301
            angle.y += 180;
302
303
            float angleYawRad = (float) Math.toRadians(angle.y);
304
305
            Vector2f newPoint = new Vector2f(
306
                screenCenter.x + distanceOffscreen.get() * (float) Math.cos(angleYawRad),
307
                screenCenter.y + distanceOffscreen.get() * (float) Math.sin(angleYawRad)
308
            );
309
310
            Vector2f[] trianglePoints = {
311
                new Vector2f(newPoint.x - sizeOffscreen.get(), newPoint.y - sizeOffscreen.get()),
312
                new Vector2f(newPoint.x + sizeOffscreen.get() * 0.73205f, newPoint.y),
313
                new Vector2f(newPoint.x - sizeOffscreen.get(), newPoint.y + sizeOffscreen.get())
314
            };
315
316
            rotateTriangle(trianglePoints, angle.y);
317
318
            Renderer2D.COLOR.triangle(
319
                trianglePoints[2].x, trianglePoints[2].y,
320
                trianglePoints[1].x, trianglePoints[1].y,
321
                trianglePoints[0].x, trianglePoints[0].y,
322
                color
323
            );
324
325
            count++;
326
        }
327
328
        Renderer2D.COLOR.render();
329
    }
330
331
    private void rotateTriangle(Vector2f[] points, float ang) {
332
        Vector2f triangleCenter = new Vector2f(0, 0);
333
        triangleCenter.add(points[0]).add(points[1]).add(points[2]).div(3.f);
334
        float theta = (float) Math.toRadians(ang);
335
        float cos = (float) Math.cos(theta);
336
        float sin = (float) Math.sin(theta);
337
        for (int i = 0; i < 3; i++) {
338
            Vector2f point = new Vector2f(points[i].x, points[i].y).sub(triangleCenter);
339
340
            Vector2f newPoint = new Vector2f(point.x * cos - point.y * sin, point.x * sin + point.y * cos);
341
            newPoint.add(triangleCenter);
342
343
            points[i] = newPoint;
344
        }
345
    }
346
347
    private Vector2f vectorAngles(final Vector3d forward) {
348
        float tmp, yaw, pitch;
349
350
        if (forward.x == 0 && forward.y == 0) {
351
            yaw = 0;
352
            if (forward.z > 0)
353
                pitch = 270;
354
            else
355
                pitch = 90;
356
        } else {
357
            yaw = (float) (Math.atan2(forward.y, forward.x) * 180 / Math.PI);
358
            if (yaw < 0)
359
                yaw += 360;
360
361
            tmp = (float) Math.sqrt(forward.x * forward.x + forward.y * forward.y);
362
            pitch = (float) (Math.atan2(-forward.z, tmp) * 180 / Math.PI);
363
            if (pitch < 0)
364
                pitch += 360;
365
        }
366
367
        return new Vector2f(pitch, yaw);
368
    }
369
370
    private float getAlpha() {
371
        double speed = blinkOffscreenSpeed.get() / 4.0;
372
        double duration = Math.abs(Duration.between(Instant.now(), initTimer).toMillis()) * speed;
373
374
        return (float) Math.abs((duration % 1000) - 500) / 500.f;
375
    }
376
377
    @Override
378
    public String getInfoString() {
379
        return Integer.toString(count);
380
    }
381
}
382
MelaHack (ThunderHack fork)RENDERsrc/main/java/thunder/hack/features/modules/render/Tracers.javaJava · 50 lines · 2.2 KB

Draws lines to the players.

SettingsHeightColorFriends
Tracers.javaJava · Minecraft 26.2 · 50 lines · 2.2 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 net.minecraft.world.entity.player.Player;
11
import net.minecraft.world.phys.Vec3;
12
13
public class Tracers extends Module {
14
    public Tracers() {
15
        super("Tracers", Category.RENDER);
16
    }
17
18
    private final Setting<Float> height = new Setting<>("Height", 0f, 0f, 2f);
19
20
    private final Setting<ColorSetting> color = new Setting<>("Color", new ColorSetting(new Color(0x93FF0000, true)));
21
    private final Setting<ColorSetting> friendColor = new Setting<>("Friends", new ColorSetting(new Color(0x9317DE5D, true)));
22
23
    public void onRender3D(PoseStack stack) {
24
        for (Player player : Managers.ASYNC.getAsyncPlayers()) {
25
            if (player == mc.player)
26
                continue;
27
28
            Color color1 = color.getValue().getColorObject();
29
30
            if (Managers.FRIEND.isFriend(player))
31
                color1 = friendColor.getValue().getColorObject();
32
33
            double x1 = mc.player.xo + (mc.player.getX() - mc.player.xo) * Render3DEngine.getTickDelta();
34
            double y1 = mc.player.getEyeHeight(mc.player.getPose()) + mc.player.yo + (mc.player.getY() - mc.player.yo) * Render3DEngine.getTickDelta();
35
            double z1 = mc.player.zo + (mc.player.getZ() - mc.player.zo) * Render3DEngine.getTickDelta();
36
37
            Vec3 vec2 = new Vec3(0, 0, 75)
38
                    .xRot(-(float) Math.toRadians(mc.gameRenderer.mainCamera().xRot()))
39
                    .yRot(-(float) Math.toRadians(mc.gameRenderer.mainCamera().yRot()))
40
                    .add(x1, y1, z1);
41
42
            double x = player.xo + (player.getX() - player.xo) * Render3DEngine.getTickDelta();
43
            double y = player.yo + (player.getY() - player.yo) * Render3DEngine.getTickDelta();
44
            double z = player.zo + (player.getZ() - player.zo) * Render3DEngine.getTickDelta();
45
46
            Render3DEngine.drawLineDebug(vec2, new Vec3(x, y + height.getValue(), z), color1);
47
        }
48
    }
49
}
50
OfflineClientRENDERsrc/main/java/com/jellypudding/offlineclient/modules/render/Tracers.javaJava · 200 lines · 8.8 KB

Draws lines from you to entities around you.

SettingsStyleTargetStemNamesArrow distanceArrow sizeBlinkBlink speedMax distanceSelf in FreecamIgnore friendsShow invisible
Tracers.javaJava · Minecraft 26.2 · 200 lines · 8.8 KB · complete file, verbatimOriginal ↗
1
package com.jellypudding.offlineclient.modules.render;
2
3
import com.jellypudding.offlineclient.event.Subscribe;
4
import com.jellypudding.offlineclient.event.events.Render2DEvent;
5
import com.jellypudding.offlineclient.event.events.Render3DEvent;
6
import com.jellypudding.offlineclient.module.Category;
7
import com.jellypudding.offlineclient.module.Module;
8
import com.jellypudding.offlineclient.render.DrawBatch;
9
import com.jellypudding.offlineclient.render.WorldToScreen;
10
import com.jellypudding.offlineclient.setting.BoolSetting;
11
import com.jellypudding.offlineclient.setting.EnumSetting;
12
import com.jellypudding.offlineclient.setting.NumberSetting;
13
import com.jellypudding.offlineclient.util.ColorUtil;
14
import com.jellypudding.offlineclient.util.EntityColors;
15
import com.jellypudding.offlineclient.util.EntityFilter;
16
import com.jellypudding.offlineclient.util.EntityUtil;
17
import com.jellypudding.offlineclient.util.Modules;
18
import com.jellypudding.offlineclient.util.RenderUtil;
19
import net.minecraft.client.gui.Font;
20
import net.minecraft.client.gui.GuiGraphicsExtractor;
21
import net.minecraft.world.entity.Entity;
22
import net.minecraft.world.entity.player.Player;
23
import net.minecraft.world.phys.AABB;
24
import net.minecraft.world.phys.Vec3;
25
26
import java.util.List;
27
28
public final class Tracers extends Module {
29
30
    public enum Style { LINES, OFFSCREEN }
31
32
    public enum Target { HEAD, BODY, FEET }
33
34
    private final EnumSetting<Style> style = new EnumSetting<>("Style", "How entities are pointed out.", Style.LINES)
35
        .describe(Style.LINES, "A line from you to each entity.")
36
        .describe(Style.OFFSCREEN, "An arrow on a ring round the screen centre for each entity out of view.");
37
    private final EnumSetting<Target> target = new EnumSetting<>("Target",
38
        "Where on the entity the line ends.", Target.BODY)
39
        .describe(Target.HEAD, "The top of the entity.")
40
        .describe(Target.BODY, "The middle of the entity.")
41
        .describe(Target.FEET, "The bottom of the entity.")
42
        .under(style, Style.LINES);
43
    private final BoolSetting stem = new BoolSetting("Stem",
44
        "Also draw a line from the entity's feet to its head.", true).under(style, Style.LINES);
45
    private final BoolSetting names = new BoolSetting("Names",
46
        "Show the player's name where their tracer ends.", true).under(style, Style.LINES);
47
    private final NumberSetting arrowDistance = new NumberSetting("Arrow distance",
48
        "Radius in pixels of the ring the arrows sit on.", 200, 0, 500, 10, " px").under(style, Style.OFFSCREEN);
49
    private final NumberSetting arrowSize = new NumberSetting("Arrow size",
50
        "Size of each arrow in pixels.", 10, 2, 50, 1, " px").under(style, Style.OFFSCREEN);
51
    private final BoolSetting blink = new BoolSetting("Blink",
52
        "Arrows pulse in and out.", true).under(style, Style.OFFSCREEN);
53
    private final NumberSetting blinkSpeed = new NumberSetting("Blink speed",
54
        "How fast the arrows pulse.", 4, 1, 15, 0.5)
55
        .under(blink, () -> style.is(Style.OFFSCREEN) && blink.isOn());
56
    private final EntityFilter filter = new EntityFilter("Draw lines to", "given a line", true,
57
        EntityFilter.Pick.NONE, EntityFilter.Pick.NONE, List.of());
58
    private final NumberSetting maxDistance = new NumberSetting("Max distance",
59
        "Entities further away than this get nothing.", 256, 0, 256, 8, " blocks").min(0);
60
    private final BoolSetting selfInFreecam = new BoolSetting("Self in Freecam",
61
        "Point to your own body whilst Freecam is on.", true);
62
    private final BoolSetting ignoreFriends = new BoolSetting("Ignore friends",
63
        "Friends get nothing.", false);
64
    private final BoolSetting showInvisible = new BoolSetting("Show invisible",
65
        "Invisible entities get a line too.", true);
66
    private final EntityColors colors = new EntityColors(EntityColors.Mode.DISTANCE);
67
68
    public Tracers() {
69
        super("Tracers", "Draws lines from you to entities around you.", Category.RENDER);
70
        addSettings(style, target, stem, names, arrowDistance, arrowSize, blink, blinkSpeed);
71
        addSettings(filter.settings());
72
        addSettings(maxDistance, selfInFreecam, ignoreFriends, showInvisible);
73
        addSettings(colors.settings());
74
    }
75
76
    private boolean wanted(Entity entity) {
77
        if (entity == mc.player) {
78
            if (!selfInFreecam.isOn() || !filter.wantsPlayers() || !Modules.enabled(Freecam.class)) {
79
                return false;
80
            }
81
        } else if (!filter.matches(entity)) {
82
            return false;
83
        }
84
        if (ignoreFriends.isOn() && EntityUtil.isFriend(entity)) {
85
            return false;
86
        }
87
        if (!showInvisible.isOn() && entity.isInvisible()) {
88
            return false;
89
        }
90
        return mc.player.distanceTo(entity) <= maxDistance.getValue();
91
    }
92
93
    private Vec3 endOf(AABB box) {
94
        double x = (box.minX + box.maxX) / 2;
95
        double z = (box.minZ + box.maxZ) / 2;
96
        return switch (target.getValue()) {
97
            case HEAD -> new Vec3(x, box.maxY, z);
98
            case BODY -> new Vec3(x, (box.minY + box.maxY) / 2, z);
99
            case FEET -> new Vec3(x, box.minY, z);
100
        };
101
    }
102
103
    @Subscribe
104
    private void onRender3D(Render3DEvent event) {
105
        if (!inGame() || !style.is(Style.LINES)) {
106
            return;
107
        }
108
        DrawBatch batch = event.getBatch();
109
        for (Entity entity : mc.level.entitiesForRendering()) {
110
            if (!wanted(entity)) {
111
                continue;
112
            }
113
            AABB box = EntityUtil.lerpedBox(entity, event.getPartialTicks());
114
            int color = colors.colorOf(entity);
115
            batch.tracer(endOf(box), color, true);
116
            if (stem.isOn()) {
117
                double x = (box.minX + box.maxX) / 2;
118
                double z = (box.minZ + box.maxZ) / 2;
119
                batch.line(new Vec3(x, box.minY, z), new Vec3(x, box.maxY, z), color, true);
120
            }
121
        }
122
    }
123
124
    @Subscribe
125
    private void onRender2D(Render2DEvent event) {
126
        if (!inGame() || !WorldToScreen.update()) {
127
            return;
128
        }
129
        if (style.is(Style.OFFSCREEN)) {
130
            drawArrows(event);
131
        } else if (names.isOn() && filter.wantsPlayers()) {
132
            drawNames(event);
133
        }
134
    }
135
136
    private void drawNames(Render2DEvent event) {
137
        Font font = mc.font;
138
        for (Entity entity : mc.level.entitiesForRendering()) {
139
            if (!(entity instanceof Player player) || !wanted(entity)) {
140
                continue;
141
            }
142
            Vec3 screen = WorldToScreen.project(endOf(EntityUtil.lerpedBox(entity, event.getPartialTicks())));
143
            if (screen == null) {
144
                continue;
145
            }
146
            String name = EntityUtil.displayNameOf(player);
147
            GuiGraphicsExtractor context = event.getContext();
148
            context.guiRenderState.up();
149
            context.text(font, name, (int) screen.x - font.width(name) / 2,
150
                (int) screen.y - 4, colors.colorOf(entity), true);
151
        }
152
    }
153
154
    // A pulse from a quarter to full strength.
155
    private float blinkStrength() {
156
        if (!blink.isOn()) {
157
            return 1;
158
        }
159
        double wave = Math.sin(System.currentTimeMillis() / 1000.0 * blinkSpeed.getValue());
160
        return (float) (0.625 + 0.375 * wave);
161
    }
162
163
    private void drawArrows(Render2DEvent event) {
164
        GuiGraphicsExtractor context = event.getContext();
165
        double centreX = mc.getWindow().getGuiScaledWidth() / 2.0;
166
        double centreY = mc.getWindow().getGuiScaledHeight() / 2.0;
167
        float strength = blinkStrength();
168
        context.guiRenderState.up();
169
        for (Entity entity : mc.level.entitiesForRendering()) {
170
            if (!wanted(entity)) {
171
                continue;
172
            }
173
            Vec3 middle = EntityUtil.lerpedBox(entity, event.getPartialTicks()).getCenter();
174
            if (WorldToScreen.onScreen(middle)) {
175
                continue;
176
            }
177
            Vec3 direction = WorldToScreen.directionTo(middle);
178
            drawArrow(context, centreX + direction.x * arrowDistance.getValue(),
179
                centreY + direction.y * arrowDistance.getValue(), direction,
180
                ColorUtil.fade(colors.colorOf(entity), strength));
181
        }
182
    }
183
184
    // A triangle pointing along the direction with its tip furthest from the centre.
185
    private void drawArrow(GuiGraphicsExtractor context, double x, double y, Vec3 direction, int color) {
186
        double size = arrowSize.getValue();
187
        double dx = direction.x;
188
        double dy = direction.y;
189
        // The tip leads and the two tail corners sit back and to either side.
190
        double tipX = x + dx * size;
191
        double tipY = y + dy * size;
192
        double backX = x - dx * size;
193
        double backY = y - dy * size;
194
        double sideX = -dy * size;
195
        double sideY = dx * size;
196
        RenderUtil.triangle(context, tipX, tipY, backX + sideX, backY + sideY,
197
            backX - sideX, backY - sideY, color);
198
    }
199
}
200
CombatantVISUALSsrc/main/java/combatant/client/features/module/modules/visuals/Tracers.javaJava · 364 lines · 15.3 KB
SettingstracersTraceFriendstracersModetracersMoveRadiusBonustracersArrowTexturetracersArrowRadiustracersArrowSize
Tracers.javaJava · Minecraft 26.2 · 364 lines · 15.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.textures.GpuSampler;
11
import com.mojang.blaze3d.textures.GpuTextureView;
12
import combatant.client.features.module.*;
13
import combatant.client.features.module.Module;
14
import combatant.client.util.screen.ClientScreen;
15
import net.minecraft.client.Minecraft;
16
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
17
import net.minecraft.client.renderer.texture.AbstractTexture;
18
import net.minecraft.resources.Identifier;
19
import net.minecraft.util.Mth;
20
import net.minecraft.world.entity.Entity;
21
import net.minecraft.world.entity.player.Player;
22
import net.minecraft.world.phys.Vec2;
23
import net.minecraft.world.phys.Vec3;
24
import org.joml.Matrix4f;
25
import combatant.client.config.values.BooleanValue;
26
import combatant.client.config.values.ModeValue;
27
import combatant.client.config.values.NumberValue;
28
import combatant.client.features.module.*;
29
import combatant.client.features.relations.CategoryService;
30
import combatant.client.mixininterface.IEntity;
31
import combatant.client.render.engine.animation.AnimationUtility;
32
import combatant.client.render.engine.color.RenderColor;
33
import combatant.client.render.engine.core.ViewportContext;
34
import combatant.client.render.engine.pipeline.CombatantRenderPipelines;
35
import combatant.client.render.engine.renderer.MeshRenderer;
36
import combatant.client.render.engine.renderer.Renderer2D;
37
import combatant.client.render.engine.renderer.Renderer3D;
38
import combatant.client.render.engine.text.TextRenderer;
39
import combatant.client.render.engine.uniform.MeshBuilder;
40
41
import java.util.List;
42
43
//todo Description
44
@ModuleInfo(id = "tracers", displayName = "Tracers", aliases = {"arrows", "lines"}, category = ModuleCategory.VISUALS)
45
public class Tracers extends Module {
46
47
    private static final String SETTING_TRACE_FRIENDS = "trace_friends";
48
    private static final String SETTING_MOVE_RADIUS_BONUS = "move_radius_bonus";
49
    private static final String SETTING_MODE = "mode";
50
    private static final String SETTING_ARROW_TEXTURE = "arrow_texture";
51
    private static final String SETTING_ARROW_RADIUS = "arrow_radius";
52
    private static final String SETTING_ARROW_SIZE = "arrow_size";
53
    private static final Identifier ARROW_1 = Identifier.fromNamespaceAndPath("combatant", "textures/hud/elements/arrow.png");
54
    private static final Identifier ARROW_2 = Identifier.fromNamespaceAndPath("combatant", "textures/hud/elements/arrow2.png");
55
    private static final Identifier ARROW_3 = Identifier.fromNamespaceAndPath("combatant", "textures/hud/elements/arrow3.png");
56
    private static final Identifier ARROW_4 = Identifier.fromNamespaceAndPath("combatant", "textures/hud/elements/arrow4.png");
57
    private static final float BASE_RADIUS = 48.0f;
58
    private static final float INVENTORY_RADIUS_BONUS = 50.0f;
59
    private static final float MOVE_RADIUS_BONUS = 1.5f;
60
    private static final float ARROW_W = 10.0f;
61
    private static final float ARROW_H = 10.0f;
62
    private static final float ARROW_OFFSET_X = -5.0f;
63
    private static final float ARROW_OFFSET_Y = -6.0f;
64
    private static final int ARROW_ALPHA = 235;
65
    private static final float ARROW_ROTATION_OFFSET_DEG = 90.0f;
66
    private static final float ARROW_DISTANCE_NEAR = 6.0f;
67
    private static final float ARROW_DISTANCE_FAR = 60.0f;
68
    private static final float ARROW_RADIUS_MIN_FACTOR = 0.55f;
69
    private static final float ARROW_RADIUS_MAX_FACTOR = 1.0f;
70
    private static final MeshBuilder ARROW_MESH =
71
            new MeshBuilder(CombatantRenderPipelines.UI_TEXTURED_ADDITIVE_TRANSFORMED);
72
    private final Minecraft mc = Minecraft.getInstance();
73
    private final BooleanValue traceFriendsValue = bool("tracersTraceFriends", SETTING_TRACE_FRIENDS, false);
74
    private final ModeValue tracersMode =
75
            modeSetting("tracersMode", SETTING_MODE, "Lines", "Lines", "Arrows");
76
    private final BooleanValue moveRadiusBonusValue =
77
            visibleWhen(bool("tracersMoveRadiusBonus", SETTING_MOVE_RADIUS_BONUS, false), this::isArrowsMode);
78
    private final ModeValue arrowTexture =
79
            visibleWhen(modeSetting("tracersArrowTexture", SETTING_ARROW_TEXTURE, "Arrow", "Arrow", "Arrow2", "Arrow3", "Arrow4"),
80
                    this::isArrowsMode);
81
    private final NumberValue<Float> arrowRadius =
82
            visibleWhen(num("tracersArrowRadius", SETTING_ARROW_RADIUS, BASE_RADIUS, 20.0f, 140.0f), this::isArrowsMode);
83
    private final NumberValue<Float> arrowSize =
84
            visibleWhen(num("tracersArrowSize", SETTING_ARROW_SIZE, 1.0f, 0.5f, 2.0f), this::isArrowsMode);
85
    private float animationStep;
86
    private float animatedYaw;
87
    private float animatedPitch;
88
    private float yaw;
89
90
    private static boolean isMoving(Vec2 move) {
91
        if (move == null) return false;
92
        return move.x != 0.0f || move.y != 0.0f;
93
    }
94
95
    private static boolean isNameValid(String name) {
96
        if (name == null) return false;
97
        int len = name.length();
98
        if (len < 3 || len > 16) return false;
99
        for (int i = 0; i < len; i++) {
100
            char c = name.charAt(i);
101
            if (c == '_') continue;
102
            if (!Character.isLetterOrDigit(c)) return false;
103
        }
104
        return true;
105
    }
106
107
    private static int withAlpha(int argb, int alpha) {
108
        int a = Mth.clamp(alpha, 0, 255);
109
        return (argb & 0x00FFFFFF) | (a << 24);
110
    }
111
112
    private static float radiusFactorForDistance(double distance) {
113
        if (distance <= ARROW_DISTANCE_NEAR) return ARROW_RADIUS_MIN_FACTOR;
114
        if (distance >= ARROW_DISTANCE_FAR) return ARROW_RADIUS_MAX_FACTOR;
115
        float t = (float) ((distance - ARROW_DISTANCE_NEAR) / (ARROW_DISTANCE_FAR - ARROW_DISTANCE_NEAR));
116
        t = Mth.clamp(t, 0.0f, 1.0f);
117
        return Mth.lerp(t, ARROW_RADIUS_MIN_FACTOR, ARROW_RADIUS_MAX_FACTOR);
118
    }
119
120
    private static void renderArrow(Identifier textureId,
121
                                    double x,
122
                                    double y,
123
                                    float angleRad,
124
                                    int argb,
125
                                    float scale) {
126
        if (textureId == null) return;
127
        Renderer2D.deferRenderThreadAction(() -> renderArrowImmediate(textureId, x, y, angleRad, argb, scale));
128
    }
129
130
    private static void renderArrowImmediate(Identifier textureId,
131
                                             double x,
132
                                             double y,
133
                                             float angleRad,
134
                                             int argb,
135
                                             float scale) {
136
        Minecraft mc = Minecraft.getInstance();
137
        if (mc == null || mc.gameRenderer == null || mc.gameRenderer.mainRenderTarget() == null) return;
138
        AbstractTexture tex = mc.getTextureManager().getTexture(textureId);
139
        if (tex == null) return;
140
        GpuTextureView view = tex.getTextureView();
141
        GpuSampler sampler = tex.getSampler();
142
        if (view == null || sampler == null) return;
143
144
        RenderColor c = new RenderColor(argb);
145
        ARROW_MESH.begin();
146
        ARROW_MESH.ensureQuadCapacity();
147
        int i1 = ARROW_MESH.vec2(ARROW_OFFSET_X * scale, ARROW_OFFSET_Y * scale)
148
                .vec2(0, 0).color(c.r, c.g, c.b, c.a).next();
149
        int i2 = ARROW_MESH.vec2(ARROW_OFFSET_X * scale, (ARROW_OFFSET_Y + ARROW_H) * scale)
150
                .vec2(0, 1).color(c.r, c.g, c.b, c.a).next();
151
        int i3 = ARROW_MESH.vec2((ARROW_OFFSET_X + ARROW_W) * scale, (ARROW_OFFSET_Y + ARROW_H) * scale)
152
                .vec2(1, 1).color(c.r, c.g, c.b, c.a).next();
153
        int i4 = ARROW_MESH.vec2((ARROW_OFFSET_X + ARROW_W) * scale, ARROW_OFFSET_Y * scale)
154
                .vec2(1, 0).color(c.r, c.g, c.b, c.a).next();
155
        ARROW_MESH.quad(i1, i2, i3, i4);
156
        ARROW_MESH.end();
157
158
        Matrix4f transform = new Matrix4f()
159
                .translation((float) x, (float) y, 0.0f)
160
                .rotateZ(angleRad);
161
162
        MeshRenderer.begin()
163
                .attachments(mc.gameRenderer.mainRenderTarget())
164
                .pipeline(CombatantRenderPipelines.UI_TEXTURED_ADDITIVE_TRANSFORMED)
165
                .mesh(ARROW_MESH)
166
                .transform(transform)
167
                .sampler("u_Texture", view, sampler)
168
                .end();
169
    }
170
171
    @Override
172
    public WorldPhase getWorldPhase() {
173
        return WorldPhase.END_MAIN;
174
    }
175
176
    @Override
177
    public HudPhase getHudPhase() {
178
        return HudPhase.BEFORE_HOTBAR;
179
    }
180
181
    @Override
182
    public void onRenderWorldEngine(Renderer3D renderer, Renderer3D depthRenderer, float tickDelta) {
183
        if (!isEnabled() || mc.level == null || mc.player == null) return;
184
        if (!isLinesMode()) return;
185
186
        Vec3 camPos = getActiveCameraPos(tickDelta);
187
        Vec3 look = getActiveCameraLook(tickDelta);
188
        Vec3 start = camPos.add(look.scale(10.0));
189
190
        for (Player p : mc.level.players()) {
191
            if (p == mc.player) continue;
192
            if (!traceFriendsValue.get() && CategoryService.isFriend(p)) continue;
193
194
            int c = resolveColor(p);
195
            Vec3 targetWorld = obtainEntityLerpedPos(p, tickDelta);
196
197
            renderer.line(
198
                    start.x, start.y, start.z,
199
                    targetWorld.x, targetWorld.y, targetWorld.z,
200
                    (c >> 16) & 255,
201
                    (c >> 8) & 255,
202
                    c & 255,
203
                    (c >> 24) & 255
204
            );
205
        }
206
    }
207
208
    @Override
209
    public void onRenderHudEngineForeground(Renderer2D renderer, TextRenderer textRenderer, net.minecraft.client.gui.GuiGraphicsExtractor ctx, float tickDelta) {
210
        if (!isEnabled() || mc.level == null || mc.player == null) return;
211
        if (!isArrowsMode()) return;
212
        if (!mc.options.getCameraType().isFirstPerson()) return;
213
214
        Vec2 move = mc.player.input != null ? mc.player.input.getMoveVector() : Vec2.ZERO;
215
        float moveX = move.x;
216
        float moveZ = move.y;
217
218
        float scale = ViewportContext.getScaleFactor();
219
        float moveScale = moveRadiusBonusValue.get() ? 10.0f : 0.0f;
220
        animatedYaw = AnimationUtility.fast(animatedYaw, moveX * moveScale * scale, 5.0f);
221
        animatedPitch = AnimationUtility.fast(animatedPitch, moveZ * moveScale * scale, 5.0f);
222
223
        yaw = AnimationUtility.fast(yaw, getActiveCameraYaw(), 10.0f);
224
225
        float size = arrowRadius.get();
226
        if (ClientScreen.current() instanceof InventoryScreen) {
227
            size += INVENTORY_RADIUS_BONUS;
228
        }
229
        if (moveRadiusBonusValue.get() && isMoving(move)) {
230
            size += MOVE_RADIUS_BONUS;
231
        }
232
        animationStep = AnimationUtility.fast(animationStep, size * scale, 6.0f);
233
234
        double centerX = mc.getWindow().getWidth() * 0.5;
235
        double centerY = mc.getWindow().getHeight() * 0.5;
236
237
        Vec3 camPos = getActiveCameraPos(tickDelta);
238
        Identifier textureId = resolveArrowTexture();
239
        for (Player player : mc.level.players()) {
240
            if (player == mc.player) continue;
241
            if (!traceFriendsValue.get() && CategoryService.isFriend(player)) continue;
242
243
            Vec3 targetWorld = obtainEntityLerpedPos(player, tickDelta);
244
            double relX = targetWorld.x - camPos.x;
245
            double relZ = targetWorld.z - camPos.z;
246
247
            double yawRad = Math.toRadians(yaw);
248
            double cos = Math.cos(yawRad);
249
            double sin = Math.sin(yawRad);
250
            double rotY = -(relZ * cos - relX * sin);
251
            double rotX = -(relX * cos + relZ * sin);
252
            float angleDeg = (float) Math.toDegrees(Math.atan2(rotY, rotX));
253
254
            double dist = targetWorld.distanceTo(camPos);
255
            float radiusFactor = shouldUseAdaptiveRadius() ? radiusFactorForDistance(dist) : 1.0f;
256
            double radius = animationStep * radiusFactor;
257
            double x2 = radius * Mth.cos((float) Math.toRadians(angleDeg)) + centerX + animatedYaw;
258
            double y2 = radius * Mth.sin((float) Math.toRadians(angleDeg)) + centerY + animatedPitch;
259
260
            int color = withAlpha(resolveColor(player), ARROW_ALPHA);
261
            float rotRad = (float) Math.toRadians(angleDeg + ARROW_ROTATION_OFFSET_DEG);
262
            renderArrow(textureId, x2, y2, rotRad, color, scale * arrowSize.get());
263
        }
264
    }
265
266
    private Vec3 getActiveCameraPos(float tickDelta) {
267
        Freecam fc = Modules.get(Freecam.class);
268
        if (fc != null && fc.isEnabled()) {
269
            return new Vec3(
270
                    Mth.lerp(tickDelta, fc.camPosPrev.x, fc.camPos.x),
271
                    Mth.lerp(tickDelta, fc.camPosPrev.y, fc.camPos.y),
272
                    Mth.lerp(tickDelta, fc.camPosPrev.z, fc.camPos.z)
273
            );
274
        }
275
        return mc.gameRenderer.mainCamera().position();
276
    }
277
278
    private Vec3 getActiveCameraLook(float tickDelta) {
279
        Freecam fc = Modules.get(Freecam.class);
280
        if (fc != null && fc.isEnabled()) {
281
            float yaw = (float) Math.toRadians(fc.camYaw);
282
            float pitch = (float) Math.toRadians(fc.camPitch);
283
284
            return new Vec3(
285
                    -Math.sin(yaw) * Math.cos(pitch),
286
                    -Math.sin(pitch),
287
                    Math.cos(yaw) * Math.cos(pitch)
288
            ).normalize();
289
        }
290
        return mc.player.getViewVector(tickDelta).normalize();
291
    }
292
293
    private float getActiveCameraYaw() {
294
        Freecam fc = Modules.get(Freecam.class);
295
        if (fc != null && fc.isEnabled()) {
296
            return fc.camYaw;
297
        }
298
        return mc.gameRenderer.mainCamera().yRot();
299
    }
300
301
    public void render3DTracersRaw(
302
            Renderer3D renderer,
303
            float tickDelta,
304
            List<Vec3> targets,
305
            int argb
306
    ) {
307
        if (mc.player == null || mc.level == null || targets == null || targets.isEmpty()) return;
308
309
        Vec3 camPos = getActiveCameraPos(tickDelta);
310
        Vec3 look = getActiveCameraLook(tickDelta);
311
        Vec3 start = camPos.add(look.scale(10.0));
312
313
        int a = (argb >> 24) & 255;
314
        int r = (argb >> 16) & 255;
315
        int g = (argb >> 8) & 255;
316
        int b = argb & 255;
317
318
        for (Vec3 targetWorld : targets) {
319
            renderer.line(
320
                    start.x, start.y, start.z,
321
                    targetWorld.x, targetWorld.y, targetWorld.z,
322
                    r, g, b, a
323
            );
324
        }
325
    }
326
327
    private Vec3 obtainEntityLerpedPos(Entity e, float f) {
328
        try {
329
            return e.getPosition(f);
330
        } catch (Throwable t) {
331
            if (e instanceof IEntity a) {
332
                return a.get$InstantRenderPos().lerp(e.position(), f);
333
            }
334
            return e.position();
335
        }
336
    }
337
338
    private int resolveColor(Player p) {
339
        return CategoryService.getColor(p);
340
    }
341
342
    private boolean shouldUseAdaptiveRadius() {
343
        if (mc.player == null) return true;
344
        return !(ClientScreen.current() instanceof InventoryScreen);
345
    }
346
347
    private Identifier resolveArrowTexture() {
348
        String mode = arrowTexture.get();
349
        if ("Arrow2".equalsIgnoreCase(mode)) return ARROW_2;
350
        if ("Arrow3".equalsIgnoreCase(mode)) return ARROW_3;
351
        if ("Arrow4".equalsIgnoreCase(mode)) return ARROW_4;
352
        return ARROW_1;
353
    }
354
355
    private boolean isLinesMode() {
356
        return "Lines".equalsIgnoreCase(tracersMode.get());
357
    }
358
359
    private boolean isArrowsMode() {
360
        return "Arrows".equalsIgnoreCase(tracersMode.get());
361
    }
362
363
}
364
KiwiClientRENDERsrc/main/java/com/tangykiwi/kiwiclient/module/render/Tracers.javaJava · 137 lines · 4.6 KB

Draws lines to entities

SettingsWidthOpacityPlayersAnimalsMobs
Tracers.javaJava · Minecraft 26.2 · 137 lines · 4.6 KB · complete file, verbatimOriginal ↗
1
package com.tangykiwi.kiwiclient.module.render;
2
3
import com.google.common.eventbus.Subscribe;
4
import com.tangykiwi.kiwiclient.event.LevelRenderEvent;
5
import com.tangykiwi.kiwiclient.module.Category;
6
import com.tangykiwi.kiwiclient.module.Module;
7
import com.tangykiwi.kiwiclient.module.setting.SliderSetting;
8
import com.tangykiwi.kiwiclient.module.setting.ToggleSetting;
9
import com.tangykiwi.kiwiclient.util.EntityUtils;
10
import com.tangykiwi.kiwiclient.util.render.RenderUtils;
11
12
import net.minecraft.util.Mth;
13
import net.minecraft.world.entity.Entity;
14
import net.minecraft.world.phys.Vec3;
15
16
import static com.tangykiwi.kiwiclient.KiwiClient.mc;
17
18
public class Tracers extends Module {
19
    public Tracers() {
20
        super("Tracers", "Draws lines to entities", Category.RENDER,
21
            new SliderSetting("Width", "Tracer line width", 0.1, 5, 1.5, 1),
22
            new SliderSetting("Opacity", "Tracer line opacity", 0, 1, 0.75, 2),
23
            new ToggleSetting("Players", "Draw tracers to players", true),
24
            new ToggleSetting("Animals", "Draw tracers to animals", false),
25
            new ToggleSetting("Mobs", "Draw tracers to hostile mobs", false));
26
    }
27
28
    @Subscribe
29
    public void onRender(LevelRenderEvent event) {
30
        float width = getSetting(0).asSlider().getValueFloat();
31
        float opacity = getSetting(1).asSlider().getValueFloat();
32
33
        for(Entity e : mc.level.entitiesForRendering()) {
34
            Vec3 vec = e.getEyePosition().add(mc.gameRenderer.mainCamera().position().reverse());
35
            Vec3 vec2 = mc.hitResult.getLocation().add(mc.gameRenderer.mainCamera().position().reverse());
36
            int color = -1;
37
38
            if(EntityUtils.isPlayer(e) && e != mc.player && e != mc.getCameraEntity() && getSetting("Players").asToggle().getValue()) {
39
                color = getColor(e);
40
            } else if(EntityUtils.isAnimal(e) && getSetting("Animals").asToggle().getValue()) {
41
                color = getColor(e);
42
            } else if(EntityUtils.isMob(e) && getSetting("Mobs").asToggle().getValue()) {
43
                color = getColor(e);
44
            }
45
46
            if (color != -1) {
47
                color = ((int)(opacity * 255) << 24) | (color & 0x00FFFFFF);
48
                RenderUtils.drawLine(event.getSubmitNodeStorage(), vec2.x, vec2.y, vec2.z, vec.x, vec.y, vec.z, color, width);
49
            }
50
        }
51
    }
52
53
    private int getColor(Entity e) {
54
        double px = mc.player.getX();
55
        double py = mc.player.getY();
56
        double pz = mc.player.getZ();
57
58
        double ex = e.getX();
59
        double ey = e.getY();
60
        double ez = e.getZ();
61
62
        double dist = Math.sqrt(Math.pow(px - ex, 2) + Math.pow(py - ey, 2) + Math.pow(pz - ez, 2));
63
64
        double ratio = dist / 80;
65
        if(ratio > 1) ratio = 1;
66
67
        return transitionOfHueRange(ratio, 0, 120);
68
    }
69
70
    public int transitionOfHueRange(double percentage, int startHue, int endHue) {
71
        double hue = ((percentage * (endHue - startHue)) + startHue) / 360;
72
73
        double saturation = 1.0;
74
        double lightness = 0.5;
75
76
        return hslColorToRgb(hue, saturation, lightness);
77
    }
78
79
    public int hslColorToRgb(double hue, double saturation, double lightness) {
80
        if (saturation == 0.0) {
81
            int grey = percToColor(lightness);
82
            return (grey << 16) | (grey << 8) | grey;
83
        }
84
85
        double q;
86
        if (lightness < 0.5) {
87
            q = lightness * (1 + saturation);
88
        } else {
89
            q = lightness + saturation - lightness * saturation;
90
        }
91
        double p = 2 * lightness - q;
92
93
        double oneThird = 1.0 / 3;
94
        int red = percToColor(hueToRgb(p, q, hue + oneThird));
95
        int green = percToColor(hueToRgb(p, q, hue));
96
        int blue = percToColor(hueToRgb(p, q, hue - oneThird));
97
98
        return (red << 16) | (green << 8) | blue;
99
    }
100
101
    public double hueToRgb(double p, double q, double t) {
102
        if (t < 0) {
103
            t += 1;
104
        }
105
        if (t > 1) {
106
            t -= 1;
107
        }
108
109
        if (t < 1.0 / 6) {
110
            return p + (q - p) * 6 * t;
111
        }
112
        if (t < 1.0 / 2) {
113
            return q;
114
        }
115
        if (t < 2.0 / 3) {
116
            return p + (q - p) * (2.0 / 3 - t) * 6;
117
        }
118
        return p;
119
    }
120
121
    public int percToColor(double percentage) {
122
        return (int) (percentage * 255);
123
    }
124
125
    public Vec3 getInterpolationOffset(Entity e) {
126
		if (mc.isPaused()) {
127
			return Vec3.ZERO;
128
		}
129
130
		double tickDelta = mc.getDeltaTracker().getGameTimeDeltaPartialTick(true);
131
		return new Vec3(
132
				e.getX() - Mth.lerp(tickDelta, e.xo, e.getX()),
133
				e.getY() - Mth.lerp(tickDelta, e.yo, e.getY()),
134
				e.getZ() - Mth.lerp(tickDelta, e.zo, e.getZ()));
135
	}
136
}
137
LiquidBounce (Kotlin)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleTracers.ktKotlin · 105 lines · 3.9 KB

Draws a line to targets within a certain radius.

SettingsLineWidthMaximumDistance
ModuleTracers.ktKotlin · Minecraft 26.2 · 105 lines · 3.9 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.render
20
21
import net.ccbluex.liquidbounce.event.events.WorldRenderEvent
22
import net.ccbluex.liquidbounce.event.handler
23
import net.ccbluex.liquidbounce.features.misc.FriendManager
24
import net.ccbluex.liquidbounce.features.module.ClientModule
25
import net.ccbluex.liquidbounce.features.module.ModuleCategories
26
import net.ccbluex.liquidbounce.render.GenericDistanceHSBColorMode
27
import net.ccbluex.liquidbounce.render.GenericEntityHealthColorMode
28
import net.ccbluex.liquidbounce.render.GenericRainbowColorMode
29
import net.ccbluex.liquidbounce.render.GenericStaticColorMode
30
import net.ccbluex.liquidbounce.render.drawLines
31
import net.ccbluex.liquidbounce.render.drawLinesWithWidth
32
import net.ccbluex.liquidbounce.render.engine.type.Color4b
33
import net.ccbluex.liquidbounce.render.engine.type.Vec3f
34
import net.ccbluex.liquidbounce.render.renderEnvironment
35
import net.ccbluex.liquidbounce.utils.combat.EntityTaggingManager
36
import net.ccbluex.liquidbounce.utils.entity.RenderedEntities
37
import net.ccbluex.liquidbounce.utils.entity.cameraDistanceSq
38
import net.ccbluex.liquidbounce.utils.entity.interpolateCurrentPosition
39
import net.ccbluex.liquidbounce.utils.math.sq
40
import net.ccbluex.liquidbounce.utils.math.toVec3f
41
42
/**
43
 * Tracers module
44
 *
45
 * Draws a line to every entity a certain radius.
46
 */
47
48
object ModuleTracers : ClientModule("Tracers", ModuleCategories.RENDER) {
49
50
    private val modes = choices("ColorMode", 0) {
51
        arrayOf(
52
            GenericDistanceHSBColorMode.entity(it),
53
            GenericEntityHealthColorMode(it),
54
            GenericStaticColorMode(it, Color4b(0, 160, 255, 255)),
55
            GenericRainbowColorMode(it)
56
        )
57
    }
58
59
    private val lineWidth by float("LineWidth", 1f, 1f..16f)
60
61
    private val maximumDistance by float("MaximumDistance", 128F, 1F..512F)
62
63
    override fun onEnabled() {
64
        RenderedEntities.subscribe(this)
65
    }
66
67
    override fun onDisabled() {
68
        RenderedEntities.unsubscribe(this)
69
    }
70
71
    val renderHandler = handler<WorldRenderEvent> { event ->
72
        if (RenderedEntities.isEmpty()) {
73
            return@handler
74
        }
75
76
        event.renderEnvironment {
77
            val eyeVector = Vec3f.eyeVector(camera)
78
79
            val maxDistanceSq = maximumDistance.sq()
80
            for (entity in RenderedEntities) {
81
                val distanceSq = entity.position().cameraDistanceSq().toFloat()
82
                if (distanceSq > maxDistanceSq) {
83
                    continue
84
                }
85
86
                val color = if (FriendManager.isFriend(entity)) {
87
                    Color4b.BLUE
88
                } else {
89
                    EntityTaggingManager.getTag(entity).color ?: modes.activeMode.getColor(entity)
90
                }
91
92
                val pos = entity.interpolateCurrentPosition(event.partialTicks).subtract(camera.position()).toVec3f()
93
                val topPos = pos.add(0f, entity.bbHeight, 0f)
94
95
                if (lineWidth == 1.0f) {
96
                    drawLines(color.argb, eyeVector, pos, pos, topPos)
97
                } else {
98
                    drawLinesWithWidth(color.argb, lineWidth, eyeVector, pos, pos, topPos)
99
                }
100
            }
101
        }
102
103
    }
104
}
105