tutorial:armor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:armor [2020/10/09 19:04] – Knockback warning sakira | tutorial:armor [2023/08/20 10:19] (current) – [Texturing] wjz_p | ||
---|---|---|---|
Line 3: | Line 3: | ||
==== Introduction ==== | ==== Introduction ==== | ||
- | While Armor is a bit more complicated to add then a normal block/item, once you can understand it, it becomes simple to make. | + | 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' |
- | 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' | + | An example for this document can be found in [[https:// |
==== Creating an Armor Material class ==== | ==== 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), | + | Since new armor needs to be set with a new name (as well as extra things like armor points and durability), |
- | This class will implement | + | This class will implement |
- | <code java [enable_line_numbers=" | + | <yarncode |
- | public | + | public |
- | | + | 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/ | ||
} | } | ||
- | </code> | + | </yarncode> |
- | Since there' | + | The next arguments |
- | - A String name. This will be used as a sort of "armor tag" for later. | + | - <yarn method_7696>: |
- | - A durability multiplier. This will be the number that will be used to determine the durability based on the base values. | + | - <yarn method_7697>: |
- | - Armor values, or " | + | - <yarn method_7699>: |
- | - Enchantability. | + | - <yarn class_3414 method_7698>: |
- | - A sound event. | + | - <yarn class_1856 method_7695>: |
- | - Toughness. This is a second protection value where the armor is more durable against high value attacks. | + | - String <yarn method_7694>: |
- | - A repair ingredient. This will be a '' | + | - <yarn method_7700>: |
- | If you' | + | And the new value introduced |
- | - Knockback Resistance. This is the scale of the amount of knockback | + | - <yarn method_24355>: |
- | With those arguments, it should now look something like this: | ||
- | <code java [enable_line_numbers=" | + | I'll leave all variables written as X or A, B, C, D. With those arguments, it should now look something like this: |
- | public enum CustomArmorMaterial implements ArmorMaterial { | + | |
- | CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance, | + | |
- | + | ||
- | } | + | |
- | } | + | |
- | </ | + | |
- | We'll also have to define those values and make it usable, so now it'll look 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}; | ||
- | <code java [enable_line_numbers=" | + | @Override |
- | public | + | public int method_7696(class_1304 slot) { |
- | private final String name; | + | return BASE_DURABILITY[slot.method_5927()] * X; |
- | private final int durabilityMultiplier; | + | } |
- | private final int[] armorValues; | + | |
- | private final int enchantability; | + | |
- | private final SoundEvent equipSound; | + | |
- | private final float toughness; | + | |
- | private final float knockbackResistance; | + | |
- | private final Lazy< | + | |
- | + | ||
- | CustomArmorMaterial(String name, int durabilityMultiplier, | + | |
- | this.name = name; | + | |
- | this.durabilityMultiplier = durabilityMultiplier; | + | |
- | this.armorValues = armorValueArr; | + | |
- | this.enchantability = enchantability; | + | |
- | this.equipSound = soundEvent; | + | |
- | this.toughness = toughness; | + | |
- | this.knockbackResistance = knockbackResistance; | + | |
- | this.repairIngredient = new Lazy(repairIngredient); // We'll need this to be a Lazy type for later. | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | '' | + | @Override |
+ | public int method_7697(class_1304 slot) { | ||
+ | return PROTECTION_VALUES[slot.method_5927()]; | ||
+ | } | ||
- | We'll also have to add our base durability values, so for now we'll use the vanilla values '' | + | @Override |
+ | public int method_7699() { | ||
+ | return X; | ||
+ | } | ||
- | <code java [enable_line_numbers=" | + | @Override |
- | public | + | public |
- | private static final int[] baseDurability = {13, 15, 16, 11}; | + | return |
- | private final String name; | + | } |
- | private final int durabilityMultiplier; | + | |
- | private final int[] armorValues; | + | |
- | private final int enchantability; | + | |
- | private final SoundEvent equipSound; | + | |
- | private final float toughness; | + | |
- | private final float knockbackResistance; | + | |
- | private final Lazy< | + | |
- | + | ||
- | CustomArmorMaterial(String name, int durabilityMultiplier, | + | |
- | | + | |
- | this.durabilityMultiplier = durabilityMultiplier; | + | |
- | this.armorValues = armorValueArr; | + | |
- | this.enchantability = enchantability; | + | |
- | this.equipSound = soundEvent; | + | |
- | this.toughness = toughness; | + | |
- | this.repairIngredient = new Lazy(repairIngredient); | + | |
- | } | + | |
- | + | ||
- | public int getDurability(EquipmentSlot equipmentSlot_1) { | + | |
- | | + | |
- | } | + | |
- | | + | @Override |
- | return | + | public |
- | } | + | return |
+ | } | ||
- | | + | @Override |
- | return | + | public |
- | } | + | // Must be all lowercase |
+ | return | ||
+ | } | ||
- | | + | @Override |
- | return | + | public |
- | } | + | return |
+ | } | ||
- | | + | @Override |
- | // We needed to make it a Lazy type so we can actually get the Ingredient from the Supplier. | + | public |
- | | + | return |
- | } | + | } |
+ | } | ||
+ | </ | ||
- | @Environment(EnvType.CLIENT) | ||
- | public String getName() { | ||
- | return this.name; | ||
- | } | ||
- | public float getToughness() { | + | 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. |
- | return this.toughness; | + | |
- | } | + | |
- | + | ||
- | public float getKnockbackResistance() { | + | |
- | return this.knockbackResistance; | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | 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: | + | ==== Creating Armor Items ==== |
+ | |||
+ | We're gonna make a new class called RegisterItems to implement | ||
+ | |||
+ | < | ||
+ | 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, | ||
+ | public static final class_1792 CUSTOM_MATERIAL_CHESTPLATE = new class_1738(CUSTOM_ARMOR_MATERIAL, | ||
+ | public static final class_1792 CUSTOM_MATERIAL_LEGGINGS = new class_1738(CUSTOM_ARMOR_MATERIAL, | ||
+ | public static final class_1792 CUSTOM_MATERIAL_BOOTS = new class_1738(CUSTOM_ARMOR_MATERIAL, | ||
- | <code java [enable_line_numbers=" | ||
- | public enum CustomArmorMaterial implements ArmorMaterial { | ||
- | WOOL(" | ||
- | return Ingredient.ofItems(Items.WHITE_WOOL); | ||
- | }); | ||
- | [...] | ||
} | } | ||
- | </code> | + | </yarncode> |
- | Feel free to change any values. | + | 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. |
- | ==== Creating Armor Items ==== | + | We'll be writing this right below your last <yarn class_1738> |
+ | |||
+ | < | ||
+ | public static void register() { | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | class_2378.method_10230(class_7923.field_41178, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Your armor items are done. Now we'll just call the Registry on our main class (and annotate the new group). | ||
- | Back in the main class, you can now create it like so: | + | < |
+ | public static final class_1761 EXAMPLE_MOD_GROUP = FabricItemGroupBuilder.create( | ||
+ | new class_2960(" | ||
+ | .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(); | ||
- | <code java [enable_line_numbers=" | + | @Override |
- | public | + | public |
- | public static final Item WOOL_HELMET = new ArmorItem(CustomArmorMaterial.WOOL, | + | |
- | | + | |
- | public static final Item WOOL_LEGGINGS = new ArmorItem(CustomArmorMaterial.WOOL, | + | |
- | public static final Item WOOL_BOOTS = new ArmorItem(CustomArmorMaterial.WOOL, | + | |
} | } | ||
- | </code> | + | </yarncode> |
- | ==== Registering Armor Items ==== | + | 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. | ||
- | Register them the same way you'd register a normal item. | ||
- | <code java [enable_line_numbers=true]> | ||
- | [...] | ||
- | public void onInitialize() { | ||
- | Registry.register(Registry.ITEM, | ||
- | Registry.register(Registry.ITEM, | ||
- | Registry.register(Registry.ITEM, | ||
- | Registry.register(Registry.ITEM, | ||
- | } | ||
- | </ | ||
==== Texturing ==== | ==== Texturing ==== | ||
- | Since you already know how to make item models and textures, we won't go over them here. (They' | + | We're going to assume |
+ | * Have the textures for each armor item (x_helmet.png, x_chestplate.png etc.) | ||
+ | * Have the textures | ||
- | < | + | 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": |
- | "pack_format": | + | "textures": |
- | "description": "Tutorial Mod" | + | "layer0": "tutorial: |
- | } | + | } |
} | } | ||
</ | </ | ||
- | Now you can finally place your textures | + | Repeat with all armor items. |
+ | |||
+ | Generally, mod textures | ||
+ | To give your on-body armor a texture, place X_layer_1.png and X_layer_2.png (where X is the <yarn method_7694> | ||
+ | |||
If you followed everything, you should now be able to have a full armor set! | If you followed everything, you should now be able to have a full armor set! |
tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p