====== 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 [[https://github.com/gdude2002/Gilded-Netherite|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 , 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 class_1741 { 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 boots, B leggings, C chestplate, and D helmet. // 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): - : 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. - : calls for the 'PROTECTION_VALUES' int we already wrote above. - : This will be how likely the armor can get high level or multiple enchantments in an enchantment book. - : The standard used by vanilla armor is ''.ITEM_ARMOR_EQUIP_X'', X being the type of armor. - : 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 : what the parent item of the armor is. In Diamond armor, it'd be "diamond". - : 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 - : 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 class_1741 { 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 method_7696(class_1304 slot) { return BASE_DURABILITY[slot.method_5927()] * X; } @Override public int method_7697(class_1304 slot) { return PROTECTION_VALUES[slot.method_5927()]; } @Override public int method_7699() { return X; } @Override public class_3414 method_7698() { return class_3417.ITEM_ARMOR_EQUIP_X; } @Override public class_1856 method_7695() { return class_1856.method_8091(RegisterItems.X); } @Override public String method_7694() { // Must be all lowercase return "name"; } @Override public float method_7700() { return X.0F; } @Override public float method_24355() { 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 ==== We're gonna make a new class called RegisterItems to implement your new armor pieces. This will also be the place to, for example, register tools, if you're making a new item like an ingot (We'll refer to this as a "Custom_Material"). public class RegisterItems { public static final class_1741 CUSTOM_ARMOR_MATERIAL = new CustomArmorMaterial(); public static final class_1792 CUSTOM_MATERIAL = new CustomMaterialItem(new class_1792.class_1793()); // If you made a new material, this is where you would note it. public static final class_1792 CUSTOM_MATERIAL_HELMET = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6169, new class_1792.class_1793()); public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6174, new class_1792.class_1793()); public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6172, new class_1792.class_1793()); public static final class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, class_1304.field_6166, new class_1792.class_1793()); } Now that your items are properly created, let's register them and give them proper names. Your first parameter is going to be your namespace, which is your mod ID, and then next one the name you want to give to your item. We'll be writing this right below your last . public static void register() { class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material"), CUSTOM_MATERIAL); class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_helmet"), CUSTOM_MATERIAL_HELMET); class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_chestplate"), CUSTOM_MATERIAL_CHESTPLATE); class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_leggings"), CUSTOM_MATERIAL_LEGGINGS); class_2378.method_10230(class_7923.field_41178, new class_2960("tutorial", "custom_material_boots"), CUSTOM_MATERIAL_BOOTS); } Your armor items are done. Now we'll just call the Registry on our main class (and annotate the new group). public static final class_1761 EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create( new class_2960("tutorial", "example_mod_group")) .icon(() -> new class_1799(RegisterItems.CUSTOM_MATERIAL)) // This uses the model of the new material you created as an icon, but you can reference to whatever you like .build(); @Override public void onInitialize() { RegisterItems.register(); } 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 * Have the textures for each armor item (x_helmet.png, x_chestplate.png etc.) * Have the textures for the armor in body (x_layer_1.png and x_layer_2.png) 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. { "parent": "item/generated", "textures": { "layer0": "tutorial:item/custom_material_helmet" } } Repeat with all armor items. Generally, mod textures go under resources/assets/, 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 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!