11package me .zacharias .speedometer ;
22
33import com .mojang .blaze3d .platform .InputConstants ;
4+ import com .mojang .blaze3d .vertex .PoseStack ;
45import dev .architectury .event .events .client .ClientGuiEvent ;
56import dev .architectury .event .events .client .ClientTickEvent ;
67import dev .architectury .platform .Platform ;
78import dev .architectury .registry .client .keymappings .KeyMappingRegistry ;
89import net .minecraft .ChatFormatting ;
9- import net .minecraft .client .DeltaTracker ;
1010import net .minecraft .client .KeyMapping ;
1111import net .minecraft .client .Minecraft ;
12- import net .minecraft .client .gui .GuiGraphics ;
12+ import net .minecraft .client .gui .Gui ;
1313import net .minecraft .network .chat .ClickEvent ;
14+ import net .minecraft .network .chat .TextColor ;
15+ import net .minecraft .network .chat .TranslatableComponent ;
1416import net .minecraft .world .entity .Entity ;
1517import net .minecraft .world .entity .vehicle .Boat ;
1618import net .minecraft .world .phys .Vec3 ;
17- import net .minecraft .network .chat .Component ;
1819
1920import java .awt .*;
2021import java .awt .image .BufferedImage ;
@@ -40,8 +41,8 @@ public class Client {
4041
4142
4243 public static void init (){
43-
44- final boolean isClothLoaded = Platform .isModLoaded ("cloth_config" ) || Platform .isModLoaded ("cloth-config" );
44+
45+ final boolean isClothLoaded = Platform .isModLoaded ("cloth_config" ) || Platform .isModLoaded ("cloth-config" ) || Platform . isModLoaded ( "cloth-config2" ) ;
4546
4647 if (isClothLoaded ) {
4748 Platform .getMod (MOD_ID ).registerConfigurationScreen (parent -> ConfigMenu .getConfig (parent ).build ());
@@ -59,20 +60,21 @@ public static void init(){
5960 }
6061 else if (Minecraft .getInstance ().player != null )
6162 {
62- Minecraft .getInstance ().player .displayClientMessage (
63- Component
64- .translatable ("speedometer.error.missing_cloth" )
65- .withColor (new Color (190 , 0 , 0 ).getRGB ())
66- .append (Component
67- .translatable ("speedometer.error.missing_cloth.open_config" )
68- .withStyle (ChatFormatting .UNDERLINE )
69- .withStyle ((style ) -> style .withClickEvent (new ClickEvent .OpenFile (Config .getConfigPath ())))
70- ), false );
71- LOGGER .warn (Component .translatable ("speedometer.error.missing_cloth" ).getString ());
63+ Minecraft .getInstance ().player .displayClientMessage (
64+ new TranslatableComponent ("speedometer.error.missing_cloth" )
65+ .withStyle (style -> style .withColor (ChatFormatting .RED ))
66+ .append (
67+ new TranslatableComponent ("speedometer.error.missing_cloth.open_config" )
68+ .withStyle (style -> style
69+ .withColor (ChatFormatting .DARK_RED )
70+ .withUnderlined (true )
71+ .withClickEvent (new ClickEvent (ClickEvent .Action .OPEN_FILE , Config .getConfigPath ()))))
72+ , false );
73+ LOGGER .warn (new TranslatableComponent ("speedometer.error.missing_cloth" ).getString ());
7274 }
7375 else
7476 {
75- LOGGER .warn (Component . translatable ("speedometer.error.missing_cloth" ).getString ());
77+ LOGGER .warn (new TranslatableComponent ("speedometer.error.missing_cloth" ).getString ());
7678 }
7779 }
7880 });
@@ -92,7 +94,7 @@ else if(Minecraft.getInstance().player != null)
9294 LOGGER .info ("Finished loading speedometer" );
9395 }
9496
95- private static void render (GuiGraphics graphics , DeltaTracker deltaTracker ) {
97+ private static void render (PoseStack poseStack , float delta ) {
9698 if (Minecraft .getInstance ().player == null ) return ;
9799 if (Minecraft .getInstance ().options .hideGui ) return ;
98100 Entity entity = Minecraft .getInstance ().player .getRootVehicle ();
@@ -112,7 +114,7 @@ private static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
112114 double lSpeed = speed ;
113115
114116 if (speeds .size () >= 30 ) {
115- speeds .removeFirst ( );
117+ speeds .remove ( 0 );
116118 }
117119 speeds .add (speed );
118120 speed = 0 ;
@@ -144,8 +146,8 @@ private static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
144146 default -> 0 ;
145147 };
146148
147- int yPos = getPosImp (graphics , width , Config .getYPosition (), false );
148- int xPos = getPosImp (graphics , width , Config .getXPosition (), true );
149+ int yPos = getPosImp (poseStack , width , Config .getYPosition (), false );
150+ int xPos = getPosImp (poseStack , width , Config .getXPosition (), true );
149151
150152 int lineHeight = Minecraft .getInstance ().font .lineHeight ;
151153
@@ -163,22 +165,22 @@ private static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
163165 int rgb = img .getRGB (x1 , y1 );
164166
165167 if (new Color (rgb ).equals (Color .black )) continue ;
166-
167- graphics .fill (x2 , y2 , x2 +1 , y2 +1 , rgb );
168+
169+ Gui .fill (poseStack , x2 , y2 , x2 +1 , y2 +1 , rgb );
168170 }
169171 }
170172
171173 }else {
172174 // i -> x
173175 // j -> y
174176 // k -> color RGB int
175- graphics . drawString (
176- Minecraft . getInstance (). font ,
177- speedString ,
178- xPos - width ,
179- yPos - lineHeight ,
180- Config .getColor ().getRGB ()
181- );
177+ drawString (
178+ poseStack ,
179+ xPos - width ,
180+ yPos - lineHeight ,
181+ speedString ,
182+ Config .getColor ().getRGB ()
183+ );
182184 }
183185
184186 if (Config .isDebug ()){
@@ -200,20 +202,24 @@ private static void render(GuiGraphics graphics, DeltaTracker deltaTracker) {
200202 "Velocity total in " + speedType .name () + ": " + speedTypeSpeed + "\n " +
201203 "Endpoint position: (" + Debugger .x + ", " + Debugger .y + ")\n " +
202204 "Percentage point of visual speedometer: " + Debugger .angle + "\n " +
203- (Config .getVisualSpeedometer ()?"Visual Size: " +Config .getImageSize ():"Textual display" );
205+ (Config .getVisualSpeedometer ()?"Visual Size: " +Config .getImageSize ():"Textual display" ) + "\n " +
206+ "Pos: (" +xPos +", " +yPos +") \n " +
207+ "Width: " +Minecraft .getInstance ().getWindow ().getGuiScaledWidth () + "\n " +
208+ "Height: " +Minecraft .getInstance ().getWindow ().getGuiScaledHeight ();
204209
205210 Color color = new Color (255 , 255 , 255 );
206211
207212 int y = 0 ;
208213 for (String s : debugData .split ("\n " )){
209- drawString (graphics ,0 , y , s , color .getRGB ());
214+ drawString (poseStack ,0 , y , s , color .getRGB ());
210215 y +=Minecraft .getInstance ().font .lineHeight +1 ;
211216 }
212217 }
213218 }
214219
215- private static void drawString (GuiGraphics graphics , int x , int y , String text , int colorRGB ){
216- graphics .drawString (
220+ private static void drawString (PoseStack poseStack , int x , int y , String text , int colorRGB ){
221+ Gui .drawString (
222+ poseStack ,
217223 Minecraft .getInstance ().font ,
218224 text ,
219225 x ,
@@ -222,11 +228,14 @@ private static void drawString(GuiGraphics graphics, int x, int y, String text,
222228 );
223229 }
224230
225- private static int getPosImp (GuiGraphics event , int width , String input , boolean isXPosition ){
231+ private static int getPosImp (PoseStack poseStack , int width , String input , boolean isXPosition ){
232+ int width1 = Minecraft .getInstance ().getWindow ().getGuiScaledWidth ();
233+ int height1 = Minecraft .getInstance ().getWindow ().getGuiScaledHeight ();
234+
226235 input = input .trim ();
227236 input = input
228- .replaceAll ("(W+)|(H+)" , String .valueOf (isXPosition ?event . guiWidth (): event . guiHeight () ))
229- .replaceAll ("(w+)|(h+)" , String .valueOf (isXPosition ?event . guiWidth ()/ 2 : event . guiHeight () /2 ))
237+ .replaceAll ("(W+)|(H+)" , String .valueOf (isXPosition ? width1 : height1 ))
238+ .replaceAll ("(w+)|(h+)" , String .valueOf (isXPosition ? width1 / 2 : height1 /2 ))
230239 .replaceAll ("(S+)|(s+)" , String .valueOf (width ));
231240 if ((Config .isDebug ()) && Config .getCounter () < 2 ) {
232241 //String speedDisplayType = SpeedTypes.getName(Config.getSpeedType()).getString();
@@ -235,23 +244,27 @@ private static int getPosImp(GuiGraphics event, int width, String input, boolean
235244 LOGGER .info ("Selected speed type(DEBUG): {}\n {}\n \n \n " , isXPosition , input );
236245 Config .addCounter ();
237246 }
238- return getPos (event , width , input , isXPosition );
247+ return getPos (poseStack , width , input , isXPosition );
239248 }
240249
241- private static int getPos (GuiGraphics event , int width , String input , boolean isXPosition ) {
250+ private static int getPos (PoseStack event , int width , String input , boolean isXPosition ) {
251+
252+ int width1 = Minecraft .getInstance ().getWindow ().getGuiScaledWidth ();
253+ int height1 = Minecraft .getInstance ().getWindow ().getGuiScaledHeight ();
254+
242255 ArrayList <String > passerPose = new ArrayList <>();
243256 final char [] s = input .toCharArray ();
244257
245258 try {
246259 for (int i = 0 ; i <s .length ; i ++){
247260 char c = s [i ];
248261 if (c == 'W' || c == 'H' ){
249- if (isXPosition ) passerPose .add (String .valueOf (event . guiWidth () ));
250- else passerPose .add (String .valueOf (event . guiHeight () ));
262+ if (isXPosition ) passerPose .add (String .valueOf (width1 ));
263+ else passerPose .add (String .valueOf (height1 ));
251264 }
252265 else if (c == 'h' || c == 'w' ){
253- if (isXPosition ) passerPose .add (String .valueOf (event . guiWidth () / 2 ));
254- else passerPose .add (String .valueOf (event . guiHeight () / 2 ));
266+ if (isXPosition ) passerPose .add (String .valueOf (width1 / 2 ));
267+ else passerPose .add (String .valueOf (height1 / 2 ));
255268 }
256269 else if (c == 'S' || c == 's' ){
257270 passerPose .add (String .valueOf (width ));
@@ -264,8 +277,8 @@ else if(c == '+' ||
264277 }
265278 else if (Character .isDigit (c )){
266279 int lastIndex = i - 1 ;
267- if (lastIndex > 0 && passerPose .get (lastIndex ).matches ("^[0-9]+$" )) {
268- passerPose .add (passerPose .removeLast ( ) + c );
280+ if (lastIndex >= 0 && passerPose .get (passerPose . size ()- 1 ).matches ("^[0-9]+$" )) {
281+ passerPose .add (passerPose .remove ( passerPose . size ()- 1 ) + c );
269282 }
270283 else
271284 {
@@ -285,11 +298,11 @@ else if(Character.isDigit(c)){
285298
286299 int position ;
287300 try {
288- position = Integer .parseInt (passerPose .getFirst ( ));
301+ position = Integer .parseInt (passerPose .get ( 0 ));
289302 }catch (NumberFormatException e ){
290303 passerPose .clear ();
291304 defaultValues (event , isXPosition , passerPose );
292- position = Integer .parseInt (passerPose .getFirst ( ));
305+ position = Integer .parseInt (passerPose .get ( 0 ));
293306 }
294307
295308 for (int i = 1 ; i < passerPose .size (); i ++){
@@ -322,16 +335,16 @@ else if(Character.isDigit(c)){
322335 return position ;
323336 }
324337
325- private static void defaultValues (GuiGraphics event , boolean isXPosition , ArrayList <String > passerPose ) {
338+ private static void defaultValues (PoseStack event , boolean isXPosition , ArrayList <String > passerPose ) {
326339 if (isXPosition )
327340 {
328- passerPose .add (String .valueOf (event . guiWidth ()));
341+ passerPose .add (String .valueOf (Minecraft . getInstance (). getWindow (). getGuiScaledWidth ()));
329342 passerPose .add ("-" );
330343 passerPose .add ("3" );
331344 }
332345 else
333346 {
334- passerPose .add (String .valueOf (event . guiHeight ()));
347+ passerPose .add (String .valueOf (Minecraft . getInstance (). getWindow (). getGuiScaledHeight ()));
335348 passerPose .add ("-" );
336349 passerPose .add ("3" );
337350 }
0 commit comments