tutorial:items
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:items [2022/04/29 09:34] – [What if I want to change the stack size of my item?] solidblock | tutorial:items [2022/12/18 04:09] – Include command to give newly created item, and syntax formatting on the same line. m4x | ||
---|---|---|---|
Line 4: | Line 4: | ||
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 ''< | ||
+ | |||
==== Registering an Item ==== | ==== Registering an Item ==== | ||
- | First, create an instance of <yarn class_1792> | + | First, create an instance of <yarn class_1792> |
< | < | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
// an instance of our new item | // an instance of our new item | ||
- | public static final class_1792 | + | public static final class_1792 |
[...] | [...] | ||
} | } | ||
</ | </ | ||
- | 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 ''< | ||
< | < | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
// an instance of our new item | // an instance of our new item | ||
- | public static final class_1792 | + | public static final class_1792 |
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
- | class_2378.method_10230(class_2378.field_11142, new class_2960(" | + | class_2378.method_10230(class_7923.field_41178, new class_2960(" |
} | } | ||
} | } | ||
</ | </ | ||
- | Your new item has now been added to Minecraft. Run the '' | + | Your new item has now been added to Minecraft. Run the run config '' |
{{: | {{: | ||
+ | |||
+ | For simplicity, you can simplify your code as following: | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | |||
+ | // an instance of our new item | ||
+ | public static final class_1792 CUSTOM_ITEM = | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | new class_1792(new FabricItemSettings())); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== Adding Item textures ==== | ==== Adding Item textures ==== | ||
- | Registering a texture for an item requires an item model .json file and a texture image. You're going to need to add these to your resource directory. The direct path of each is: | + | Registering a texture for an item requires an item model json file and a texture image. You're going to need to add these to your resource directory. The direct path of each is: |
- | Item model: .../ | + | Item model: .../ |
- | Item texture: .../ | + | Item texture: .../ |
Our example texture can be found [[https:// | Our example texture can be found [[https:// | ||
Line 43: | Line 62: | ||
If you registered your item properly in the first step, your game will complain about a missing texture file in a fashion similar to this: | If you registered your item properly in the first step, your game will complain about a missing texture file in a fashion similar to this: | ||
- | [Server-Worker-1/ | + | [Server-Worker-1/ |
It conveniently tells you exactly where it expects your asset[s] to be found-- when in doubt, check the log. | It conveniently tells you exactly where it expects your asset[s] to be found-- when in doubt, check the log. | ||
Line 51: | Line 70: | ||
" | " | ||
" | " | ||
- | " | + | " |
} | } | ||
} | } | ||
Line 65: | Line 84: | ||
To add additional behavior to the item you will need to create an Item class. The default constructor requires an Item.Settings object. | To add additional behavior to the item you will need to create an Item class. The default constructor requires an Item.Settings object. | ||
< | < | ||
- | public class FabricItem | + | public class CustomItem |
- | public | + | public |
super(settings); | super(settings); | ||
} | } | ||
Line 75: | Line 94: | ||
A practical use-case for a custom item class would be making the item play a sound when you use it: | A practical use-case for a custom item class would be making the item play a sound when you use it: | ||
< | < | ||
- | public class FabricItem | + | public class CustomItem |
- | public | + | public |
super(settings); | super(settings); | ||
} | } | ||
Line 94: | Line 113: | ||
// an instance of our new item | // an instance of our new item | ||
- | public static final FabricItem FABRIC_ITEM | + | public static final CustomItem CUSTOM_ITEM |
[...] | [...] | ||
} | } | ||
Line 107: | Line 126: | ||
// 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 FabricItem FABRIC_ITEM | + | public static final CustomItem CUSTOM_ITEM |
[...] | [...] | ||
} | } | ||
Line 122: | Line 141: | ||
public void onInitialize() { | public void onInitialize() { | ||
[...] | [...] | ||
- | FuelRegistry.INSTANCE.add(FABRIC_ITEM, 300) | + | FuelRegistry.INSTANCE.add(CUSTOM_ITEM, 300) |
} | } | ||
} | } |
tutorial/items.txt · Last modified: 2024/04/20 08:05 by ryhon