User Tools

Site Tools


tutorial:armor

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:armor [2023/08/20 10:19] – [Texturing] wjz_ptutorial:armor [2024/07/04 16:32] (current) mineblock11
Line 1: Line 1:
 +~~REDIRECT>https://docs.fabricmc.net/develop/items/custom-armor~~
 +
 ====== Adding Armor ====== ====== Adding Armor ======
  
-==== Introduction ====+===== Introduction =====
  
 While armor is a bit more complicated to implement than a normal block or item, once you understand it, it becomes simple to implement. To add armor, we'll first make a CustomArmorMaterial class, then register the items. We'll also take a look at how to texture them. There's a special chapter at the end of this document that explains how to add knockback to the armor, since the method is only accessible through a mixin (as of 1.16.3). While armor is a bit more complicated to implement than a normal block or item, once you understand it, it becomes simple to implement. To add armor, we'll first make a CustomArmorMaterial class, then register the items. We'll also take a look at how to texture them. There's a special chapter at the end of this document that explains how to add knockback to the armor, since the method is only accessible through a mixin (as of 1.16.3).
Line 7: Line 9:
 An example for this document can be found in [[https://github.com/gdude2002/Gilded-Netherite|this mod GitHub repository]].  An example for this document can be found in [[https://github.com/gdude2002/Gilded-Netherite|this mod GitHub repository]]. 
  
-==== Creating an Armor Material class ====+===== Creating an Armor Material class =====
  
 Since new armor needs to be set with a new name (as well as extra things like armor points and durability), we'll have to create a new class for our CustomArmorMaterial.  Since new armor needs to be set with a new name (as well as extra things like armor points and durability), we'll have to create a new class for our CustomArmorMaterial. 
Line 90: Line 92:
 Now that you have the basics of the armor material class, let's register your armor items in a new class we'll simply call RegisterItems. Now that you have the basics of the armor material class, let's register your armor items in a new class we'll simply call RegisterItems.
  
-==== Creating Armor Items ====+===== Creating Armor Items =====
  
-We're gonna make new class called RegisterItems to implement your new armor pieces. This will also be the place to, for example, register tools, if you're making a new item like an ingot (We'll refer to this as a "Custom_Material").+In the [[item]] tutorial, we've created a class ''TutorialItems'' for items in the mod. Here we place them hereand use the convenient ''register'' method we've introducted in the [[item]] tutorial.
  
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
-public class RegisterItems +public final class TutorialItems 
 +    // [...] 
 +    
     public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial();     public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial();
-    public static final class_1792 CUSTOM_MATERIAL = new CustomMaterialItem(new class_1792.class_1793());+    public static final class_1792 CUSTOM_MATERIAL = register(new CustomMaterialItem(new class_1792.class_1793()), "custom_material");
     // If you made a new material, this is where you would note it.     // If you made a new material, this is where you would note it.
-    public static final class_1792 CUSTOM_MATERIAL_HELMET = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6169, new class_1792.class_1793()); +    public static final class_1792 CUSTOM_MATERIAL_HELMET = register(new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6169, new class_1792.class_1793()), "custom_material_helmet"); 
-    public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6174, new class_1792.class_1793()); +    public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = register(new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6174, new class_1792.class_1793()), "custom_material_chestplate"); 
-    public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6172, new class_1792.class_1793()); +    public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = register(new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6172, new class_1792.class_1793()), "custom_material_leggings"); 
-    public static final class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6166, new class_1792.class_1793());+    public static final class_1792 CUSTOM_MATERIAL_BOOTS = register(new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6166, new class_1792.class_1793()), "custom_material_boots");
  
 } }
 </yarncode> </yarncode>
  
