2
2
3
3
import net .fabricmc .api .EnvType ;
4
4
import net .fabricmc .api .Environment ;
5
- import net .minecraft .ChatFormatting ;
6
5
import net .minecraft .Util ;
7
- import net .minecraft .client .Minecraft ;
8
- import net .minecraft .client .gui .GuiGraphics ;
9
6
import net .minecraft .network .chat .Component ;
10
7
import net .minecraft .resources .ResourceLocation ;
11
8
import net .minecraft .world .entity .ai .attributes .AttributeModifier ;
12
9
import net .minecraft .world .item .ItemStack ;
13
10
import smartin .miapi .Miapi ;
14
- import smartin .miapi .client .gui .ParentHandledScreen ;
15
11
import smartin .miapi .modules .properties .util .DoubleOperationResolvable ;
16
12
import smartin .miapi .modules .properties .util .DoubleProperty ;
17
13
18
14
import java .text .DecimalFormat ;
19
15
import java .text .DecimalFormatSymbols ;
20
- import java .util .ArrayList ;
21
- import java .util .List ;
22
16
import java .util .Locale ;
23
17
import java .util .function .BiFunction ;
24
18
@@ -46,37 +40,12 @@ public double getValue(ItemStack stack) {
46
40
return property .getValue (stack ).orElse (0.0 );
47
41
}
48
42
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
-
74
43
public DoubleOperationResolvable getResolvable (ItemStack stack ) {
75
44
return property .getData (stack ).orElse (null );
76
45
}
77
46
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 () );
80
49
String operation = getStringName (resolvable .attributeOperation );
81
50
if (operation .equals ("+" ) && number .startsWith ("-" )) {
82
51
return number + " " + resolvable .instance .getModuleName ().getString ();
@@ -103,6 +72,7 @@ public static class Builder {
103
72
public String translationKey = "" ;
104
73
public Object [] descriptionArgs = new Object []{};
105
74
public DecimalFormat modifierFormat ;
75
+ public DecimalFormat hoverFormat ;
106
76
public double min = 0 ;
107
77
public double max = 100 ;
108
78
public boolean inverse = false ;
@@ -169,6 +139,13 @@ public Builder setFormat(String format) {
169
139
return this ;
170
140
}
171
141
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
+
172
149
public SinglePropertyStatDisplay build () {
173
150
// Validate the required fields
174
151
if (name == null ) {
@@ -185,6 +162,10 @@ public SinglePropertyStatDisplay build() {
185
162
display .modifierFormat = modifierFormat ;
186
163
display .inverse = inverse ;
187
164
display .condition = condition ;
165
+ if (hoverFormat == null ) {
166
+ hoverFormat = modifierFormat ;
167
+ }
168
+ display .hoverFormat = hoverFormat ;
188
169
return display ;
189
170
}
190
171
}
0 commit comments