11package io .github .codecraftplugin .registrylib .utils ;
22
33import net .fabricmc .fabric .api .item .v1 .FabricItemSettings ;
4+ import net .fabricmc .fabric .api .itemgroup .v1 .FabricItemGroup ;
45import net .fabricmc .fabric .api .itemgroup .v1 .ItemGroupEvents ;
56import net .fabricmc .loader .api .FabricLoader ;
67import net .minecraft .block .Block ;
1112import net .minecraft .entity .SpawnGroup ;
1213import net .minecraft .entity .effect .StatusEffect ;
1314import net .minecraft .fluid .FlowableFluid ;
14- import net .minecraft .item .BlockItem ;
15- import net .minecraft .item .Item ;
16- import net .minecraft .item .ItemGroup ;
17- import net .minecraft .item .ItemGroups ;
15+ import net .minecraft .item .*;
1816import net .minecraft .registry .Registries ;
17+ import net .minecraft .text .Text ;
1918import net .minecraft .util .Identifier ;
2019import org .slf4j .Logger ;
2120
22-
23- public class Registry {
21+ import java .util .function .Supplier ;
2422
2523
24+ public class Registry {
25+ /**
26+ * Register items item.
27+ *
28+ * @param name the name of the item
29+ * @param MOD_ID the mod id of your mod
30+ * @param item the item settings
31+ * @param itemGroup the item group
32+ * @return the item will be created and returned
33+ */
2634 public static Item registerItems (String name , String MOD_ID , Item item , ItemGroup itemGroup ){
2735 Item createditem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),item );
2836 addToItemGroup (itemGroup ,createditem );
2937 return createditem ;
3038 }
39+ /**
40+ * Register items item.
41+ *
42+ * @param name the name of the item
43+ * @param MOD_ID the mod id of your mod
44+ * @param block the block settings
45+ * @return the block and the block item will be created and returned
46+ */
3147 public static Block registerBlocks (String name , String MOD_ID , Block block , ItemGroup itemGroup ){
3248 registerBlockItem (name ,MOD_ID ,block ,itemGroup );
3349 return net .minecraft .registry .Registry .register (Registries .BLOCK ,new Identifier (MOD_ID ,name ),block );
3450 }
51+
52+ /**
53+ *
54+ * @param name the name of the item
55+ * @param MOD_ID the Mod id of your mod
56+ * @param block the reference of the block this item is for
57+ * @param itemGroup the item group that the block item will be shown
58+ * @return the block item without creating the block (for crops)
59+ */
3560 public static Item registerBlockItem (String name , String MOD_ID , Block block , ItemGroup itemGroup ) {
3661 Item blockItem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),
3762 new BlockItem (block ,new FabricItemSettings ()));
3863 addToItemGroup (itemGroup ,blockItem );
3964 return blockItem ;
4065 }
66+
67+ /**
68+ *
69+ * @param name the name of the group make sure the name is same the name you want to be displayed in the game
70+ * @param MOD_ID the mod id of your mod
71+ * @param itemStack the item that you want to use as the icon as an item stack e.g. new ItemStack(Items.APPLE);
72+ * @return the item group
73+ */
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 ();
77+ }
4178 //Adds Group to the items created
4279
80+ /**
81+ * Add an item to an item group
82+ * @param group reference of the item Group
83+ * @param item reference of the item
84+ */
4385 public static void addToItemGroup (ItemGroup group , Item item ) {
4486 ItemGroupEvents .modifyEntriesEvent (group ).register (entries -> entries .add (item ));
4587 }
@@ -56,7 +98,14 @@ public static Block registerBlocksWithoutBlockItem(String name, String MOD_ID, B
5698 return net .minecraft .registry .Registry .register (Registries .BLOCK ,new Identifier (MOD_ID ,name ),block );
5799 }
58100
59- //register enchantments
101+ /**
102+ * Register enchantments enchantment.
103+ *
104+ * @param name the name of the enchantment
105+ * @param enchantment the enchantment settings
106+ * @param MOD_ID the mod id of your mod
107+ * @return the enchantment
108+ */
60109 public static Enchantment registerEnchantments (String name , Enchantment enchantment , String MOD_ID ){
61110 return net .minecraft .registry .Registry .register (Registries .ENCHANTMENT , new Identifier (MOD_ID , name ),enchantment );
62111
@@ -88,10 +137,20 @@ public static EntityType registerEntity(String name,String MOD_ID, EntityType en
88137 return net .minecraft .registry .Registry .register (Registries .ENTITY_TYPE , new Identifier (MOD_ID ,name ),entity );
89138 }
90139 //register status effects
140+
141+ /**
142+ * Register status effects status effect.
143+ *
144+ * @param name the name of the status effect / potion effect
145+ * @param MOD_ID the mod id of your mod
146+ * @param statusEffect the status effect settings
147+ * @return the status effect
148+ */
91149 public static StatusEffect registerStatusEffects (String name ,String MOD_ID , StatusEffect statusEffect ){
92150 return net .minecraft .registry .Registry .register (Registries .STATUS_EFFECT , new Identifier (MOD_ID , name ), statusEffect );
93151 }
94152 //register entities with spawn egg
153+
95154 public static <T extends Entity > EntityType <T > buildEntity (EntityType .EntityFactory <T > entity , Class <T > entityClass ,
96155 float width , float height , SpawnGroup group , String MOD_ID ) {
97156 if (FabricLoader .getInstance ().isDevelopmentEnvironment ()) {
0 commit comments