1
1
package io .github .codecraftplugin .registrylib .utils ;
2
2
3
3
import net .fabricmc .fabric .api .item .v1 .FabricItemSettings ;
4
+ import net .fabricmc .fabric .api .itemgroup .v1 .FabricItemGroup ;
4
5
import net .fabricmc .fabric .api .itemgroup .v1 .ItemGroupEvents ;
5
6
import net .fabricmc .loader .api .FabricLoader ;
6
7
import net .minecraft .block .Block ;
11
12
import net .minecraft .entity .SpawnGroup ;
12
13
import net .minecraft .entity .effect .StatusEffect ;
13
14
import 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 .*;
18
16
import net .minecraft .registry .Registries ;
17
+ import net .minecraft .text .Text ;
19
18
import net .minecraft .util .Identifier ;
20
19
import org .slf4j .Logger ;
21
20
22
-
23
- public class Registry {
21
+ import java .util .function .Supplier ;
24
22
25
23
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
+ */
26
34
public static Item registerItems (String name , String MOD_ID , Item item , ItemGroup itemGroup ){
27
35
Item createditem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),item );
28
36
addToItemGroup (itemGroup ,createditem );
29
37
return createditem ;
30
38
}
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
+ */
31
47
public static Block registerBlocks (String name , String MOD_ID , Block block , ItemGroup itemGroup ){
32
48
registerBlockItem (name ,MOD_ID ,block ,itemGroup );
33
49
return net .minecraft .registry .Registry .register (Registries .BLOCK ,new Identifier (MOD_ID ,name ),block );
34
50
}
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
+ */
35
60
public static Item registerBlockItem (String name , String MOD_ID , Block block , ItemGroup itemGroup ) {
36
61
Item blockItem = net .minecraft .registry .Registry .register (Registries .ITEM ,new Identifier (MOD_ID ,name ),
37
62
new BlockItem (block ,new FabricItemSettings ()));
38
63
addToItemGroup (itemGroup ,blockItem );
39
64
return blockItem ;
40
65
}
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
+ }
41
78
//Adds Group to the items created
42
79
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
+ */
43
85
public static void addToItemGroup (ItemGroup group , Item item ) {
44
86
ItemGroupEvents .modifyEntriesEvent (group ).register (entries -> entries .add (item ));
45
87
}
@@ -56,7 +98,14 @@ public static Block registerBlocksWithoutBlockItem(String name, String MOD_ID, B
56
98
return net .minecraft .registry .Registry .register (Registries .BLOCK ,new Identifier (MOD_ID ,name ),block );
57
99
}
58
100
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
+ */
60
109
public static Enchantment registerEnchantments (String name , Enchantment enchantment , String MOD_ID ){
61
110
return net .minecraft .registry .Registry .register (Registries .ENCHANTMENT , new Identifier (MOD_ID , name ),enchantment );
62
111
@@ -88,10 +137,20 @@ public static EntityType registerEntity(String name,String MOD_ID, EntityType en
88
137
return net .minecraft .registry .Registry .register (Registries .ENTITY_TYPE , new Identifier (MOD_ID ,name ),entity );
89
138
}
90
139
//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
+ */
91
149
public static StatusEffect registerStatusEffects (String name ,String MOD_ID , StatusEffect statusEffect ){
92
150
return net .minecraft .registry .Registry .register (Registries .STATUS_EFFECT , new Identifier (MOD_ID , name ), statusEffect );
93
151
}
94
152
//register entities with spawn egg
153
+
95
154
public static <T extends Entity > EntityType <T > buildEntity (EntityType .EntityFactory <T > entity , Class <T > entityClass ,
96
155
float width , float height , SpawnGroup group , String MOD_ID ) {
97
156
if (FabricLoader .getInstance ().isDevelopmentEnvironment ()) {
0 commit comments