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
tutorial:items [2025/03/25 00:47] solidblocktutorial:items [2025/04/01 08:57] (current) – [Adding model, texture and model mapping] solidblock
Line 128: Line 128:
 In the method ''Items.register'', the registry key will be written in the ''settings'' first, and then use that ''settings'' to create the item. In the method ''Items.register'', the registry key will be written in the ''settings'' first, and then use that ''settings'' to create the item.
  
-===== Adding model and textures =====+===== Adding model, texture and model definition =====
  
 If you registered your item properly in the first step, you can successfully get your item by typing command ''/give @s tutorial:custom_item''. You will find it has missing texture, and Minecraft will complain about a missing texture file in a fashion similar to this: If you registered your item properly in the first step, you can successfully get your item by typing command ''/give @s tutorial:custom_item''. You will find it has missing texture, and Minecraft will complain about a missing texture file in a fashion similar to this:
Line 134: Line 134:
     [Server-Worker-1/WARN]: Unable to load model: 'tutorial:custom_item#inventory' referenced from: tutorial:custom_item#inventory: java.io.FileNotFoundException: tutorial:models/item/custom_item.json     [Server-Worker-1/WARN]: Unable to load model: 'tutorial:custom_item#inventory' referenced from: tutorial:custom_item#inventory: java.io.FileNotFoundException: tutorial:models/item/custom_item.json
  
-That's because we haven't provided the item with textures and modelsTherefore, you need to define the item model json and provide a texture image. You're going to need to add these to your resource directory. The direct path of each is:+That's because we haven't provided the item with **textures**, **baked models** (we call them "models" for short) and **model definition** (also called model mapping)Those files are located in the following places respectively:
  
   * Item model: ''.../resources/assets/tutorial/models/item/custom_item.json''   * Item model: ''.../resources/assets/tutorial/models/item/custom_item.json''
   * Item texture: ''.../resources/assets/tutorial/textures/item/custom_item.png''   * Item texture: ''.../resources/assets/tutorial/textures/item/custom_item.png''
 +  * Item model definition (since 1.21.4): ''.../resources/assets/tutorial/items/custom_item.json''
  
 Our example texture can be found [[https://i.imgur.com/CqLSMEQ.png|here]]. Our example texture can be found [[https://i.imgur.com/CqLSMEQ.png|here]].
  
 A basic item model template is: A basic item model template is:
-<code JavaScript>+<code JavaScript /resources/assets/tutorial/models/item/custom_item.json>
 { {
   "parent": "item/generated",   "parent": "item/generated",
Line 151: Line 152:
 </code> </code>
 The ''parent'' of your item model changes how it's rendered in the hand and comes in useful for things like block items in the inventory. ''item/generated'' is used for many simple items. ''item/handheld'' is used for tools that are held from the bottom left of the texture. In the json, ''textures/layer0'' is the location of your image file. The ''parent'' of your item model changes how it's rendered in the hand and comes in useful for things like block items in the inventory. ''item/generated'' is used for many simple items. ''item/handheld'' is used for tools that are held from the bottom left of the texture. In the json, ''textures/layer0'' is the location of your image file.
 +
 +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 /resources/assets/tutorial/items/custom_item.json>
 +{
 +  "model": {
 +    "type": "model",
 +    "model": "tutorial:item/custom_item"
 +  }
 +}
 +</code>
 +
 +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 211: Line 226:
     public static final CustomItem CUSTOM_ITEM = register("custom_item", new CustomItem(new class_1792.class_1793()     public static final CustomItem CUSTOM_ITEM = register("custom_item", new CustomItem(new class_1792.class_1793()
         .component(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true))));         .component(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true))));
-    // For versions since 1.21.2:+         
 +    // For versions since 1.21.2, before 1.21.4:
     public static final Item CUSTOM_ITEM = register("custom_item", CustomItem::new, new Item.Settings()     public static final Item CUSTOM_ITEM = register("custom_item", CustomItem::new, new Item.Settings()
         .component(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)));         .component(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)));
 +        
 +    // For versions since 1.21.4:
 +    public static final Item CUSTOM_ITEM = register("custom_item", CustomItem::new, new Item.Settings()
 +        .component(DataComponentTypes.UNBREAKABLE, Unit.INSTANCE));
 </yarncode> </yarncode>
  
Line 224: Line 244:
     // For versions below 1.21.2:     // For versions below 1.21.2:
     public static final CustomItem CUSTOM_ITEM = register("custom_item", new CustomItem(new class_1792.class_1793().maxCount(16)));     public static final CustomItem CUSTOM_ITEM = register("custom_item", new CustomItem(new class_1792.class_1793().maxCount(16)));
 +    
     // For versions since 1.21.2:     // For versions since 1.21.2:
     public static final Item CUSTOM_ITEM = register("custom_item", CustomItem::new, new Item.Settings().maxCount(16));     public static final Item CUSTOM_ITEM = register("custom_item", CustomItem::new, new Item.Settings().maxCount(16));
Line 290: Line 311:
 Similarly, you can use a ''CompostingChanceRegistry'' to make it compostable in a composter. Similarly, you can use a ''CompostingChanceRegistry'' to make it compostable in a composter.
 ===== Next Steps ===== ===== Next Steps =====
-[[tutorial:itemgroup|Add your item to your own ItemGroup]].+Try [[itemgroup|adding your item to an item group]]. Your item also does not have a name, so you can also [[lang|learn how to add language files]].
tutorial/items.1742863622.txt.gz · Last modified: 2025/03/25 00:47 by solidblock