tutorial:items
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:items [2024/10/27 14:37] – [Make your item become fuel, or compostable] solidblock | tutorial:items [2025/04/01 08:57] (current) – [Adding model, texture and model mapping] solidblock | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| Adding a basic item is one of the first steps in modding. You're going to need to create an ''< | Adding a basic item is one of the first steps in modding. You're going to need to create an ''< | ||
| - | ===== Create an Item instance ===== | + | ===== Create an Item instance |
| :!: If you're in version 1.21.2 or above, please directly read [[#Creating Items in 1.21.2+]]. | :!: If you're in version 1.21.2 or above, please directly read [[#Creating Items in 1.21.2+]]. | ||
| Line 25: | Line 25: | ||
| </ | </ | ||
| - | ===== Register the item ===== | + | ===== Register the item (before 1.21.2) |
| We've create a basic item, but it still does not exist in Minecraft, because it has not been registered. In Minecraft, almost everything has an registry, and items are no exceptions. | We've create a basic item, but it still does not exist in Minecraft, because it has not been registered. In Minecraft, almost everything has an registry, and items are no exceptions. | ||
| - | You'll use the vanilla registry system for registering new content. The basic syntax is ''< | + | You'll use the vanilla registry system for registering new content. The basic syntax is ''< |
| For versions since 1.21, an '' | For versions since 1.21, an '' | ||
| Line 64: | Line 64: | ||
| </ | </ | ||
| - | ===== Best practice of registering items ===== | + | ===== Best practice of registering items (before 1.21.2) |
| In the code above, you simply created //one// item. However, it is not convenient if you have //many// items in your mod, as you need to register and create an '' | In the code above, you simply created //one// item. However, it is not convenient if you have //many// items in your mod, as you need to register and create an '' | ||
| Line 128: | Line 128: | ||
| In the method '' | In the method '' | ||
| - | ===== Adding model and textures | + | ===== Adding model, texture |
| If you registered your item properly in the first step, you can successfully get your item by typing command ''/ | If you registered your item properly in the first step, you can successfully get your item by typing command ''/ | ||
| Line 134: | Line 134: | ||
| [Server-Worker-1/ | [Server-Worker-1/ | ||
| - | That's because we haven' | + | That's because we haven' |
| * Item model: '' | * Item model: '' | ||
| * Item texture: '' | * Item texture: '' | ||
| + | * Item model definition (since 1.21.4): '' | ||
| Our example texture can be found [[https:// | Our example texture can be found [[https:// | ||
| A basic item model template is: | A basic item model template is: | ||
| - | <code JavaScript> | + | <code JavaScript |
| { | { | ||
| " | " | ||
| Line 151: | Line 152: | ||
| </ | </ | ||
| The '' | The '' | ||
| + | |||
| + | An item model definition is also needed since 1.21.4 (not needed before 1.21.4), of which the content may be: | ||
| + | <code javascript / | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | The item model definition will define the item model that the item uses. | ||
| + | |||
| + | > :!: Creating these files manually for each item can be tiring. You may refer to [[datagen_model]] for data generation. | ||
| ===== Creating an Item class ===== | ===== Creating an Item class ===== | ||
| Line 204: | Line 219: | ||
| ===== Item components ===== | ===== Item components ===== | ||
| - | Sometimes you may need to add some default components for the item, such as max stack size or fire durability. This can be done by calling '' | + | Sometimes you may need to add some default components for the item, such as max stack size or fire durability. This can be done by calling '' |
| In this example, the item will be unbreakable by default, while hiding tooltips about it. | In this example, the item will be unbreakable by default, while hiding tooltips about it. | ||
| < | < | ||
| - | public static final CustomItem CUSTOM_ITEM = new CustomItem(new class_1792.class_1793().component(DataComponentTypes.UNBREAKABLE, | + | |
| + | | ||
| + | | ||
| + | |||
| + | // For versions since 1.21.2, before 1.21.4: | ||
| + | public static final Item CUSTOM_ITEM = register(" | ||
| + | .component(DataComponentTypes.UNBREAKABLE, | ||
| + | |||
| + | // For versions since 1.21.4: | ||
| + | public static final Item CUSTOM_ITEM = register(" | ||
| + | .component(DataComponentTypes.UNBREAKABLE, | ||
| </ | </ | ||
| - | Specifically, | + | Specifically, |
| < | < | ||
| public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
| - | |||
| // An instance of our new item, where the maximum stack size is 16 | // An instance of our new item, where the maximum stack size is 16 | ||
| - | public static final CustomItem CUSTOM_ITEM = new CustomItem(new class_1792.class_1793().maxCount(16)); | + | |
| + | // For versions below 1.21.2: | ||
| + | | ||
| + | |||
| + | // For versions since 1.21.2: | ||
| + | public static final Item CUSTOM_ITEM = register(" | ||
| [...] | [...] | ||
| } | } | ||
| Line 281: | Line 311: | ||
| Similarly, you can use a '' | Similarly, you can use a '' | ||
| ===== Next Steps ===== | ===== Next Steps ===== | ||
| - | [[tutorial:itemgroup|Add your item to your own ItemGroup]]. | + | Try [[itemgroup|adding |
tutorial/items.1730039840.txt.gz · Last modified: 2024/10/27 14:37 by solidblock