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 [2019/09/27 20:42] – SoundEvents.ITEM_ARMOR_EQUIP_X, as SoundEvents.ITEM.EQUIP.ARMOR.X doesn't exist descuddlebattutorial:armor [2023/08/20 10:19] (current) – [Texturing] wjz_p
Line 3: Line 3:
 ==== Introduction ==== ==== Introduction ====
  
-While Armor is a bit more complicated to add then a normal block/item, once you can understand it, it becomes simple to make. To add Armor, we'll first make a custom material class, then register the items. We'll also take a look at how to texture them.+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). 
 + 
 +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 custom ArmorMaterial+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
  
-This class will implement ArmorMaterial and will be an enum type. It'll need a lot of arguments, mainly the name, durability, etc., so for now we'll just leave it empty. Don't worry about any errors for now.+This class will implement <yarn class_1741>, and it'll start by assigning values to armor points (called PROTECTION_VALUES). All its following arguments will make use of @Override.
  
-<code java [enable_line_numbers="true"]> +<yarncode java [enable_line_numbers="true"]> 
-public enum CustomArmorMaterial implements ArmorMaterial +public class CustomArmorMaterial implements class_1741 
-    CustomArmorMaterial() + private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11}; 
-         + private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D};  
-    }+ 
 + // In which A is boots, B leggings, C chestplate, and D helmet.  
 + // For reference, Leather uses {1, 2, 3, 1}, and Diamond/Netherite {3, 6, 8, 3}
 } }
-</code>+</yarncode>
  
-Since there's a lot of arguments neededhere's a list explaining each one of them.+The next arguments are defined as follows (don't worry about the namesyou'll see how we implement it below them):
  
-  - A String name. This will be used as a sort of "armor tag" for later. +  - <yarn method_7696>: how many hits can armor take before breakingUses the int we wrote on 'BASE_DURABILITY' to calculate. Leather uses 5, Diamond 33, Netherite 37
-  - A durability multiplierThis will be the number that will be used to determine the durability based on the base values+  - <yarn method_7697>: calls for the 'PROTECTION_VALUES' int we already wrote above
-  - Armor values, or "Protection Amounts" in the vanilla code. This will be an int array+  - <yarn method_7699>: This will be how likely the armor can get high level or multiple enchantments in an enchantment book. 
-  - Enchantability. This will be how likely the armor can get high level or multiple enchantments in an enchantment book. +  - <yarn class_3414 method_7698>: The standard used by vanilla armor is ''<yarn class_3417>.ITEM_ARMOR_EQUIP_X'', X being the type of armor. 
-  - A sound event. The standard used by vanilla armor is ''SoundEvents.ITEM_ARMOR_EQUIP_X'', X being the type of armor. +  - <yarn class_1856 method_7695>: what item are we gonna be using to repair the armor on an anvilIt can be either a vanilla item or one of your own. 
-  - Toughness. This is a second protection value where the armor is more durable against high value attacks. +  - String <yarn method_7694>: what the parent item of the armor is. In Diamond armor, it'd be "diamond"
-  - A repair ingredient. This will be a ''Supplier<Ingredient>'' instance instead of an ''Item'', which will go over in a bit.+  - <yarn method_7700>: This is a second protection value where the armor is more durable against high value attacks. Value goes as 'X.0F'
  
-With those arguments, it should now look something like this:+And the new value introduced on 1.16 
 +  - <yarn method_24355>: leave this value at 0. If you want to implement itwrite '0.XF' (in which X is how much knockback protection you want), and I'll teach you how to make it work later on.
  
-<code java [enable_line_numbers="true"]> 
-public enum CustomArmorMaterial implements ArmorMaterial { 
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) { 
-         
-    } 
-} 
-</code> 
  
-We'll also have to define those values and make it usableso now it'll look like this:+I'll leave all variables written as X or A, B, C, D. With those arguments, it should now look something like this:
  