-Now that your items are properly created, let's register them and give them proper namesYour first parameter is going to be your namespace, which is your mod ID, and then next one the name you want to give to your item. +Your armor items are doneNow we'll just create a separate [[itemgroup|item group]] for that.
- +
-We'll be writing this right below your last <yarn class_1738>.+
  
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
-public static void register() +public final class TutorialItemGroups 
-    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material")CUSTOM_MATERIAL); +    public static final class_1761 TEST_GROUP = FabricItemGroup.builder(
-    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_helmet"), CUSTOM_MATERIAL_HELMET); +        .icon(() -> new class_1799(TutorialItems.CUSTOM_MATERIAL)) // This uses the model of the new material you created as an icon, but you can reference to whatever you like 
-    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_chestplate")CUSTOM_MATERIAL_CHESTPLATE); +        .displayName(Text.translatable("itemGroup.tutorial.test_group")
-    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_leggings"), CUSTOM_MATERIAL_LEGGINGS); +        .entries((contextentries-> { 
-    class_2378.method_10230(class_7923.field_41178new class_2960("tutorial", "custom_material_boots"), CUSTOM_MATERIAL_BOOTS);+            entries.add(CUSTOM_MATERIAL) 
 +                .add(CUSTOM_MATERIAL_HELMET) 
 +                .add(CUSTOM_MATERIAL_CHESTPLATE) 
 +                .add(CUSTOM_MATERIAL_LEGGINGS) 
 +                .add(CUSTOM_MATERIAL_BOOTS)
 +        }) 
 +        .build(); 
 +         
 +    public static void initialize() { 
 +        // Since 1.21: 
 +        Registry.register(Registries.ITEM_GROUPIdentifier.of("tutorial", "test_group"), ITEM_GROUP); 
 +    }
 } }
 </yarncode> </yarncode>
  
-Your armor items are done. Now we'll just call the Registry on our main class (and annotate the new group). +If you did those above in the separate classes, remember to statically initialize the classes in your ''ModInitializer'', if you haven't done yet: 
- +<code java> 
-<yarncode java [enable_line_numbers="true"]+public class ExampleMod implements ModInitializer { 
-public static final class_1761 EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create( +    [...] 
-    new class_2960("tutorial", "example_mod_group")) +  
-    .icon(() -> new class_1799(RegisterItems.CUSTOM_MATERIAL)) // This uses the model of the new material you created as an icon, but you can reference to whatever you like +    @Override 
-    .build(); +    public void onInitialize() { 
- +        TutorialItems.initialize(); 
-@Override +        TUtorialItemGroups.initialize(); 
-public void onInitialize() { +    }
-    RegisterItems.register();+
 } }
-</yarncode> +</code>
 That's it! Your armor should now exist in game, untextured still, but present and able to be given with /give. That's it! Your armor should now exist in game, untextured still, but present and able to be given with /give.
  
 Now we'll be assigning the textures to each piece. Now we'll be assigning the textures to each piece.
- 
- 
  
 ==== Texturing ==== ==== Texturing ====
  
 We're going to assume you We're going to assume you
-  * Have the textures for each armor item (x_helmet.png, x_chestplate.png etc.) +  * Have the textures for each armor item (''x_helmet.png''''x_chestplate.png'' etc.) 
-  * Have the textures for the armor in body (x_layer_1.png and x_layer_2.png)+  * Have the textures for the armor in body (''x_layer_1.png'' and ''x_layer_2.png'')
  
 And assign them to each armor item.  And assign them to each armor item. 
Line 152: Line 160:
 The following should be the same with all armor items, only changing which part are we using. We'll use helmet for our example. The following should be the same with all armor items, only changing which part are we using. We'll use helmet for our example.
  
-<code JSON resources/assets/tutorial/models/item/custom_material_helmet.json>+<code javascript resources/assets/tutorial/models/item/custom_material_helmet.json>
 { {
  "parent": "item/generated",  "parent": "item/generated",
Line 164: Line 172:
  
 Generally, mod textures go under resources/assets/<modid>, however **armor textures go specifically in the minecraft directory**: Generally, mod textures go under resources/assets/<modid>, however **armor textures go specifically in the minecraft directory**:
-To give your on-body armor a texture, place X_layer_1.png and X_layer_2.png (where X is the <yarn method_7694> argument you chose in your armor material class) into 'resources/assets/**minecraft**/textures/models/armor'. 
- 
  
 +To give your on-body armor a texture, place ''X_layer_1.png'' and ''X_layer_2.png'' (where X is the ''<yarn method_7694>'' argument you chose in your armor material class) into 'resources/assets/**minecraft**/textures/models/armor'.
  
 If you followed everything, you should now be able to have a full armor set! If you followed everything, you should now be able to have a full armor set!
tutorial/armor.1692526752.txt.gz · Last modified: 2023/08/20 10:19 by wjz_p