🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for version:
1.21.4
This page is written for version:
1.21.4
Armor provides the player with increased defense against attacks from mobs and other players.
Technically, you don't need a dedicated class for your armor material, but it's good practice anyways with the number of static fields you will need.
For this example, we'll create an GuiditeArmorMaterial
class to store our static fields.
This constant will be used in the Item.Settings#maxDamage(int damageValue)
method when creating our armor items, it is also required as a parameter in the ArmorMaterial
constructor when we create our ArmorMaterial
object later.
public static final int BASE_DURABILITY = 15;
If you're struggling to determine a balanced base durability, you can refer to the vanilla armor material instances found in the ArmorMaterials
interface.
Even though we don't have to register our ArmorMaterial
to any registries, it's generally good practice to store any registry keys as constants, as the game will use this to find the relevant textures for our armor.
public static final RegistryKey<EquipmentAsset> GUIDITE_ARMOR_MATERIAL_KEY = RegistryKey.of(EquipmentAssetKeys.REGISTRY_KEY, Identifier.of(FabricDocsReference.MOD_ID, "guidite"));
We will pass this to the ArmorMaterial
constructor later.
ArmorMaterial
Instance To create our material, we need to create a new instance of the ArmorMaterial
record, the base durability and material registry key constants will be used here.
public static final ArmorMaterial INSTANCE = new ArmorMaterial(
BASE_DURABILITY,
Map.of(
EquipmentType.HELMET, 3,
EquipmentType.CHESTPLATE, 8,
EquipmentType.LEGGINGS, 6,
EquipmentType.BOOTS, 3
),
5,
SoundEvents.ITEM_ARMOR_EQUIP_IRON,
0.0F,
0.0F,
REPAIRS_GUIDITE_ARMOR,
GUIDITE_ARMOR_MATERIAL_KEY
);
The ArmorMaterial
constructor accepts the following parameters, in this specific order:
Parameter | Description |
---|---|
durability | The base durability of all armor pieces, this is used when calculating the total durability of each individual armor piece that use this material. This should be the base durability constant you created earlier. |
defense | A map of EquipmentType (an enum representing each armor slot) to an integer value, which indicates the defense value of the material when used in the corresponding armor slot. |
enchantmentValue | The "enchantability" of armor items which use this material. |
equipSound | A registry entry of a sound event that is played when you equip a piece of armor which uses this material. For more information on sounds, check out the Custom Sounds page. |
toughness | A float value which represents the "toughness" attribute of the armor material - essentially how well the armor will absorb damage. |
knockbackResistance | A float value which represents the amount of knockback resistance the armor material grants the wearer. |
repairIngredient | An item tag that represents all items which can be used to repair the armor items of this material in an anvil. |
assetId | An EquipmentAsset registry key, this should be the equipment asset registry key constant you created earlier. |
If you're struggling to determine values for any of the parameters, you can consult the vanilla ArmorMaterial
instances which can be found in the ArmorMaterials
interface.
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 base durability needs to be manually added to the armor items' Item.Settings
when registering them.
This is achieved by passing the BASE_DURABILITY
constant we created previously into the maxDamage
method in the Item.Settings
class.
public static final RegistryKey<Item> GUIDITE_HELMET_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_helmet"));
public static final Item GUIDITE_HELMET = register(new ArmorItem(GuiditeArmorMaterial.INSTANCE, EquipmentType.HELMET, new Item.Settings().registryKey(GUIDITE_HELMET_KEY).maxDamage(EquipmentType.HELMET.getMaxDamage(GuiditeArmorMaterial.BASE_DURABILITY))), GUIDITE_HELMET_KEY);
public static final RegistryKey<Item> GUIDITE_CHESTPLATE_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_chestplate"));
public static final Item GUIDITE_CHESTPLATE = register(new ArmorItem(GuiditeArmorMaterial.INSTANCE, EquipmentType.CHESTPLATE, new Item.Settings().registryKey(GUIDITE_CHESTPLATE_KEY).maxDamage(EquipmentType.CHESTPLATE.getMaxDamage(GuiditeArmorMaterial.BASE_DURABILITY))), GUIDITE_CHESTPLATE_KEY);
public static final RegistryKey<Item> GUIDITE_LEGGINGS_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_leggings"));
public static final Item GUIDITE_LEGGINGS = register(new ArmorItem(GuiditeArmorMaterial.INSTANCE, EquipmentType.LEGGINGS, new Item.Settings().registryKey(GUIDITE_LEGGINGS_KEY).maxDamage(EquipmentType.LEGGINGS.getMaxDamage(GuiditeArmorMaterial.BASE_DURABILITY))), GUIDITE_LEGGINGS_KEY);
public static final RegistryKey<Item> GUIDITE_BOOTS_KEY = RegistryKey.of(RegistryKeys.ITEM, Identifier.of(FabricDocsReference.MOD_ID, "guidite_boots"));
public static final Item GUIDITE_BOOTS = register(new ArmorItem(GuiditeArmorMaterial.INSTANCE, EquipmentType.BOOTS, new Item.Settings().registryKey(GUIDITE_BOOTS_KEY).maxDamage(EquipmentType.BOOTS.getMaxDamage(GuiditeArmorMaterial.BASE_DURABILITY))), GUIDITE_BOOTS_KEY);
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 a set of textures for the items, and a set of textures for the actual armour when it's worn by a "humanoid" entity (players, zombies, skeletons, etc).
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": "minecraft: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, nothing will be shown. This is because you're missing textures and the equipment model definitions.
There are two layers for the armor texture, both must be present.
Previously, we created a RegistryKey<EquipmentAsset>
constant called GUIDITE_ARMOR_MATERIAL_KEY
which we passed into our ArmorMaterial
constructor. It's recommended to name the texture similarly, so in our case, guidite.png
assets/mod-id/textures/entity/equipment/humanoid/guidite.png
- Contains upper body and boot textures.assets/mod-id/textures/entity/equipment/humanoid_leggings/guidite.png
- Contains legging textures.TIP
If you're updating to 1.21.4 from an older version of the game, the humanoid
folder is where your layer0.png
armor texture goes, and the humanoid_leggings
folder is where your layer1.png
armor texture goes.
Next, you'll need to create an associated equipment model definition. These go in the /assets/mod-id/equipment/
folder.
The RegistryKey<EquipmentAsset>
constant we created earlier will determine the name of the JSON file. In this case, it'll be guidite.json
.
Since we only plan to add "humanoid" (helmet, chestplate, leggings, boots etc.) armor pieces, our equipment model definition will look like this:
{
"layers": {
"humanoid": [
{
"texture": "fabric-docs-reference:guidite"
}
],
"humanoid_leggings": [
{
"texture": "fabric-docs-reference:guidite"
}
]
}
}
With the textures and equipment model definition present, you should be able to see your armor on entities that wear it: