14
14
import net .minecraft .fluid .FlowableFluid ;
15
15
import net .minecraft .item .*;
16
16
import net .minecraft .registry .Registries ;
17
+ import net .minecraft .registry .RegistryKey ;
18
+ import net .minecraft .registry .RegistryKeys ;
17
19
import net .minecraft .text .Text ;
18
20
import net .minecraft .util .Identifier ;
19
21
import org .slf4j .Logger ;
@@ -31,7 +33,7 @@ public class Registry {
31
33
* @param itemGroup the item group
32
34
* @return the item will be created and returned
33
35
*/
34
- public static Item registerItems (String name , String MOD_ID , Item item , ItemGroup itemGroup ){
36
+ public static Item registerItems (String name , String MOD_ID , Item item , RegistryKey < ItemGroup > itemGroup ){
35
37
Item createditem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),item );
36
38
addToItemGroup (itemGroup ,createditem );
37
39
return createditem ;
@@ -44,7 +46,7 @@ public static Item registerItems(String name, String MOD_ID, Item item, ItemGrou
44
46
* @param block the block settings
45
47
* @return the block and the block item will be created and returned
46
48
*/
47
- public static Block registerBlocks (String name , String MOD_ID , Block block , ItemGroup itemGroup ){
49
+ public static Block registerBlocks (String name , String MOD_ID , Block block , RegistryKey < ItemGroup > itemGroup ){
48
50
registerBlockItem (name ,MOD_ID ,block ,itemGroup );
49
51
return net .minecraft .registry .Registry .register (Registries .BLOCK ,new Identifier (MOD_ID ,name ),block );
50
52
}
@@ -57,7 +59,7 @@ public static Block registerBlocks(String name, String MOD_ID, Block block, Item
57
59
* @param itemGroup the item group that the block item will be shown
58
60
* @return the block item without creating the block (for crops)
59
61
*/
60
- public static Item registerBlockItem (String name , String MOD_ID , Block block , ItemGroup itemGroup ) {
62
+ public static Item registerBlockItem (String name , String MOD_ID , Block block , RegistryKey < ItemGroup > itemGroup ) {
61
63
Item blockItem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),
62
64
new BlockItem (block ,new FabricItemSettings ()));
63
65
addToItemGroup (itemGroup ,blockItem );
@@ -71,9 +73,13 @@ public static Item registerBlockItem(String name, String MOD_ID, Block block, It
71
73
* @param itemStack the item that you want to use as the icon as an item stack e.g. new ItemStack(Items.APPLE);
72
74
* @return the item group
73
75
*/
74
- public static ItemGroup registerItemGroup (String name , String MOD_ID , Supplier <ItemStack > itemStack ){
75
- String formattedName = name .substring (0 , 1 ).toUpperCase () + name .substring (1 ).toLowerCase ();
76
- return FabricItemGroup .builder (new Identifier (MOD_ID ,name )).displayName (Text .literal (formattedName )).icon (itemStack ).build ();
76
+ public static RegistryKey <ItemGroup > registerItemGroup (String name , String MOD_ID , Supplier <ItemStack > itemStack ){
77
+ String displayName = formatString (name );
78
+ RegistryKey <ItemGroup > customItemGroup = RegistryKey .of (RegistryKeys .ITEM_GROUP ,new Identifier (MOD_ID ,name ));
79
+ net .minecraft .registry .Registry .register (Registries .ITEM_GROUP , customItemGroup , FabricItemGroup .builder ()
80
+ .icon (itemStack ).displayName (Text .literal (displayName )).build ());
81
+
82
+ return customItemGroup ;
77
83
}
78
84
//Adds Group to the items created
79
85
@@ -82,7 +88,7 @@ public static ItemGroup registerItemGroup(String name, String MOD_ID, Supplier<I
82
88
* @param group reference of the item Group
83
89
* @param item reference of the item
84
90
*/
85
- public static void addToItemGroup (ItemGroup group , Item item ) {
91
+ public static void addToItemGroup (RegistryKey < ItemGroup > group , Item item ) {
86
92
ItemGroupEvents .modifyEntriesEvent (group ).register (entries -> entries .add (item ));
87
93
}
88
94
/**
@@ -175,5 +181,19 @@ public static <I extends Item> I registerEgg(I item, Identifier name) {
175
181
}
176
182
return null ;
177
183
}
178
-
184
+
185
+ private static String formatString (String input ) {
186
+ String [] words = input .split ("_" );
187
+ StringBuilder result = new StringBuilder ();
188
+
189
+ for (String word : words ) {
190
+ if (!word .isEmpty ()) {
191
+ String formattedWord = word .substring (0 , 1 ).toUpperCase () + word .substring (1 ).toLowerCase ();
192
+ result .append (formattedWord ).append (" " );
193
+ }
194
+ }
195
+
196
+ return result .toString ().trim ();
197
+ }
198
+
179
199
}
0 commit comments