22
33import net .fabricmc .loader .api .ModContainer ;
44import net .fabricmc .loader .api .metadata .Person ;
5- import net .minecraft .text .*;
6- import net .minecraft .util .Formatting ;
7-
5+ import net .minecraft .ChatFormatting ;
6+ import net .minecraft .network .chat .ClickEvent ;
7+ import net .minecraft .network .chat .Component ;
8+ import net .minecraft .network .chat .HoverEvent ;
9+ import net .minecraft .network .chat .MutableComponent ;
10+ import net .minecraft .network .chat .Style ;
811import javax .imageio .ImageIO ;
912import java .net .URI ;
1013import java .nio .file .Files ;
1417import java .util .stream .Collectors ;
1518
1619public class GenericModInfo {
17- private static Text [] icon = new Text [0 ];
18- private static Text [] about = new Text [0 ];
19- private static Text [] consoleAbout = new Text [0 ];
20+ private static Component [] icon = new Component [0 ];
21+ private static Component [] about = new Component [0 ];
22+ private static Component [] consoleAbout = new Component [0 ];
2023
2124 public static void build (ModContainer container ) {
2225 {
2326 final String chr = "█" ;
24- var icon = new ArrayList <MutableText >();
27+ var icon = new ArrayList <MutableComponent >();
2528 try {
2629 var source = ImageIO .read (Files .newInputStream (container .getPath ("assets/logo_mini.png" )));
2730
2831 for (int y = 0 ; y < source .getHeight (); y ++) {
29- var base = Text .literal ("" );
32+ var base = Component .literal ("" );
3033 int line = 0 ;
3134 int color = source .getRGB (0 , y ) & 0xFFFFFF ;
3235 for (int x = 0 ; x < source .getWidth (); x ++) {
@@ -35,52 +38,52 @@ public static void build(ModContainer container) {
3538 if (color == colorPixel ) {
3639 line ++;
3740 } else {
38- base .append (Text .literal (chr .repeat (line )).setStyle (Style .EMPTY .withColor (color )));
41+ base .append (Component .literal (chr .repeat (line )).setStyle (Style .EMPTY .withColor (color )));
3942 color = colorPixel ;
4043 line = 1 ;
4144 }
4245 }
4346
44- base .append (Text .literal (chr .repeat (line )).setStyle (Style .EMPTY .withColor (color )));
47+ base .append (Component .literal (chr .repeat (line )).setStyle (Style .EMPTY .withColor (color )));
4548 icon .add (base );
4649 }
4750 } catch (Throwable e ) {
4851 e .printStackTrace ();
4952 while (icon .size () < 16 ) {
50- icon .add (Text .literal ("/!\\ [ Invalid icon file ] /!\\ " ).setStyle (Style .EMPTY .withColor (0xFF0000 ).withItalic (true )));
53+ icon .add (Component .literal ("/!\\ [ Invalid icon file ] /!\\ " ).setStyle (Style .EMPTY .withColor (0xFF0000 ).withItalic (true )));
5154 }
5255 }
5356
54- GenericModInfo .icon = icon .toArray (new Text [0 ]);
57+ GenericModInfo .icon = icon .toArray (new Component [0 ]);
5558 }
5659
5760 {
58- var about = new ArrayList <Text >();
59- var aboutBasic = new ArrayList <Text >();
60- var output = new ArrayList <Text >();
61+ var about = new ArrayList <Component >();
62+ var aboutBasic = new ArrayList <Component >();
63+ var output = new ArrayList <Component >();
6164
6265 try {
63- about .add (Text .literal (container .getMetadata ().getName ()).setStyle (Style .EMPTY .withColor (0x00e6b4 ).withBold (true ).withClickEvent (new ClickEvent .OpenUrl (URI .create (container .getMetadata ().getContact ().get ("github" ).orElse ("https://pb4.eu" ))))));
64- about .add (Text .translatable ("text.graves.about.version" , Text .literal (container .getMetadata ().getVersion ().getFriendlyString ()).setStyle (Style .EMPTY .withColor (Formatting .WHITE ))).setStyle (Style .EMPTY .withColor (0xf7e1a7 )));
66+ about .add (Component .literal (container .getMetadata ().getName ()).setStyle (Style .EMPTY .withColor (0x00e6b4 ).withBold (true ).withClickEvent (new ClickEvent .OpenUrl (URI .create (container .getMetadata ().getContact ().get ("github" ).orElse ("https://pb4.eu" ))))));
67+ about .add (Component .translatable ("text.graves.about.version" , Component .literal (container .getMetadata ().getVersion ().getFriendlyString ()).setStyle (Style .EMPTY .withColor (ChatFormatting .WHITE ))).setStyle (Style .EMPTY .withColor (0xf7e1a7 )));
6568
6669 aboutBasic .addAll (about );
67- aboutBasic .add (Text .empty ());
68- aboutBasic .add (Text . of (container .getMetadata ().getDescription ()));
70+ aboutBasic .add (Component .empty ());
71+ aboutBasic .add (Component . nullToEmpty (container .getMetadata ().getDescription ()));
6972
7073 var contributors = new ArrayList <String >();
7174 contributors .addAll (container .getMetadata ().getAuthors ().stream ().map (Person ::getName ).toList ());
7275 contributors .addAll (container .getMetadata ().getContributors ().stream ().map (Person ::getName ).toList ());
7376
74- about .add (Text .literal ("" )
75- .append (Text .translatable ("text.graves.about.contributors" )
76- .setStyle (Style .EMPTY .withColor (Formatting .AQUA )
77+ about .add (Component .literal ("" )
78+ .append (Component .translatable ("text.graves.about.contributors" )
79+ .setStyle (Style .EMPTY .withColor (ChatFormatting .AQUA )
7780 .withHoverEvent (new HoverEvent .ShowText (
78- Text .literal (String .join (", " , contributors )
81+ Component .literal (String .join (", " , contributors )
7982 ))
8083 )))
8184 .append ("" )
82- .setStyle (Style .EMPTY .withColor (Formatting .DARK_GRAY )));
83- about .add (Text .empty ());
85+ .setStyle (Style .EMPTY .withColor (ChatFormatting .DARK_GRAY )));
86+ about .add (Component .empty ());
8487
8588 var desc = new ArrayList <>(List .of (container .getMetadata ().getDescription ().split (" " )));
8689
@@ -90,21 +93,21 @@ public static void build(ModContainer container) {
9093 (descPart .isEmpty () ? descPart : descPart .append (" " )).append (desc .remove (0 ));
9194
9295 if (descPart .length () > 16 ) {
93- about .add (Text .literal (descPart .toString ()).setStyle (Style .EMPTY .withColor (Formatting .GRAY )));
96+ about .add (Component .literal (descPart .toString ()).setStyle (Style .EMPTY .withColor (ChatFormatting .GRAY )));
9497 descPart = new StringBuilder ();
9598 }
9699 }
97100
98101 if (descPart .length () > 0 ) {
99- about .add (Text .literal (descPart .toString ()).setStyle (Style .EMPTY .withColor (Formatting .GRAY )));
102+ about .add (Component .literal (descPart .toString ()).setStyle (Style .EMPTY .withColor (ChatFormatting .GRAY )));
100103 }
101104 }
102105
103106 if (icon .length > about .size () + 2 ) {
104107 int a = 0 ;
105108 for (int i = 0 ; i < icon .length ; i ++) {
106109 if (i == (icon .length - about .size () - 1 ) / 2 + a && a < about .size ()) {
107- output .add (icon [i ].copy ().append (Text .literal (" " ).setStyle (Style .EMPTY .withItalic (false )).append (about .get (a ++))));
110+ output .add (icon [i ].copy ().append (Component .literal (" " ).setStyle (Style .EMPTY .withItalic (false )).append (about .get (a ++))));
108111 } else {
109112 output .add (icon [i ]);
110113 }
@@ -115,26 +118,26 @@ public static void build(ModContainer container) {
115118 }
116119 } catch (Throwable e ) {
117120 e .printStackTrace ();
118- var invalid = Text .literal ("/!\\ [ Invalid about mod info ] /!\\ " ).setStyle (Style .EMPTY .withColor (0xFF0000 ).withItalic (true ));
121+ var invalid = Component .literal ("/!\\ [ Invalid about mod info ] /!\\ " ).setStyle (Style .EMPTY .withColor (0xFF0000 ).withItalic (true ));
119122
120123 output .add (invalid );
121124 about .add (invalid );
122125 }
123126
124- GenericModInfo .about = output .toArray (new Text [0 ]);
125- GenericModInfo .consoleAbout = aboutBasic .toArray (new Text [0 ]);
127+ GenericModInfo .about = output .toArray (new Component [0 ]);
128+ GenericModInfo .consoleAbout = aboutBasic .toArray (new Component [0 ]);
126129 }
127130 }
128131
129- public static Text [] getIcon () {
132+ public static Component [] getIcon () {
130133 return icon ;
131134 }
132135
133- public static Text [] getAboutFull () {
136+ public static Component [] getAboutFull () {
134137 return about ;
135138 }
136139
137- public static Text [] getAboutConsole () {
140+ public static Component [] getAboutConsole () {
138141 return consoleAbout ;
139142 }
140143}
0 commit comments