-<code java [enable_line_numbers="true"]> +<yarncode java [enable_line_numbers="true"]> 
-public enum CustomArmorMaterial implements ArmorMaterial +public class CustomArmorMaterial implements class_1741 
-    private final String name; + private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11}
-    private final int durabilityMultiplier; + private static final int[] PROTECTION_VALUES = new int[] {ABCD};
-    private final int[] armorValues+
-    private final int enchantability; +
-    private final SoundEvent equipSound; +
-    private final float toughness; +
-    private final Lazy<Ingredient> repairIngredient; +
-     +
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArrint enchantabilitySoundEvent soundEventfloat toughness, Supplier<Ingredient> repairIngredient) { +
-        this.name = name; +
-        this.durabilityMultiplier = durabilityMultiplier; +
-        this.armorValues = armorValueArr; +
-        this.enchantability = enchantability; +
-        this.equipSound = soundEvent; +
-        this.toughness = toughness; +
-        this.repairIngredient = new Lazy(repairIngredient); // We'll need this to be a Lazy type for later. +
-    } +
-+
-</code>+
  
-''ArmorMaterial'' also needs several other methods, so we'll add them real quick here.+ @Override 
 + public int method_7696(class_1304 slot) { 
 + return BASE_DURABILITY[slot.method_5927()] * X; 
 + }
  
-We'll also have to add our base durability values, so for now we'll use the vanilla values ''[13, 15, 16, 11]''+ @Override 
 + public int method_7697(class_1304 slot) { 
 + return PROTECTION_VALUES[slot.method_5927()]
 + }
  
-<code java [enable_line_numbers="true"]> + @Override 
-public enum CustomArmorMaterial implements ArmorMaterial { + public int method_7699() { 
-    private static final int[] baseDurability = {13, 15, 16, 11}; + return X
-    private final String name; + }
-    private final int durabilityMultiplier; +
-    private final int[] armorValues; +
-    private final int enchantability; +
-    private final SoundEvent equipSound; +
-    private final float toughness; +
-    private final Lazy<Ingredient> repairIngredient; +
-     +
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) { +
-        this.name = name; +
-        this.durabilityMultiplier = durabilityMultiplier; +
-        this.armorValues = armorValueArr; +
-        this.enchantability = enchantability; +
-        this.equipSound = soundEvent; +
-        this.toughness = toughness; +
-        this.repairIngredient = new Lazy(repairIngredient); +
-    } +
-     +
-    public int getDurability(EquipmentSlot equipmentSlot_1) { +
-        return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier+
-    }+
  
-    public int getProtectionAmount(EquipmentSlot equipmentSlot_1) { + @Override 
-        return this.protectionAmounts[equipmentSlot_1.getEntitySlotId()]+ public class_3414 method_7698() { 
-    }+ return class_3417.ITEM_ARMOR_EQUIP_X
 + }
  
-    public int getEnchantability() { + @Override 
-        return this.enchantability+ public class_1856 method_7695() { 
-    }+ return class_1856.method_8091(RegisterItems.X)
 + }
  
-    public SoundEvent getEquipSound() { + @Override 
-        return this.equipSound+ public String method_7694() { 
-    }+ // Must be all lowercase 
 + return "name"
 + }
  
-    public Ingredient getRepairIngredient() { + @Override 
-        // We needed to make it a Lazy type so we can actually get the Ingredient from the Supplier. + public float method_7700() { 
-        return this.repairIngredientSupplier.get()+ return X.0F
-    }+ }
  
-    @Environment(EnvType.CLIENT) + @Override 
-    public String getName() { + public float method_24355() { 
-        return this.name; + return 0.XF
-    } + }
- +
-    public float getToughness() { +
-        return this.toughness+
-    }+
 } }
-</code>+</yarncode>
  
-Now that you have the basics of the armor material class, you can now make your own material for armor. This can be done at the top of the code like so: 
  
-<code java [enable_line_numbers="true"]> +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. 
-public enum CustomArmorMaterial implements ArmorMaterial + 
-    WOOL("wool", 5, new int[]{1,3,2,1}, 15, SoundEvents.BLOCK_WOOL_PLACE0.0F, () -> { +==== Creating Armor Items ==== 
-        return Ingredient.ofItems(Items.WHITE_WOOL); + 
-    }); +We're gonna make a 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"). 
-    [...]+ 
 +<yarncode java [enable_line_numbers="true"]> 
 +public class RegisterItems { 
 + 
 +    public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial(); 
 +    public static final class_1792 CUSTOM_MATERIAL = new CustomMaterialItem(new class_1792.class_1793()); 
 +    // If you made a new materialthis is where you would note it. 
 +    public static final class_1792 CUSTOM_MATERIAL_HELMET = new class_1738(CUSTOM_ARMOR_MATERIALclass_1304.field_6169new class_1792.class_1793()); 
 +    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_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6172, new class_1792.class_1793()); 
 +    public static final class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6166, new class_1792.class_1793()); 
 } }
