Item registry.
Creating a registry. 0.1>
In order to register items you will have to create a registry. To do this, you must use the following code within the init() function:
//This is the init() inside your main class.
public static void init() {
//Here we create the registry so we can use it later.
ItemRegistry.CreateRegistry(MOD_ID);
}
Creating a simple item. 0.1>
In order to register items you will have to create a registry, then create the item and finally register them all. I recommend that you separate each type of registry into a separate class, meaning, if you are going to register items, do it in a class separate from the others; this way, you can organize yourself more easily.
//This is another separate class from the initial one. I recommend you do this for organization.
public class ItemRegister {
//Here we create the item.
public static final RestItem item1 = ItemRegistry.CreateSimple(Testing.MOD_ID, "YOUR_ITEM_ID", YourCreativeTab);
/*
Parameters:
- Testing.MOD_ID = Your mod id as string.
- "YOUR_ITEM_ID" = Your item's id as string.
- YourCreativeTab = The creative tab where your item will appear or null. See how to register (LINK.creative tabs).
*/
//You can create a method/function like this to call it from the main class.
public static void register() {
//This registers all of your items into minecraft.
ItemRegistry.Register(Testing.MOD_ID);
}
}
//This is another separate class from the initial one. I recommend you do this for organization.
public class ItemRegister {
//Here we create the item.
public static final Object item1 = ItemRegistry.CreateSimple(Testing.MOD_ID, "YOUR_ITEM_ID", YourCreativeTab);
/*
Parameters:
- Testing.MOD_ID = Your mod id as string.
- "YOUR_ITEM_ID" = Your item's id as string.
- YourCreativeTab = The creative tab where your item will appear or null. See how to register (LINK.creative tabs).
*/
//You can create a method/function like this to call it from the main class.
public static void register() {
//This registers all of your items into minecraft.
ItemRegistry.Register(Testing.MOD_ID);
}
}
Creating a simple food item. 0.2>
To create a food item is almost the same as creating a simple item. The structure is as follows:
public class ItemRegister {
//Here we create the item.
public static final RestItem food_simple = ItemRegistry.CreateFood(
MOD_ID,
"YOUR_ITEM_ID",
YourCreativeTab,
1,
2.2f
);
/*
Parameters:
- MOD_ID = Your mod id as string.
- "YOUR_ITEM_ID" = Your item's id as string.
- YourCreativeTab = The creative tab where your item will appear or null. See how to register creative tabs.
- 1 = Nutrition value/Hunger points. Int.
- 2.2f = SaturationMod/Extra hunger points. Float.
*/
public static void register() {
ItemRegistry.Register(Testing.MOD_ID);
}
}
public class ItemRegister {
//Here we create the item.
public static final Object food_simple = ItemRegistry.CreateFood(
MOD_ID,
"YOUR_ITEM_ID",
YourCreativeTab,
1,
2.2f
);
/*
Parameters:
- MOD_ID = Your mod id as string.
- "YOUR_ITEM_ID" = Your item's id as string.
- YourCreativeTab = The creative tab where your item will appear or null. See how to register creative tabs.
- 1 = Nutrition value/Hunger points. Int.
- 2.2f = SaturationMod/Extra hunger points. Float.
*/
public static void register() {
ItemRegistry.Register(Testing.MOD_ID);
}
}
Creating a food item with effects. 0.2>
To create a food item that has a certain probability of giving you an effect, you can do the following
public class ItemRegister {
//Here we create the effect.
public static final MobEffectInstance effect = ItemRegistry.CreateExistingEffect(
MobEffects.GLOWING,
20*60*2,
1
);
/*
Parameters:
- MobEffects.GLOWING = The effect type.
- 20*60*2 = The duration in ticks.
- 1 = Power/level of the effect.
*/
//Here we create the item.
public static final RestItem food_effect = ItemRegistry.CreateFoodWithEffect(
MOD_ID,
"YOUR_ITEM_ID",
YourCreativeTab,
1,
2,
effect,
1
);
/*
Parameters:
- MOD_ID = Your mod id as string.
- "YOUR_ITEM_ID" = Your item's id as string.
- YourCreativeTab = The creative tab where your item will appear or null. See how to register creative tabs.
- 1 = Nutrition value/Hunger points. Int.
- 2 = SaturationMod/Extra hunger points. Float.
- effect = The effect you created before.
- 1 = The chances of getting the effect. Float. 0 = 0%, 0.5 = 50%, 1 = 100%.
*/
public static void register() {
ItemRegistry.Register(Testing.MOD_ID);
}
}
public class ItemRegister {
//Here we create the effect.
public static final MobEffectInstance effect = (MobEffectInstance) ItemRegistry.CreateExistingEffect(
MobEffects.GLOWING,
20*60*2,
1
);
/*
Parameters:
- MobEffects.GLOWING = The effect type.
- 20*60*2 = The duration in ticks.
- 1 = Power/level of the effect.
*/
//Here we create the item.
public static final Object food_effect = ItemRegistry.CreateFoodWithEffect(
MOD_ID,
"YOUR_ITEM_ID",
YourCreativeTab,
1,
2,
effect,
1
);
/*
Parameters:
- MOD_ID = Your mod id as string.
- "YOUR_ITEM_ID" = Your item's id as string.
- YourCreativeTab = The creative tab where your item will appear or null. See how to register creative tabs.
- 1 = Nutrition value/Hunger points. Int.
- 2 = SaturationMod/Extra hunger points. Float.
- effect = The effect you created before.
- 1 = The chances of getting the effect. Float. 0 = 0%, 0.5 = 50%, 1 = 100%.
*/
public static void register() {
ItemRegistry.Register(Testing.MOD_ID);
}
}
Creating a custom item. Best method 0.5>
In this function, you can create a complex item more easily. You can create an item with a custom class that extends the Item class.
public class ItemRegister {
//Here we create the item.
public static final RestItem CustomItem = ItemRegistry.CreateCustom(
Variables.modID,
"ITEM_ID",
() -> new CustomPickaxeItem(
new CustomToolTier(750, 7, 3, 5, 15, ItemsRegistry.ITEM_USED_TO_REPAIR), //See (LINK.CustomToolTier)
1,
1,
new CustomItemProperties().tab(CreativeTabsRegistry.main).build() //See (LINK.CustomItemProperties)
)
);
/*
Parameters:
- Variables.modID = Your mod id as string.
- "ITEM_ID" = Your item's id as string.
- Custom class in a supplier. You can create a custom class or use a vanilla one. "() ->" is the supplier thing, it's a java thing.
*/
public static void register() {
ItemRegistry.Register(Testing.MOD_ID);
}
}
public class ItemRegister {
//Here we create the item.
public static final Object CustomItem = ItemRegistry.CreateCustom(
Variables.modID,
"ITEM_ID",
() -> new CustomPickaxeItem(
new CustomToolTier(750, 7, 3, 5, 15, ItemsRegistry.ITEM_USED_TO_REPAIR), //See (LINK.CustomToolTier)
1,
1,
new CustomItemProperties().tab(CreativeTabsRegistry.main).build() //See (LINK.CustomItemProperties)
)
);
/*
Parameters:
- Variables.modID = Your mod id as string.
- "ITEM_ID" = Your item's id as string.
- Custom class in a supplier. You can create a custom class or use a vanilla one. "() ->" is the supplier thing, it's a java thing.
*/
public static void register() {
ItemRegistry.Register(Testing.MOD_ID);
}
}
Here is an example of a custom class that extends the PickaxeItem class, which, in turn, extends the Item class.
public class CustomPickaxeItem extends PickaxeItem {
public CustomPickaxeItem(Tier tier, int i, float f, Properties properties) {
super(tier, i, f, properties);
}
}