User Tools

Site Tools





Blocks and Block Entities



World Generation




Dynamic Data Generation


Tutorials for Minecraft 1.15

Tutorials for Minecraft 1.14



This is an old revision of the document!

Adding Armor


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.

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.

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.

  1. public enum CustomArmorMaterial implements ArmorMaterial {
  2. CustomArmorMaterial() {
  4. }
  5. }

Since there's a lot of arguments needed, here's a list explaining each one of them.

  1. A String name. This will be used as a sort of “armor tag” for later.
  2. A durability multiplier. This will be the number that will be used to determine the durability based on the base values.
  3. Armor values, or “Protection Amounts” in the vanilla code. This will be an int array.
  4. Enchantability. This will be how likely the armor can get high level or multiple enchantments in an enchantment book.
  5. A sound event. The standard used by vanilla armor is SoundEvents.ITEM_ARMOR_EQUIP_X, X being the type of armor.
  6. Toughness. This is a second protection value where the armor is more durable against high value attacks.
  7. A repair ingredient. This will be a Supplier<Ingredient> instance instead of an Item, which will go over in a bit.

With those arguments, it should now look something like this:

  1. public enum CustomArmorMaterial implements ArmorMaterial {
  2. CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {
  4. }
  5. }

We'll also have to define those values and make it usable, so now it'll look like this:

  1. public enum CustomArmorMaterial implements ArmorMaterial {
  2. private final String name;
  3. private final int durabilityMultiplier;
  4. private final int[] armorValues;
  5. private final int enchantability;
  6. private final SoundEvent equipSound;
  7. private final float toughness;
  8. private final Lazy<Ingredient> repairIngredient;
  10. CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {
  11. = name;
  12. this.durabilityMultiplier = durabilityMultiplier;
  13. this.armorValues = armorValueArr;
  14. this.enchantability = enchantability;
  15. this.equipSound = soundEvent;
  16. this.toughness = toughness;
  17. this.repairIngredient = new Lazy(repairIngredient); // We'll need this to be a Lazy type for later.
  18. }
  19. }

ArmorMaterial also needs several other methods, so we'll add them real quick here.

We'll also have to add our base durability values, so for now we'll use the vanilla values [13, 15, 16, 11]

  1. public enum CustomArmorMaterial implements ArmorMaterial {
  2. private static final int[] baseDurability = {13, 15, 16, 11};
  3. private final String name;
  4. private final int durabilityMultiplier;
  5. private final int[] armorValues;
  6. private final int enchantability;
  7. private final SoundEvent equipSound;
  8. private final float toughness;
  9. private final Lazy<Ingredient> repairIngredient;
  11. CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {
  12. = name;
  13. this.durabilityMultiplier = durabilityMultiplier;
  14. this.armorValues = armorValueArr;
  15. this.enchantability = enchantability;
  16. this.equipSound = soundEvent;
  17. this.toughness = toughness;
  18. this.repairIngredient = new Lazy(repairIngredient);
  19. }
  21. public int getDurability(EquipmentSlot equipmentSlot_1) {
  22. return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier;
  23. }
  25. public int getProtectionAmount(EquipmentSlot equipmentSlot_1) {
  26. return this.protectionAmounts[equipmentSlot_1.getEntitySlotId()];
  27. }
  29. public int getEnchantability() {
  30. return this.enchantability;
  31. }
  33. public SoundEvent getEquipSound() {
  34. return this.equipSound;
  35. }
  37. public Ingredient getRepairIngredient() {
  38. // We needed to make it a Lazy type so we can actually get the Ingredient from the Supplier.
  39. return this.repairIngredientSupplier.get();
  40. }
  42. @Environment(EnvType.CLIENT)
  43. public String getName() {
  44. return;
  45. }
  47. public float getToughness() {
  48. return this.toughness;
  49. }
  50. }

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:

  1. public enum CustomArmorMaterial implements ArmorMaterial {
  2. WOOL("wool", 5, new int[]{1,3,2,1}, 15, SoundEvents.BLOCK_WOOL_PLACE, 0.0F, () -> {
  3. return Ingredient.ofItems(Items.WHITE_WOOL);
  4. });
  5. [...]
  6. }

Feel free to change any values.

Creating Armor Items

Back in the main class, you can now create it like so:

  1. public class ExampleMod implements ModInitializer {
  2. public static final Item WOOL_HELMET = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT)));
  3. public static final Item WOOL_CHESTPLATE = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.CHEST, (new Item.Settings().group(ItemGroup.COMBAT)));
  4. public static final Item WOOL_LEGGINGS = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.LEGS, (new Item.Settings().group(ItemGroup.COMBAT)));
  5. public static final Item WOOL_BOOTS = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.FEET, (new Item.Settings().group(ItemGroup.COMBAT)));
  6. }

Registering Armor Items

Register them the same way you'd register a normal item.

  1. [...]
  2. public void onInitialize() {
  3. Registry.register(Registry.ITEM,new Identifier("tutorial","wool_helmet"), WOOL_HELMET);
  4. Registry.register(Registry.ITEM,new Identifier("tutorial","wool_chestplate"), WOOL_CHESTPLATE);
  5. Registry.register(Registry.ITEM,new Identifier("tutorial","wool_leggings"), WOOL_LEGGINGS);
  6. Registry.register(Registry.ITEM,new Identifier("tutorial","wool_boots"), WOOL_BOOTS);
  7. }


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.

        "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!

tutorial/armor.1592425174.txt.gz · Last modified: 2020/06/17 20:19 by terantai