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 .neoforged .neoforge .fluids .FluidStack ;
1612
17-
18- import java .util .ArrayList ;
19- import java .util .List ;
13+ import java .util .Map ;
14+ import java .util .TreeMap ;
2015
2116public class FormicApiLang extends Lang {
2217 //blatant copy of CreateLang
23- /**
24- * legacy-ish. Use CROWNSLang.translate and other builder methods where possible
25- */
26- public static MutableComponent translateDirect (String key , Object ... args ) {
27- Object [] args1 = LangBuilder .resolveBuilders (args );
28- return Component .translatable (FormicAPI .MODID + "." + key , args1 );
29- }
30-
31- public static List <Component > translatedOptions (String prefix , String ... keys ) {
32- List <Component > result = new ArrayList <>(keys .length );
33- for (String key : keys )
34- result .add (translate ((prefix != null ? prefix + "." : "" ) + key ).component ());
35- 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" );
3633 }
3734
3835//
@@ -41,57 +38,34 @@ public static LangBuilder builder() {
4138 return new LangBuilder (FormicAPI .MODID );
4239 }
4340
44- public static LangBuilder blockName (BlockState state ) {
45- return builder ().add (state .getBlock ()
46- .getName ());
47- }
48-
49- public static LangBuilder itemName (ItemStack stack ) {
50- return builder ().add (stack .getHoverName ()
51- .copy ());
52- }
53-
54- public static LangBuilder fluidName (FluidStack stack ) {
55- return builder ().add (stack .getDisplayName ()
56- .copy ());
57- }
58-
59- public static LangBuilder number (double d ) {
60- 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 ());
6147 }
6248
6349 public static LangBuilder translate (String langKey , Object ... args ) {
6450 return builder ().translate (langKey , args );
6551 }
6652
67- public static LangBuilder text (String text ) {
68- return builder ().text (text );
69- }
70-
71- @ Deprecated // Use while implementing and replace all references with Lang.translate
72- public static LangBuilder temporaryText (String text ) {
73- return builder ().text (text );
74- }
75-
7653 public static LangBuilder formatTemperature (float temperature ) {
7754 Temperature unit = FormicAPIConfigs .CLIENT .units .temperature .get ();
7855 return CreateLang .builder ().add (Component .literal ("T = " ))
79- .add (number (unit .convert (temperature )))
80- .text (" " )
56+ .text (LangNumberFormat .format (unit .convert (temperature ))+ " " )
8157 .add (unit .getSymbol ());
8258 }
8359 public static LangBuilder formatPressure (float pressure ) {
8460 Pressure unit = FormicAPIConfigs .CLIENT .units .pressure .get ();
8561 return CreateLang .builder ().add (Component .literal ("P = " ))
86- .add (number (unit .convert (pressure )))
87- .text (" " )
62+ .add (numberWithSymbol (unit .convert (pressure )))
8863 .add (unit .getSymbol ());
8964 }
9065 public static LangBuilder formatRadiationFlux (float radiationFlux ) {
9166 RadiationFlux unit = FormicAPIConfigs .CLIENT .units .radiationFlux .get ();
9267 return CreateLang .builder ().add (Component .literal ("activity : " ))
93- .add (number (unit .convert (radiationFlux )))
94- .text (" " )
68+ .add (numberWithSymbol (unit .convert (radiationFlux )))
9569 .add (unit .getSymbol ());
9670 }
9771
0 commit comments