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/11/02 06:36] – [Adding Item textures] item/generated -> builtin/generated leocth2 | tutorial:items [2020/12/20 11:42] – Fixed some mistakes and changed some things 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 '' | + | 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 { | ||
Line 15: | Line 15: | ||
} | } | ||
</ | </ | ||
- | 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 '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
Line 28: | Line 28: | ||
} | } | ||
</ | </ | ||
- | Your new item has now been added to Minecraft. Run the `runClient` gradle | + | Your new item has now been added to Minecraft. Run the '' |
{{: | {{: | ||
Line 49: | Line 49: | ||
<code JavaScript> | <code JavaScript> | ||
{ | { | ||
- | " | + | " |
" | " | ||
" | " | ||
Line 73: | Line 73: | ||
</ | </ | ||
- | A practical use-case for a custom item class would be making the item play a sound when you right click with it: | + | A practical use-case for a custom item class would be making the item play a sound when you use it: |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class FabricItem extends Item { | public class FabricItem extends Item { | ||
Line 84: | Line 84: | ||
public TypedActionResult< | public TypedActionResult< | ||
playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, | playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, | ||
- | return | + | return TypedActionResult.success(playerEntity.getStackInHand(hand)); |
} | } | ||
} | } | ||
Line 106: | Line 106: | ||
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 FabricItemSettings().group(ItemGroup.MISC).maxCount(16)); | public static final FabricItem FABRIC_ITEM = new FabricItem(new FabricItemSettings().group(ItemGroup.MISC).maxCount(16)); | ||
[...] | [...] |
tutorial/items.txt · Last modified: 2024/06/17 12:49 by solidblock