This is an old revision of the document!
Table of Contents
Adding Armor
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 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).
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.
This class will implement ArmorMaterial, and it'll start by assigning values to armor points (called PROTECTION_VALUES). All its following arguments will make use of @Override.
public class CustomArmorMaterial implements ArmorMaterial { 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 helmet, B chestplate, C leggings and D boots. // For reference, Leather uses {1, 2, 3, 1}, and Diamond/Netherite {3, 6, 8, 3} }
The next arguments are defined as follows (don't worry about the names, you'll see how we implement it below them):
- getDurability: how many hits can armor take before breaking. Uses the int we wrote on 'BASE_DURABILITY' to calculate. Leather uses 5, Diamond 33, Netherite 37.
- getPretectionAmount: calls for the 'PROTECTION_VALUES' int we already wrote above.
- getEnchantability: This will be how likely the armor can get high level or multiple enchantments in an enchantment book.
- SoundEvent getEquipSound: The standard used by vanilla armor is
SoundEvents.ITEM_ARMOR_EQUIP_X
, X being the type of armor. - Ingredient getRepairIngridient: what item are we gonna be using to repair the armor on an anvil. It can be either a vanilla item or one of your own.
- String getName: what the parent item of the armor is. In Diamond armor, it'd be “diamond”.
- getToughness: This is a second protection value where the armor is more durable against high value attacks. Value goes as 'X.0F'
And the new value introduced on 1.16
- getKnockbackResistance: leave this value at 0. If you want to implement it, write '0.XF' (in which X is how much knockback protection you want), and I'll teach you how to make it work later on.
I'll leave all variables written as X or A, B, C, D. With those arguments, it should now look something like this:
public class CustomArmorMaterial implements ArmorMaterial { private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11}; private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D}; @Override public int getDurability(EquipmentSlot slot) { return BASE_DURABILITY[slot.getEntitySlotId()] * X; } @Override public int getProtectionAmount(EquipmentSlot slot) { return PROTECTION_VALUES[slot.getEntitySlotId()]; } @Override public int getEnchantability() { return X; } @Override public SoundEvent getEquipSound() { return SoundEvents.ITEM_ARMOR_EQUIP_X; } @Override public Ingredient getRepairIngredient() { return Ingredient.ofItems(RegisterItems.X); } @Override return "name"; } @Override public float getToughness() { return X.0F; } @Override public float getKnockbackResistance() { return 0.XF; } }
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
Back in the main class, you can now create it like so:
public class ExampleMod implements ModInitializer { public static final Item WOOL_HELMET = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT))); 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))); }
Registering Armor Items
Register them the same way you'd register a normal item.
[...] public void onInitialize() { }
Texturing
Since you already know how to make item models and textures, we 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 item. For this, we'll make a pack.mcmeta
file so our resources can act like a resource pack.
- src/main/resources/pack.mcmeta
{ "pack":{ "pack_format": 5, "description": "Tutorial Mod" } }
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.)
If you followed everything, you should now be able to have a full armor set!