11package com .wurstclient_v7 .feature ;
22
33import com .mojang .blaze3d .systems .RenderSystem ;
4- import com .mojang .blaze3d .vertex .BufferBuilder ;
5- import com .mojang .blaze3d .vertex .DefaultVertexFormat ;
6- import com .mojang .blaze3d .vertex .PoseStack ;
7- import com .mojang .blaze3d .vertex .Tesselator ;
8- import com .mojang .blaze3d .vertex .VertexFormat ;
4+ import com .mojang .blaze3d .vertex .*;
95import net .minecraft .client .Minecraft ;
106import net .minecraft .client .renderer .GameRenderer ;
117import net .minecraft .world .entity .Entity ;
1612public final class Tracers {
1713 private static volatile boolean enabled = false ;
1814
19- private Tracers () {
20- }
21-
22- public static boolean isEnabled () {
23- return enabled ;
24- }
15+ private Tracers () {}
2516
26- public static void toggle () {
27- enabled = !enabled ;
28- }
17+ public static boolean isEnabled () { return enabled ; }
18+ public static void toggle () { enabled = !enabled ; }
2919
30- public static void onRender ( PoseStack poseStack , float partialTicks ) {
20+ public static void render ( Matrix4f matrix , float partialTicks ) {
3121 if (!enabled ) return ;
3222 Minecraft mc = Minecraft .getInstance ();
3323 if (mc .player == null || mc .level == null ) return ;
@@ -38,38 +28,46 @@ public static void onRender(PoseStack poseStack, float partialTicks) {
3828 RenderSystem .setShader (GameRenderer ::getPositionColorShader );
3929
4030 Tesselator tesselator = Tesselator .getInstance ();
41- // 1.21 Change: begin() now takes the format and returns the BufferBuilder directly
42- com .mojang .blaze3d .vertex .BufferBuilder buffer = tesselator .begin (VertexFormat .Mode .DEBUG_LINES , DefaultVertexFormat .POSITION_COLOR );
31+ BufferBuilder buffer = tesselator .begin (VertexFormat .Mode .DEBUG_LINES , DefaultVertexFormat .POSITION_COLOR );
4332
44- poseStack .pushPose ();
4533 Vec3 cameraPos = mc .gameRenderer .getMainCamera ().getPosition ();
46- poseStack .translate (-cameraPos .x , -cameraPos .y , -cameraPos .z );
47-
48- Vec3 start = mc .player .getEyePosition (partialTicks );
49- Matrix4f matrix = poseStack .last ().pose ();
34+ Vec3 start = mc .player .getEyePosition (partialTicks ).subtract (cameraPos );
5035
5136 for (Entity entity : mc .level .entitiesForRendering ()) {
52- if (entity == mc .player ) continue ;
53- if (!(entity instanceof Player )) continue ;
37+ if (entity == mc .player || !(entity instanceof Player )) continue ;
38+
39+ // 1. Calculate Distance
40+ float distance = mc .player .distanceTo (entity );
41+
42+ // 2. Determine Color (Green to Red)
43+ // 20 blocks = Red, 60+ blocks = Green
44+ float red = Math .min (1.0f , 1.0f - (distance - 20 ) / 40.0f );
45+ float green = Math .min (1.0f , (distance - 20 ) / 40.0f );
46+
47+ // If they are super close (under 20 blocks), force pure Red
48+ if (distance < 20 ) {
49+ red = 1.0f ; green = 0.0f ;
50+ }
5451
55- Vec3 pos = entity .getPosition (partialTicks );
52+ Vec3 pos = entity .getPosition (partialTicks )
53+ .add (0 , entity .getBbHeight () / 2 , 0 )
54+ .subtract (cameraPos );
5655
57- // 1.21 Change: vertex() method order matters
56+ // First Vertex (at player)
5857 buffer .addVertex (matrix , (float ) start .x , (float ) start .y , (float ) start .z )
59- .setColor (0 , 255 , 0 , 255 );
58+ .setColor (red , green , 0.0f , 1.0f );
6059
61- buffer .addVertex (matrix , (float ) pos .x , (float ) pos .y + entity .getEyeHeight () / 2 , (float ) pos .z )
62- .setColor (0 , 255 , 0 , 255 );
60+ // Second Vertex (at target)
61+ buffer .addVertex (matrix , (float ) pos .x , (float ) pos .y , (float ) pos .z )
62+ .setColor (red , green , 0.0f , 1.0f );
6363 }
6464
65- // 1.21 Change: BufferUploader is now often used to finish the draw
66- com .mojang .blaze3d .vertex .MeshData meshData = buffer .build ();
65+ MeshData meshData = buffer .build ();
6766 if (meshData != null ) {
68- com . mojang . blaze3d . vertex . BufferUploader .drawWithShader (meshData );
67+ BufferUploader .drawWithShader (meshData );
6968 }
7069
71- poseStack .popPose ();
7270 RenderSystem .enableDepthTest ();
7371 RenderSystem .disableBlend ();
7472 }
75- }
73+ }
0 commit comments