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 [2020/06/09 23:42] – draylar | tutorial:items [2020/09/23 08:33] – Change Item.Settings to FabricItemSettings because it exists ytg1234 | ||
---|---|---|---|
Line 6: | Line 6: | ||
==== Registering an Item ==== | ==== Registering an Item ==== | ||
- | First, create an instance of Item. We'll store it at the top of our initializer class. The constructor takes in an Item.Settings object, which is used to set item properties such as the inventory category, durability, and stack count. | + | First, create an instance of Item. We'll store it at the top of our initializer class. The constructor takes in an '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
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 Item FABRIC_ITEM = new Item(new | + | public static final Item FABRIC_ITEM = new Item(new |
[...] | [...] | ||
} | } | ||
Line 20: | Line 20: | ||
// an instance of our new item | // an instance of our new item | ||
- | public static final Item FABRIC_ITEM = new Item(new | + | public static final Item FABRIC_ITEM = new Item(new |
| | ||
@Override | @Override | ||
Line 73: | Line 73: | ||
</ | </ | ||
- | A practical use-case for a custom item class would be making the item play a sound when you click with it: | + | A practical use-case for a custom item class would be making the item play a sound when you right click with it: |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class FabricItem extends Item { | public class FabricItem extends Item { | ||
Line 94: | Line 94: | ||
// an instance of our new item | // an instance of our new item | ||
- | public static final FabricItem FABRIC_ITEM = new FabricItem(new | + | public static final FabricItem FABRIC_ITEM = new FabricItem(new |
[...] | [...] | ||
} | } | ||
Line 102: | Line 102: | ||
==== What if I want to change the stack size of my item? ==== | ==== What if I want to change the stack size of my item? ==== | ||
- | For this you would use '' | + | For this you would use '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
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 FabricItem FABRIC_ITEM = new FabricItem(new | + | public static final FabricItem FABRIC_ITEM = new FabricItem(new |
[...] | [...] | ||
} | } |
tutorial/items.txt · Last modified: 2024/04/20 08:05 by ryhon