-</code>+</yarncode>
  
-Feel free to change any values.+Now that your items are properly created, let's register them and give them proper names. Your 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.
  
-==== Creating Armor Items ====+We'll be writing this right below your last <yarn class_1738>
 + 
 +<yarncode java [enable_line_numbers="true"]> 
 +public static void register() { 
 +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material"), CUSTOM_MATERIAL); 
 +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_helmet"), CUSTOM_MATERIAL_HELMET); 
 +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_chestplate"), CUSTOM_MATERIAL_CHESTPLATE); 
 +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_leggings"), CUSTOM_MATERIAL_LEGGINGS); 
 +    class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_boots"), CUSTOM_MATERIAL_BOOTS); 
 +
 +</yarncode> 
 + 
 +Your armor items are done. Now we'll just call the Registry on our main class (and annotate the new group).
  
-Back in the main class, you can now create it like so:+<yarncode java [enable_line_numbers="true"]> 
 +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 iconbut you can reference to whatever you like 
 +    .build();
  
-<code java [enable_line_numbers="true"]> +@Override 
-public class ExampleMod implements ModInitializer { +public void onInitialize() { 
-    public static final Item WOOL_HELMET = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT))); +    RegisterItems.register();
-    public static final Item WOOL_CHESTPLATE = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.CHEST, (new Item.Settings().group(ItemGroup.COMBAT))); +
-    public static final Item WOOL_LEGGINGS = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.LEGS, (new Item.Settings().group(ItemGroup.COMBAT))); +
-    public static final Item WOOL_BOOTS = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.FEET, (new Item.Settings().group(ItemGroup.COMBAT)));+
 } }
-</code>+</yarncode>
  
-==== Registering Armor Items ====+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.
  
-Register them the same way you'd register a normal item. 
  
-<code java [enable_line_numbers=true]> 
-    [...] 
-    public void onInitialize() { 
-        Registry.register(Registry.ITEM,new Identifier("tutorial","wool_helmet"), WOOL_HELMET); 
- Registry.register(Registry.ITEM,new Identifier("tutorial","wool_chestplate"), WOOL_CHESTPLATE); 
- Registry.register(Registry.ITEM,new Identifier("tutorial","wool_leggings"), WOOL_LEGGINGS); 
- Registry.register(Registry.ITEM,new Identifier("tutorial","wool_boots"), WOOL_BOOTS); 
-    } 
-</code> 
  
 ==== Texturing ==== ==== Texturing ====
  
-Since you already know how to make item models and textureswe won't go over them here(They're done exactly the same as items.) Armor textures are done a little differently since Minecraft thinks it's a vanilla armor itemFor this, we'll make a ''pack.mcmeta'' file so our resources can act like a resource pack.+We're going to assume you 
 +  * Have the textures for each armor item (x_helmet.pngx_chestplate.png etc.) 
 +  * Have the textures for the armor in body (x_layer_1.png and x_layer_2.png)
  
-<code JavaScript src/main/resources/pack.mcmeta>+And assign them to each armor item.  
 + 
 +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>
 { {
-    "pack":{ + "parent": "item/generated", 
-        "pack_format":4, + "textures": { 
-        "description":"Tutorial Mod+ "layer0": "tutorial:item/custom_material_helmet
-    }+ }
 } }
 </code> </code>
  
-Now you can finally place your textures here in ''src/main/resources/assets/minecraft/textures/models/armor/''Keep in mind that they're separated in 2 pictures. (Use vanilla textures for reference.)+Repeat with all armor items. 
 + 
 +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'. 
 + 
  
 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.1569616926.txt.gz · Last modified: 2019/09/27 20:42 by descuddlebat