1414import net .minecraft .fluid .FlowableFluid ;
1515import net .minecraft .item .*;
1616import net .minecraft .registry .Registries ;
17+ import net .minecraft .registry .RegistryKey ;
18+ import net .minecraft .registry .RegistryKeys ;
1719import net .minecraft .text .Text ;
1820import net .minecraft .util .Identifier ;
1921import org .slf4j .Logger ;
@@ -31,7 +33,7 @@ public class Registry {
3133 * @param itemGroup the item group
3234 * @return the item will be created and returned
3335 */
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 ){
3537 Item createditem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),item );
3638 addToItemGroup (itemGroup ,createditem );
3739 return createditem ;
@@ -44,7 +46,7 @@ public static Item registerItems(String name, String MOD_ID, Item item, ItemGrou
4446 * @param block the block settings
4547 * @return the block and the block item will be created and returned
4648 */
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 ){
4850 registerBlockItem (name ,MOD_ID ,block ,itemGroup );
4951 return net .minecraft .registry .Registry .register (Registries .BLOCK ,new Identifier (MOD_ID ,name ),block );
5052 }
@@ -57,7 +59,7 @@ public static Block registerBlocks(String name, String MOD_ID, Block block, Item
5759 * @param itemGroup the item group that the block item will be shown
5860 * @return the block item without creating the block (for crops)
5961 */
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 ) {
6163 Item blockItem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),
6264 new BlockItem (block ,new FabricItemSettings ()));
6365 addToItemGroup (itemGroup ,blockItem );
@@ -71,9 +73,13 @@ public static Item registerBlockItem(String name, String MOD_ID, Block block, It
7173 * @param itemStack the item that you want to use as the icon as an item stack e.g. new ItemStack(Items.APPLE);
7274 * @return the item group
7375 */
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 ;
7783 }
7884 //Adds Group to the items created
7985
@@ -82,7 +88,7 @@ public static ItemGroup registerItemGroup(String name, String MOD_ID, Supplier<I
8288 * @param group reference of the item Group
8389 * @param item reference of the item
8490 */
85- public static void addToItemGroup (ItemGroup group , Item item ) {
91+ public static void addToItemGroup (RegistryKey < ItemGroup > group , Item item ) {
8692 ItemGroupEvents .modifyEntriesEvent (group ).register (entries -> entries .add (item ));
8793 }
8894 /**
@@ -175,5 +181,19 @@ public static <I extends Item> I registerEgg(I item, Identifier name) {
175181 }
176182 return null ;
177183 }
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+
179199}
0 commit comments