Table of Contents

This page has been moved, the new location is https://docs.fabricmc.net/develop/items/custom-armor.

Adding Armor

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).

An example for this document can be found in this mod GitHub repository.

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.

  1. public class CustomArmorMaterial implements ArmorMaterial {
  2. private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};
  3. private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D};
  4.  
  5. // In which A is boots, B leggings, C chestplate, and D helmet.
  6. // For reference, Leather uses {1, 2, 3, 1}, and Diamond/Netherite {3, 6, 8, 3}
  7. }

The next arguments are defined as follows (don't worry about the names, you'll see how we implement it below them):

  1. method_7696: 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.
  2. method_7697: calls for the 'PROTECTION_VALUES' int we already wrote above.
  3. getEnchantability: This will be how likely the armor can get high level or multiple enchantments in an enchantment book.
  4. SoundEvent getEquipSound: The standard used by vanilla armor is SoundEvents.ITEM_ARMOR_EQUIP_X, X being the type of armor.
  5. Ingredient getRepairIngredient: 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.
  6. String getName: what the parent item of the armor is. In Diamond armor, it'd be “diamond”.
  7. 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

  1. 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:

  1. public class CustomArmorMaterial implements ArmorMaterial {
  2. private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11};
  3. private static final int[] PROTECTION_VALUES = new int[] {A, B, C, D};
  4.  
  5. @Override
  6. public int method_7696(EquipmentSlot slot) {
  7. return BASE_DURABILITY[slot.getEntitySlotId()] * X;
  8. }
  9.  
  10. @Override
  11. public int method_7697(EquipmentSlot slot) {
  12. return PROTECTION_VALUES[slot.getEntitySlotId()];
  13. }
  14.  
  15. @Override
  16. public int getEnchantability() {
  17. return X;
  18. }
  19.  
  20. @Override
  21. public SoundEvent getEquipSound() {
  22. return SoundEvents.ITEM_ARMOR_EQUIP_X;
  23. }
  24.  
  25. @Override
  26. public Ingredient getRepairIngredient() {
  27. return Ingredient.ofItems(RegisterItems.X);
  28. }
  29.  
  30. @Override
  31. public String getName() {
  32. // Must be all lowercase
  33. return "name";
  34. }
  35.  
  36. @Override
  37. public float getToughness() {
  38. return X.0F;
  39. }
  40.  
  41. @Override
  42. public float getKnockbackResistance() {
  43. return 0.XF;
  44. }
  45. }

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

In the item tutorial, we've created a class TutorialItems for items in the mod. Here we place them here, and use the convenient register method we've introducted in the item tutorial.

  1. public final class TutorialItems {
  2. // [...]
  3.  
  4. public static final ArmorMaterial CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial();
  5. public static final Item CUSTOM_MATERIAL = register(new CustomMaterialItem(new Item.Settings()), "custom_material");
  6. // If you made a new material, this is where you would note it.
  7. public static final Item CUSTOM_MATERIAL_HELMET = register(new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.HEAD, new Item.Settings()), "custom_material_helmet");
  8. public static final Item CUSTOM_MATERIAL_CHESTPLATE = register(new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.CHEST, new Item.Settings()), "custom_material_chestplate");
  9. public static final Item CUSTOM_MATERIAL_LEGGINGS = register(new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.LEGS, new Item.Settings()), "custom_material_leggings");
  10. public static final Item CUSTOM_MATERIAL_BOOTS = register(new ArmorItem(CUSTOM_ARMOR_MATERIAL, EquipmentSlot.FEET, new Item.Settings()), "custom_material_boots");
  11.  
  12. }

Your armor items are done. Now we'll just create a separate item group for that.

  1. public final class TutorialItemGroups {
  2. public static final ItemGroup TEST_GROUP = FabricItemGroup.builder()
  3. .icon(() -> new ItemStack(TutorialItems.CUSTOM_MATERIAL)) // This uses the model of the new material you created as an icon, but you can reference to whatever you like
  4. .displayName(Text.translatable("itemGroup.tutorial.test_group"))
  5. .entries((context, entries) -> {
  6. entries.add(CUSTOM_MATERIAL)
  7. .add(CUSTOM_MATERIAL_HELMET)
  8. .add(CUSTOM_MATERIAL_CHESTPLATE)
  9. .add(CUSTOM_MATERIAL_LEGGINGS)
  10. .add(CUSTOM_MATERIAL_BOOTS);
  11. })
  12. .build();
  13.  
  14. public static void initialize() {
  15. // Since 1.21:
  16. Registry.register(Registries.ITEM_GROUP, Identifier.of("tutorial", "test_group"), ITEM_GROUP);
  17. }
  18. }

If you did those above in the separate classes, remember to statically initialize the classes in your ModInitializer, if you haven't done yet:

public class ExampleMod implements ModInitializer {
    [...]
 
    @Override
    public void onInitialize() {
        TutorialItems.initialize();
        TUtorialItemGroups.initialize();
    }
}

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.

Texturing

We're going to assume you

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.

resources/assets/tutorial/models/item/custom_material_helmet.json
{
	"parent": "item/generated",
	"textures": {
		"layer0": "tutorial:item/custom_material_helmet"
	}
}

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