99import net .createmod .catnip .lang .LangBuilder ;
1010import net .createmod .catnip .lang .LangNumberFormat ;
1111import net .minecraft .network .chat .Component ;
12- import net .minecraft .network .chat .MutableComponent ;
13- import net .minecraft .world .item .ItemStack ;
14- import net .minecraft .world .level .block .state .BlockState ;
15- import net .minecraftforge .fluids .FluidStack ;
1612
17- import java .util .ArrayList ;
18- import java .util .List ;
13+ import java .util .Map ;
14+ import java .util .TreeMap ;
1915
2016public class FormicApiLang extends Lang {
2117 //blatant copy of CreateLang
22- /**
23- * legacy-ish. Use CROWNSLang.translate and other builder methods where possible
24- */
25- public static MutableComponent translateDirect (String key , Object ... args ) {
26- Object [] args1 = LangBuilder .resolveBuilders (args );
27- return Component .translatable (FormicAPI .MODID + "." + key , args1 );
28- }
29-
30- public static List <Component > translatedOptions (String prefix , String ... keys ) {
31- List <Component > result = new ArrayList <>(keys .length );
32- for (String key : keys )
33- result .add (translate ((prefix != null ? prefix + "." : "" ) + key ).component ());
34- return result ;
18+ static TreeMap <Double , String > MULTIPLE_SYMBOLS = new TreeMap <>();
19+ static {
20+ MULTIPLE_SYMBOLS .put (1e18 , "E" );
21+ MULTIPLE_SYMBOLS .put (1e15 , "P" );
22+ MULTIPLE_SYMBOLS .put (1e12 , "T" );
23+ MULTIPLE_SYMBOLS .put (1e9 , "G" );
24+ MULTIPLE_SYMBOLS .put (1e6 , "M" );
25+ MULTIPLE_SYMBOLS .put (1e3 , "k" );
26+ MULTIPLE_SYMBOLS .put (1.0 , "" );
27+ MULTIPLE_SYMBOLS .put (1e-3 , "m" );
28+ MULTIPLE_SYMBOLS .put (1e-6 , "µ" );
29+ MULTIPLE_SYMBOLS .put (1e-9 , "n" );
30+ MULTIPLE_SYMBOLS .put (1e-12 ,"p" );
31+ MULTIPLE_SYMBOLS .put (1e-15 ,"f" );
32+ MULTIPLE_SYMBOLS .put (1e-18 ,"a" );
3533 }
3634
3735//
@@ -40,57 +38,34 @@ public static LangBuilder builder() {
4038 return new LangBuilder (FormicAPI .MODID );
4139 }
4240
43- public static LangBuilder blockName (BlockState state ) {
44- return builder ().add (state .getBlock ()
45- .getName ());
46- }
47-
48- public static LangBuilder itemName (ItemStack stack ) {
49- return builder ().add (stack .getHoverName ()
50- .copy ());
51- }
52-
53- public static LangBuilder fluidName (FluidStack stack ) {
54- return builder ().add (stack .getDisplayName ()
55- .copy ());
56- }
57-
58- public static LangBuilder number (double d ) {
59- return builder ().text (LangNumberFormat .format (d ));
41+ public static LangBuilder numberWithSymbol (double d ) {
42+ Map .Entry <Double , String > entry = MULTIPLE_SYMBOLS .floorEntry (d );
43+ if (entry == null ) {
44+ builder ().text (LangNumberFormat .format (d )+ " " );
45+ }
46+ return builder ().text (LangNumberFormat .format (d /entry .getKey ())+" " +entry .getValue ());
6047 }
6148
6249 public static LangBuilder translate (String langKey , Object ... args ) {
6350 return builder ().translate (langKey , args );
6451 }
6552
66- public static LangBuilder text (String text ) {
67- return builder ().text (text );
68- }
69-
70- @ Deprecated // Use while implementing and replace all references with Lang.translate
71- public static LangBuilder temporaryText (String text ) {
72- return builder ().text (text );
73- }
74-
7553 public static LangBuilder formatTemperature (float temperature ) {
7654 Temperature unit = FormicAPIConfigs .CLIENT .units .temperature .get ();
7755 return CreateLang .builder ().add (Component .literal ("T = " ))
78- .add (number (unit .convert (temperature )))
79- .text (" " )
56+ .text (LangNumberFormat .format (unit .convert (temperature ))+ " " )
8057 .add (unit .getSymbol ());
8158 }
8259 public static LangBuilder formatPressure (float pressure ) {
8360 Pressure unit = FormicAPIConfigs .CLIENT .units .pressure .get ();
8461 return CreateLang .builder ().add (Component .literal ("P = " ))
85- .add (number (unit .convert (pressure )))
86- .text (" " )
62+ .add (numberWithSymbol (unit .convert (pressure )))
8763 .add (unit .getSymbol ());
8864 }
8965 public static LangBuilder formatRadiationFlux (float radiationFlux ) {
9066 RadiationFlux unit = FormicAPIConfigs .CLIENT .units .radiationFlux .get ();
9167 return CreateLang .builder ().add (Component .literal ("activity : " ))
92- .add (number (unit .convert (radiationFlux )))
93- .text (" " )
68+ .add (numberWithSymbol (unit .convert (radiationFlux )))
9469 .add (unit .getSymbol ());
9570 }
9671
0 commit comments