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:04] – Knockback warning 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 ====
Line 28: Line 30:
   - Toughness. This is a second protection value where the armor is more durable against high value attacks.   - Toughness. This is a second protection value where the armor is more durable against high value attacks.
   - A repair ingredient. This will be a ''Supplier<Ingredient>'' instance instead of an ''Item'', which will go over in a bit.   - A repair ingredient. This will be a ''Supplier<Ingredient>'' instance instead of an ''Item'', which will go over in a bit.
 +
 +If you're on 1.16+, they also have a new argument:
 +  - Knockback Resistance. This is the scale of the amount of knockback resisted from attacks, explosions, and projectiles. 1.0 is 100%.
  
 With those arguments, it should now look something like this: With those arguments, it should now look something like this:
Line 33: Line 38:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 public enum CustomArmorMaterial implements ArmorMaterial { public enum CustomArmorMaterial implements ArmorMaterial {
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {+    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
                  
     }     }
Line 49: Line 54:
     private final SoundEvent equipSound;     private final SoundEvent equipSound;
     private final float toughness;     private final float toughness;
 +    private final float knockbackResistance;
     private final Lazy<Ingredient> repairIngredient;     private final Lazy<Ingredient> repairIngredient;
          
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {+    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
         this.name = name;         this.name = name;
         this.durabilityMultiplier = durabilityMultiplier;         this.durabilityMultiplier = durabilityMultiplier;
Line 58: Line 64:
         this.equipSound = soundEvent;         this.equipSound = soundEvent;
         this.toughness = toughness;         this.toughness = toughness;
 +        this.knockbackResistance = knockbackResistance;
         this.repairIngredient = new Lazy(repairIngredient); // We'll need this to be a Lazy type for later.         this.repairIngredient = new Lazy(repairIngredient); // We'll need this to be a Lazy type for later.
     }     }
Line 76: Line 83:
     private final SoundEvent equipSound;     private final SoundEvent equipSound;
     private final float toughness;     private final float toughness;
 +    private final float knockbackResistance;
     private final Lazy<Ingredient> repairIngredient;     private final Lazy<Ingredient> repairIngredient;
          
-    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairIngredient) {+    CustomArmorMaterial(String name, int durabilityMultiplier, int[] armorValueArr, int enchantability, SoundEvent soundEvent, float toughness, float knockbackResistance, Supplier<Ingredient> repairIngredient) {
         this.name = name;         this.name = name;
         this.durabilityMultiplier = durabilityMultiplier;         this.durabilityMultiplier = durabilityMultiplier;
Line 116: Line 124:
     public float getToughness() {     public float getToughness() {
         return this.toughness;         return this.toughness;
 +    }
 +    
 +    public float getKnockbackResistance() {
 +        return this.knockbackResistance;
     }     }
 } }
Line 124: Line 136:
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
 public enum CustomArmorMaterial implements ArmorMaterial { public enum CustomArmorMaterial implements ArmorMaterial {
-    WOOL("wool", 5, new int[]{1,3,2,1}, 15, SoundEvents.BLOCK_WOOL_PLACE, 0.0F, () -> {+    WOOL("wool", 5, new int[]{1,3,2,1}, 15, SoundEvents.BLOCK_WOOL_PLACE, 0.0F, 0.0F, () -> {
         return Ingredient.ofItems(Items.WHITE_WOOL);         return Ingredient.ofItems(Items.WHITE_WOOL);
     });     });
Line 167: Line 179:
 { {
     "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