User Tools

Site Tools


tutorial:armor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:armor [2019/09/27 20:42] – SoundEvents.ITEM_ARMOR_EQUIP_X, as SoundEvents.ITEM.EQUIP.ARMOR.X doesn't exist descuddlebattutorial:armor [2020/10/09 19:34] – [Creating an Armor Material class] sakira
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. To add Armor, we'll first make a custom material class, then register the items. We'll also take a look at how to texture them.+While Armor is a bit more complicated to add then a normal block/item, once you can understand it, it becomes simple to make. 
 +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).
  
 ==== 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), we'll have to create a new class for custom ArmorMaterial+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 will be an enum type. It'll need a lot of arguments, mainly the name, durability, etc., so for now we'll just leave it empty. Don't worry about any errors for now.+This class will implement ArmorMaterialand it'll start by assigning values to armor points (called PROTECTION_VALUES). All its following arguments will make use of @Override.
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public enum CustomArmorMaterial implements ArmorMaterial { +public class CustomArmorMaterial implements ArmorMaterial { 
-    CustomArmorMaterial() +    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 helmet, B chestplate, C leggings and D boots.  
 +    // For reference, Leather uses {1, 2, 3, 1}, and Diamond/Netherite {3, 6, 8, 3}
 } }
 </code> </code>
  
-Since there's a lot of arguments neededhere's a list explaining each one of them.+The next arguments are defined as follows (don't worry about the namesyou'll see how we implement it below them):
  
-  - A String name. This will be used as a sort of "armor tag" for later. +  - getDurability: how many hits can armor take before breakingUses the int we wrote on 'BASE_DURABILITY' to calculate. Leather uses 5, Diamond 33, Netherite 37
-  - A durability multiplier. This will be the number that will be used to determine the durability based on the base values+  - getPretectionAmount: calls for the 'PROTECTION_VALUES' int we already wrote above
-  - Armor values, or "Protection Amounts" in the vanilla code. This will be an int array+  - getEnchantability: This will be how likely the armor can get high level or multiple enchantments in an enchantment book. 
-  - Enchantability. This will be how likely the armor can get high level or multiple enchantments in an enchantment book. +  - SoundEvent getEquipSound: The standard used by vanilla armor is ''SoundEvents.ITEM_ARMOR_EQUIP_X'', X being the type of armor. 
-  - A sound event. The standard used by vanilla armor is ''SoundEvents.ITEM_ARMOR_EQUIP_X'', X being the type of armor. +  - Ingredient getRepairIngridient: what item are we gonna be using to repair the armor on an anvilIt can be either a vanilla item or one of your own. 
-  - Toughness. This is a second protection value where the armor is more durable against high value attacks. +  - String getName: what the parent item of the armor is. In Diamond armor, it'd be "diamond"
-  - A repair ingredientThis will be a ''Supplier<Ingredient>'' instance instead of an ''Item'', which will go over in a bit.+  - getToughness: This is a second protection value where the armor is more durable against high value attacks. Value goes as 'X.0F'
  
-With those arguments, it should now look something like this:+And the new value introduced on 1.16 
 +  - getKnockbackResistance: leave this value at 0. If you want to implement itwrite '0.XF' (in which X is how much knockback protection you want), and I'll teach you how to make it work later on.
  
-<code java [enable_line_numbers="true"]> 
-public enum CustomArmorMaterial implements ArmorMaterial { 
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) { 
-         
-    } 
-} 
-</code> 
  
-We'll also have to define those values and make it usableso now it'll look like this:+I'll leave all variables written as X or A, B, C, D. With those arguments, it should now look something like this:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public enum CustomArmorMaterial implements ArmorMaterial { +public class CustomArmorMaterial implements ArmorMaterial { 
-    private final String name; +    private static final int[] BASE_DURABILITY = new int[] {13, 15, 16, 11}
-    private final int durabilityMultiplier; +    private static final int[] PROTECTION_VALUES = new int[] {ABCD};
-    private final int[] armorValues+
-    private final int enchantability; +
-    private final SoundEvent equipSound; +
-    private final float toughness; +
-    private final Lazy<Ingredient> repairIngredient; +
-     +
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArrint enchantabilitySoundEvent soundEventfloat toughness, Supplier<Ingredient> repairIngredient) { +
-        this.name = name; +
-        this.durabilityMultiplier = durabilityMultiplier; +
-        this.armorValues = armorValueArr; +
-        this.enchantability = enchantability; +
-        this.equipSound = soundEvent; +
-        this.toughness = toughness; +
-        this.repairIngredient = new Lazy(repairIngredient); // We'll need this to be a Lazy type for later. +
-    } +
-+
-</code>+
  
-''ArmorMaterial'' also needs several other methods, so we'll add them real quick here. +    @Override 
- +    public int getDurability(EquipmentSlot slot) { 
-We'll also have to add our base durability values, so for now we'll use the vanilla values ''[13, 15, 16, 11]'' +        return BASE_DURABILITY[slot.getEntitySlotId()] * X;
- +
-<code java [enable_line_numbers="true"]> +
-public enum CustomArmorMaterial implements ArmorMaterial { +
-    private static final int[] baseDurability = {13, 15, 16, 11}; +
-    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 Lazy<Ingredient> repairIngredient; +
-     +
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) { +
-        this.name = name; +
-        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) { +
-        return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier;+
     }     }
  
-    public int getProtectionAmount(EquipmentSlot equipmentSlot_1) { +    @Override 
-        return this.protectionAmounts[equipmentSlot_1.getEntitySlotId()];+    public int getProtectionAmount(EquipmentSlot slot) { 
 +        return PROTECTION_VALUES[slot.getEntitySlotId()];
     }     }
  
 +    @Override
     public int getEnchantability() {     public int getEnchantability() {
-        return this.enchantability;+        return X;
     }     }
  
 +    @Override
     public SoundEvent getEquipSound() {     public SoundEvent getEquipSound() {
-        return this.equipSound;+        return SoundEvents.ITEM_ARMOR_EQUIP_X;
     }     }
  
 +    @Override
     public Ingredient getRepairIngredient() {     public Ingredient getRepairIngredient() {
-        // We needed to make it a Lazy type so we can actually get the Ingredient from the Supplier. +        return Ingredient.ofItems(RegisterItems.X);
-        return this.repairIngredientSupplier.get();+
     }     }
  
-    @Environment(EnvType.CLIENT)+    @Override
     public String getName() {     public String getName() {
-        return this.name;+        return "name";
     }     }
  
 +    @Override
     public float getToughness() {     public float getToughness() {
-        return this.toughness;+        return X.0F; 
 +    } 
 + 
 +    @Override 
 +    public float getKnockbackResistance() { 
 +        return 0.XF;
     }     }
 } }
 </code> </code>
  
-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: 
- 
-<code java [enable_line_numbers="true"]> 
-public enum CustomArmorMaterial implements ArmorMaterial { 
-    WOOL("wool", 5, new int[]{1,3,2,1}, 15, SoundEvents.BLOCK_WOOL_PLACE, 0.0F, () -> { 
-        return Ingredient.ofItems(Items.WHITE_WOOL); 
-    }); 
-    [...] 
-} 
-</code> 
  
-Feel free to change any values.+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 ==== ==== Creating Armor Items ====
Line 167: Line 123:
 { {
     "pack":{     "pack":{
-        "pack_format":4+        "pack_format": 5
-        "description":"Tutorial Mod"+        "description": "Tutorial Mod"
     }     }
 } }
tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p