🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21
This page is written for version:
1.21
Armor provides the player with increased defense against attacks from mobs and other players.
Just like items and blocks, armor materials need to be registered. We will create a ModArmorMaterials
class to store our custom armor materials for the sake of organization.
You will need to add a static initialize()
method to this class, and call it from your mod's initializer so that the materials are registered.
// Within the ModArmorMaterials class
public static void initialize() {};
WARNING
Make sure to call this method before you register your items, as the materials will need to be registered before the items can be created.
@Override
public void onInitialize() {
ModArmorMaterials.initialize();
}
Within this ModArmorMaterials
class, you will need to create a static method which will register the armor material. This method should return a registry entry of the material, as this entry will be used by the ArmorItem constructor to create the armor items.
public static RegistryEntry<ArmorMaterial> registerMaterial(String id, Map<ArmorItem.Type, Integer> defensePoints, int enchantability, RegistryEntry<SoundEvent> equipSound, Supplier<Ingredient> repairIngredientSupplier, float toughness, float knockbackResistance, boolean dyeable) {
// Get the supported layers for the armor material
List<ArmorMaterial.Layer> layers = List.of(
// The ID of the texture layer, the suffix, and whether the layer is dyeable.
// We can just pass the armor material ID as the texture layer ID.
// We have no need for a suffix, so we'll pass an empty string.
// We'll pass the dyeable boolean we received as the dyeable parameter.
new ArmorMaterial.Layer(Identifier.of(FabricDocsReference.MOD_ID, id), "", dyeable)
);
ArmorMaterial material = new ArmorMaterial(defensePoints, enchantability, equipSound, repairIngredientSupplier, layers, toughness, knockbackResistance);
// Register the material within the ArmorMaterials registry.
material = Registry.register(Registries.ARMOR_MATERIAL, Identifier.of(FabricDocsReference.MOD_ID, id), material);
// The majority of the time, you'll want the RegistryEntry of the material - especially for the ArmorItem constructor.
return RegistryEntry.of(material);
}
TIP
If you're struggling to gauge a good value for any of these properties, consider looking at the vanilla armor materials in the ArmorMaterials
class.
When creating an armor material, you will need to define the following properties:
WARNING
Ensure you assign a value to each type of armor piece you plan to create and register as an item. If you make an item for an armor piece without a set defense point value, the game will crash.
The defensePoints
map is used to define the number of defense points that each armor piece will provide. The higher the number, the more protection the armor piece will provide. The map should contain an entry for each armor piece type.
The enchantability
property defines how easily the armor can be enchanted. The higher the number, the more enchantments the armor can receive.
The equipSound
property is the sound that will play when the armor is equipped. This sound should be a registry entry of a SoundEvent
. Consider taking a look at the Custom Sound Events page if you are considering creating custom sounds rather than relying on vanilla sounds within the SoundEvents
class.
The repairIngredientSupplier
property is a supplier of an Ingredient
that is used to repair the armor. This ingredient can pretty much be anything, it's recommended to set it to be the same as the material's crafting ingredient used to actually craft the armor items.
The toughness
property defines how much damage the armor will absorb. The higher the number, the more damage the armor will absorb.
The knockbackResistance
property defines how much knockback the player will reflect when hit. The higher the number, the less knockback the player will receive.
The dyeable
property is a boolean that defines whether the armor can be dyed. If set to true
, the armor can be dyed using dyes in a crafting table.
If you do choose to make your armor dyeable, your armor layer and item textures must be designed to be dyed, as the dye will overlay the texture, not replace it. Take a look at the vanilla leather armor for an example, the textures are grayscale and the dye is applied as an overlay, causing the armor to change color.
Now that you've created a utility method which can be used to register armor materials, you can register your custom armor materials as a static field in the ModArmorMaterials
class.
For this example, we'll be creating Guidite armor, with the following properties:
public static final RegistryEntry<ArmorMaterial> GUIDITE = registerMaterial("guidite",
// Defense (protection) point values for each armor piece.
Map.of(
ArmorItem.Type.HELMET, 3,
ArmorItem.Type.CHESTPLATE, 8,
ArmorItem.Type.LEGGINGS, 6,
ArmorItem.Type.BOOTS, 3
),
// Enchantability. For reference, leather has 15, iron has 9, and diamond has 10.
5,
// The sound played when the armor is equipped.
SoundEvents.ITEM_ARMOR_EQUIP_IRON,
// The ingredient(s) used to repair the armor.
() -> Ingredient.ofItems(ModItems.SUSPICIOUS_SUBSTANCE),
0.0F,
0.0F,
// Guidite is NOT dyeable, so we will pass false.
false);
Now that you've registered the material, you can create the armor items in your ModItems
class:
Obviously, an armor set doesn't need every type to be satisfied, you can have a set with just boots, or leggings etc. - the vanilla turtle shell helmet is a good example of an armor set with missing slots.
Unlike ToolMaterial
, ArmorMaterial
does not store any information about the durability of items. For this reason the durability needs to be manually added to the armor items' Item.Settings
when registering them.
This is achieved using the maxDamage
method in the Item.Settings
class. The different armor slots have different base durabilities which are commonly multiplied by a shared armor material multiplier but hard-coded values can also be used.
For the Guidite armor we'll be using a shared armor multiplier stored alongside the armor material:
public static final int GUIDITE_DURABILITY_MULTIPLIER = 15;
We can then create the armor items using the durability constant:
public static final Item GUIDITE_HELMET = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.HELMET, new Item.Settings().maxDamage(ArmorItem.Type.HELMET.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_helmet");
public static final Item GUIDITE_CHESTPLATE = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.CHESTPLATE, new Item.Settings().maxDamage(ArmorItem.Type.CHESTPLATE.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_chestplate");
public static final Item GUIDITE_LEGGINGS = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.LEGGINGS, new Item.Settings().maxDamage(ArmorItem.Type.LEGGINGS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_leggings");
public static final Item GUIDITE_BOOTS = register(new ArmorItem(ModArmorMaterials.GUIDITE, ArmorItem.Type.BOOTS, new Item.Settings().maxDamage(ArmorItem.Type.BOOTS.getMaxDamage(ModArmorMaterials.GUIDITE_DURABILITY_MULTIPLIER))), "guidite_boots");
You will also need to add the items to an item group if you want them to be accessible from the creative inventory.
As with all items, you should create translation keys for them as well.
You will need to create two sets of textures:
These textures are no different to other items - you must create the textures, and create a generic generated item model - which was covered in the Creating Your First Item guide.
For example purposes, you may use the following textures and model JSON as a reference.
INFO
You will need model JSON files for all the items, not just the helmet, it's the same principle as other item models.
{
"parent": "item/generated",
"textures": {
"layer0": "fabric-docs-reference:item/guidite_helmet"
}
}
As you can see, in-game the armor items should have suitable models:
When an entity wears your armor, currently the missing texture will appear:
There are two layers for the armor texture, both must be present.
Since the armor material name in our case is guidite
, the locations of the textures will be:
assets/<mod-id>/textures/models/armor/guidite_layer_1.png
assets/<mod-id>/textures/models/armor/guidite_layer_2.png
The first layer contains textures for the helmet and chestplate, whilst the second layer contains textures for leggings and boots.
When these textures are present, you should be able to see your armor on entities that wear it: