1
1
package one .pouekdev .coordinatelist ;
2
2
3
- import com .mojang .blaze3d .systems . RenderSystem ;
3
+ import com .mojang .blaze3d .vertex . VertexFormat ;
4
4
import net .fabricmc .api .ClientModInitializer ;
5
5
import net .fabricmc .fabric .api .client .event .lifecycle .v1 .ClientTickEvents ;
6
6
import net .fabricmc .fabric .api .client .keybinding .v1 .KeyBindingHelper ;
7
7
import net .fabricmc .fabric .api .client .rendering .v1 .WorldRenderEvents ;
8
8
import net .minecraft .client .font .TextRenderer ;
9
- import net .minecraft .client .gl .ShaderProgramKeys ;
10
9
import net .minecraft .client .option .KeyBinding ;
11
10
import net .minecraft .client .render .*;
12
11
import net .minecraft .client .util .InputUtil ;
21
20
import org .apache .commons .lang3 .StringUtils ;
22
21
import org .joml .Matrix4f ;
23
22
import org .lwjgl .glfw .GLFW ;
24
- import org .lwjgl .opengl .GL11 ;
25
23
import eu .midnightdust .lib .config .MidnightConfig ;
26
24
27
- import java .util .ArrayList ;
28
25
import java .util .List ;
29
26
import java .util .Objects ;
30
27
import java .util .Random ;
31
- import java .util .regex .Matcher ;
32
- import java .util .regex .Pattern ;
33
28
34
29
public class CListClient implements ClientModInitializer {
35
30
public static CListVariables variables = new CListVariables ();
36
31
static Random rand = new Random ();
37
32
KeyBinding open_waypoints_keybind ;
38
33
KeyBinding add_a_waypoint ;
39
34
KeyBinding toggle_visibility ;
40
- public float calculateSizeWaypoint (){
35
+ public float calculateWaypointSize (){
41
36
return 0.5f * (CListConfig .multiplier /10.0f );
42
37
}
43
- public float calculateSizeText (){
38
+ public float calculateTextSize (){
44
39
return 15f * (CListConfig .multiplier /10.0f );
45
40
}
46
41
public float distanceTo (CListWaypoint waypoint ) {
@@ -77,15 +72,6 @@ public Vec3d calculateRenderCoords(CListWaypoint waypoint, Camera camera, float
77
72
}
78
73
return new Vec3d (prx ,pry ,prz );
79
74
}
80
- public static List <String > findNumbersInString (String input ) {
81
- List <String > numbersList = new ArrayList <>();
82
- Pattern pattern = Pattern .compile ("-?\\ b(?![A-Za-z])\\ d+(\\ .\\ d+)?\\ b" );
83
- Matcher matcher = pattern .matcher (input );
84
- while (matcher .find ()) {
85
- numbersList .add (matcher .group ());
86
- }
87
- return numbersList ;
88
- }
89
75
@ Override
90
76
public void onInitializeClient () {
91
77
open_waypoints_keybind = KeyBindingHelper .registerKeyBinding (new KeyBinding (
@@ -108,14 +94,12 @@ public void onInitializeClient() {
108
94
));
109
95
WorldRenderEvents .END .register (context ->{
110
96
if (!variables .waypoints .isEmpty () && CListConfig .waypoints_toggled && !CListVariables .minecraft_client .options .hudHidden ) {
111
- RenderSystem .disableCull ();
112
- RenderSystem .depthFunc (GL11 .GL_ALWAYS );
113
97
for (int i = 0 ; i < variables .waypoints .size (); i ++){
114
98
CListWaypoint waypoint = variables .waypoints .get (i );
115
99
int distance_without_decimal_places = (int ) distanceTo (waypoint );
116
100
if (Objects .equals (waypoint .getDimensionString (), getDimension (String .valueOf (variables .last_world .getDimension ().effects ()))) && waypoint .render && (CListConfig .render_distance == 0 || CListConfig .render_distance >= distance_without_decimal_places )) {
117
101
Camera camera = context .camera ();
118
- float size = calculateSizeWaypoint ();
102
+ float size = calculateWaypointSize ();
119
103
Vec3d renderCoords = calculateRenderCoords (waypoint , camera , distance_without_decimal_places );
120
104
Vec3d targetPosition = new Vec3d (renderCoords .x , renderCoords .y +1 , renderCoords .z );
121
105
Vec3d transformedPosition = targetPosition .subtract (camera .getPos ());
@@ -130,25 +114,21 @@ public void onInitializeClient() {
130
114
BufferBuilder buffer = tessellator .begin (VertexFormat .DrawMode .QUADS , VertexFormats .POSITION_TEXTURE_COLOR );
131
115
buffer .vertex (positionMatrix , 0 , 1 , 0 ).color (variables .colors .get (i ).r , variables .colors .get (i ).g , variables .colors .get (i ).b , 1f ).texture (0f , 0f );
132
116
buffer .vertex (positionMatrix , 0 , 0 , 0 ).color (variables .colors .get (i ).r , variables .colors .get (i ).g , variables .colors .get (i ).b , 1f ).texture (0f , 1f );
133
- buffer .vertex (positionMatrix , 1 , 0 , 0 ).color (variables .colors .get (i ).r , variables .colors .get (i ).g , variables .colors .get (i ).b , 1f ).texture (1f , 1 );
117
+ buffer .vertex (positionMatrix , 1 , 0 , 0 ).color (variables .colors .get (i ).r , variables .colors .get (i ).g , variables .colors .get (i ).b , 1f ).texture (1f , 1f );
134
118
buffer .vertex (positionMatrix , 1 , 1 , 0 ).color (variables .colors .get (i ).r , variables .colors .get (i ).g , variables .colors .get (i ).b , 1f ).texture (1f , 0f );
135
- RenderSystem . setShader ( ShaderProgramKeys . POSITION_TEX_COLOR ) ;
119
+ Identifier icon ;
136
120
if (waypoint .deathpoint ){
137
- RenderSystem . setShaderTexture ( 0 , Identifier .of ("coordinatelist" , "skull.png" ) );
121
+ icon = Identifier .of ("coordinatelist" , "skull.png" );
138
122
}
139
123
else {
140
- RenderSystem . setShaderTexture ( 0 , Identifier .of ("coordinatelist" , "waypoint_icon.png" ) );
124
+ icon = Identifier .of ("coordinatelist" , "waypoint_icon.png" );
141
125
}
142
- RenderSystem .setShaderColor (1f , 1f , 1f , 1f );
143
- BufferRenderer .drawWithGlobalProgram (buffer .end ());
144
- RenderSystem .enableBlend ();
145
- RenderSystem .depthMask (true );
146
- RenderSystem .clear (GL11 .GL_DEPTH_BUFFER_BIT );
126
+ CListRenderLayers .POSITION_TEX_COLOR .apply (icon ).draw (buffer .end ());
147
127
TextRenderer textRenderer = CListVariables .minecraft_client .textRenderer ;
148
128
String labelText = waypoint .name + " (" + distance_without_decimal_places + " m)" ;
149
129
int textWidth = textRenderer .getWidth (labelText );
150
130
matrixStack .scale (-0.025f , -0.025f , 0.025f );
151
- size = calculateSizeText ();
131
+ size = calculateTextSize ();
152
132
matrixStack .scale ((float ) Math .log (size * 4 ), (float ) Math .log (size * 4 ), (float ) Math .log (size * 4 ));
153
133
matrixStack .translate (0 ,-20 ,0 );
154
134
positionMatrix = matrixStack .peek ().getPositionMatrix ();
@@ -157,16 +137,14 @@ public void onInitializeClient() {
157
137
if (CListConfig .waypoint_text_background ) {
158
138
textRenderer .draw (labelText , h , 0 , 0xFFFFFF , false , positionMatrix , v , TextRenderer .TextLayerType .NORMAL , 0x90000000 , LightmapTextureManager .MAX_LIGHT_COORDINATE );
159
139
}
160
- // This fixes text flickering. If somebody finds a better way to fix it, please open a PR
161
- matrixStack .translate (0 ,0 ,0.06f );
162
- positionMatrix = matrixStack .peek ().getPositionMatrix ();
163
- textRenderer .draw (labelText , h ,0 ,0xFFFFFF ,false ,positionMatrix ,v , TextRenderer .TextLayerType .NORMAL ,0x00000000 ,LightmapTextureManager .MAX_LIGHT_COORDINATE );
140
+ else {
141
+ textRenderer .draw (labelText , h , 0 , 0xFFFFFF , false , positionMatrix , v , TextRenderer .TextLayerType .NORMAL , 0x00000000 , LightmapTextureManager .MAX_LIGHT_COORDINATE );
142
+ }
143
+ // If we want text to be rendered on top we will have to have a separate layer for it
144
+ // A separate layer breaks the rotation of the text
164
145
v .draw ();
165
- RenderSystem .disableBlend ();
166
146
}
167
147
}
168
- RenderSystem .depthFunc (GL11 .GL_LEQUAL );
169
- RenderSystem .enableCull ();
170
148
}
171
149
});
172
150
ClientTickEvents .END_CLIENT_TICK .register (client -> {
0 commit comments