22
33import  net .fabricmc .api .EnvType ;
44import  net .fabricmc .api .Environment ;
5- import  net .minecraft .ChatFormatting ;
65import  net .minecraft .Util ;
7- import  net .minecraft .client .Minecraft ;
8- import  net .minecraft .client .gui .GuiGraphics ;
96import  net .minecraft .network .chat .Component ;
107import  net .minecraft .resources .ResourceLocation ;
118import  net .minecraft .world .entity .ai .attributes .AttributeModifier ;
129import  net .minecraft .world .item .ItemStack ;
1310import  smartin .miapi .Miapi ;
14- import  smartin .miapi .client .gui .ParentHandledScreen ;
1511import  smartin .miapi .modules .properties .util .DoubleOperationResolvable ;
1612import  smartin .miapi .modules .properties .util .DoubleProperty ;
1713
1814import  java .text .DecimalFormat ;
1915import  java .text .DecimalFormatSymbols ;
20- import  java .util .ArrayList ;
21- import  java .util .List ;
2216import  java .util .Locale ;
2317import  java .util .function .BiFunction ;
2418
@@ -46,37 +40,12 @@ public double getValue(ItemStack stack) {
4640        return  property .getValue (stack ).orElse (0.0 );
4741    }
4842
49-     //@Override 
50-     public  void  renderHover2 (GuiGraphics  drawContext , int  mouseX , int  mouseY , float  delta ) {
51-         List <Component > list  = new  ArrayList (getHoverLines (drawContext , mouseX , mouseY , delta ));
52-         if  (this .isMouseOver (mouseX , mouseY )) {
53-             if  (ParentHandledScreen .hasShiftDown ()) {
54-                 property .getData (compareTo  == null  ? original  : compareTo ).ifPresent (resolvable  -> {
55-                     resolvable .operations .forEach (operation  -> {
56-                         if  (operation .solve () != 0 ) {
57-                             list .add (Component .literal (stringForOperation (operation )).withStyle (ChatFormatting .GRAY ));
58-                             if  (ParentHandledScreen .hasAltDown ()) {
59-                                 list .add (Component .literal ("  "  + operation .value ).withStyle (ChatFormatting .DARK_GRAY ));
60-                             }
61-                         }
62-                     });
63-                 });
64-                 list .add (Component .translatable ("miapi.ui.stat_detail.shift_alt" ).withStyle (ChatFormatting .DARK_GRAY ));
65-             } else  {
66-                 list .add (Component .translatable ("miapi.ui.stat_detail.shift" ).withStyle (ChatFormatting .DARK_GRAY ));
67-             }
68-         }
69-         drawContext .renderComponentTooltip (
70-                 Minecraft .getInstance ().font ,
71-                 list , mouseX , mouseY );
72-     }
73- 
7443    public  DoubleOperationResolvable  getResolvable (ItemStack  stack ) {
7544        return  property .getData (stack ).orElse (null );
7645    }
7746
78-     public  static  String  stringForOperation (DoubleOperationResolvable .Operation  resolvable ) {
79-         String  number  = ""  + resolvable .solve ();
47+     public  static  String  stringForOperation (DecimalFormat   format ,  DoubleOperationResolvable .Operation  resolvable ) {
48+         String  number  = ""  + format . format ( resolvable .solve () );
8049        String  operation  = getStringName (resolvable .attributeOperation );
8150        if  (operation .equals ("+" ) && number .startsWith ("-" )) {
8251            return  number  + " "  + resolvable .instance .getModuleName ().getString ();
@@ -103,6 +72,7 @@ public static class Builder {
10372        public  String  translationKey  = "" ;
10473        public  Object [] descriptionArgs  = new  Object []{};
10574        public  DecimalFormat  modifierFormat ;
75+         public  DecimalFormat  hoverFormat ;
10676        public  double  min  = 0 ;
10777        public  double  max  = 100 ;
10878        public  boolean  inverse  = false ;
@@ -169,6 +139,13 @@ public Builder setFormat(String format) {
169139            return  this ;
170140        }
171141
142+         public  Builder  setHoverFormat (String  format ) {
143+             hoverFormat  = Util .make (new  DecimalFormat (format ), (decimalFormat ) -> {
144+                 decimalFormat .setDecimalFormatSymbols (DecimalFormatSymbols .getInstance (Locale .ROOT ));
145+             });
146+             return  this ;
147+         }
148+ 
172149        public  SinglePropertyStatDisplay  build () {
173150            // Validate the required fields 
174151            if  (name  == null ) {
@@ -185,6 +162,10 @@ public SinglePropertyStatDisplay build() {
185162            display .modifierFormat  = modifierFormat ;
186163            display .inverse  = inverse ;
187164            display .condition  = condition ;
165+             if  (hoverFormat  == null ) {
166+                 hoverFormat  = modifierFormat ;
167+             }
168+             display .hoverFormat  = hoverFormat ;
188169            return  display ;
189170        }
190171    }
0 commit comments