User Tools

Site Tools


tutorial:items

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:items [2020/11/02 06:36] – [Adding Item textures] item/generated -> builtin/generated leocth2tutorial: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 ''Item.Settings'' (or a ''FabricItemSettings''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 ''Item.Settings'' (or a ''FabricItemSettings''instance, which is used to set item properties such as the inventory category, durability, and stack count. 
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
Line 15: Line 15:
 } }
 </code> </code>
-You'll use the vanilla registry system for registering new content. The basic syntax is ''Registry#register(Registry Type, Identifier, Content)''. Registry types are stored as static fields in the ''Registry'' object, and the identifier is what labels your content. Content is an instance of whatever you're adding. This can be called anywhere as long as it occurs during initialization.+You'll use the vanilla registry system for registering new content. The basic syntax is ''Registry#register(Registry Type, Identifier, Content)''. Registry types are stored as static fields in the ''Registry'' class, and the identifier is what labels your content. Content is an instance of whatever you're adding. This can be called anywhere as long as it occurs during initialization.
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
Line 28: Line 28:
 } }
 </code> </code>
-Your new item has now been added to Minecraft. Run the `runClient` gradle task to see it in action.+Your new item has now been added to Minecraft. Run the ''runClient'' Gradle task to see it in action.
  
 {{:tutorial:2019-02-17_16.50.44.png?400|}} {{:tutorial:2019-02-17_16.50.44.png?400|}}
Line 49: Line 49:
 <code JavaScript> <code JavaScript>
 { {
-  "parent": "builtin/generated",+  "parent": "item/generated",
   "textures": {   "textures": {
     "layer0": "tutorial:item/fabric_item"     "layer0": "tutorial:item/fabric_item"
Line 73: Line 73:
 </code> </code>
  
-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="true"]> <code java [enable_line_numbers="true"]>
 public class FabricItem extends Item { public class FabricItem extends Item {
Line 84: Line 84:
     public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {     public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
         playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, 1.0F, 1.0F);         playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, 1.0F, 1.0F);
-        return new TypedActionResult<>(ActionResult.SUCCESS, playerEntity.getStackInHand(hand));+        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