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:58] – [Creating Armor Items] 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:+ 
 +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"). This setup will also put the items on a new Creative tab, but you're free to delete that part.  
 + 
 +The syntax of groups is //.group([Your mod name here].[YOUR_MOD_NAME_BUT_IN_CAPS]_GROUP)//. I'll be referring to it as ExampleMod:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public enum CustomArmorMaterial implements ArmorMaterial +public class RegisterItems 
-    WOOL("wool", 5, new int[]{1,3,2,1}15, SoundEvents.BLOCK_WOOL_PLACE0.0F, () -> { + 
-        return Ingredient.ofItems(Items.WHITE_WOOL); +   public static final ArmorMaterial customArmorMaterial = new CustomArmorMaterial(); 
-    }); +   public static final Item CUSTOM_MATERIAL = new CustomMaterialItem(new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); 
-    [...]+    // If you made a new materialthis is where you would note it. 
 +    public static final Item CUSTOM_MATERIAL_HELMET = new ArmorItem(CustomArmorMaterialEquipmentSlot.HEADnew Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); 
 +    public static final Item CUSTOM_MATERIAL_CHESTPLATE = new ArmorItem(CustomArmorMaterialEquipmentSlot.CHESTnew Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); 
 +    public static final Item CUSTOM_MATERIAL_LEGGINGS = new ArmorItem(CustomArmorMaterial, EquipmentSlot.LEGS, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); 
 +    public static final Item CUSTOM_MATERIAL_BOOTS = new ArmorItem(CustomArmorMaterial, EquipmentSlot.FEET, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); 
 } }
 </code> </code>
  
-Feel free to change any values.+Now that your items are properly created, lets register them and give them proper names. Your first parameter is going to be your namespace, which is your ModID, 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 ArmorItem.
  
-Back in the main class, you can now create it like so:+<code java [enable_line_numbers="true"]> 
 + public static void register() { 
 +        Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material"), CUSTOM_MATERIAL); 
 +        Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_helmet"), CUSTOM_MATERIAL_HELMET); 
 +        Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_chestplate"), CUSTOM_MATERIAL_CHESTPLATE); 
 +        Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_leggings"), CUSTOM_MATERIAL_LEGGINGS); 
 +        Registry.register(Registry.ITEM, new Identifier("examplemod", "custom_material_boots"), CUSTOM_MATERIAL_BOOTS); 
 +    } 
 +</code> 
 + 
 +Your armor items are done. Now we'll just call the Registry on our main class.
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public class ExampleMod implements ModInitializer { +@Override 
-    public static final Item WOOL_HELMET = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.HEAD, (new Item.Settings().group(ItemGroup.COMBAT))); +    public void onInitialize() { 
-    public static final Item WOOL_CHESTPLATE = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.CHEST, (new Item.Settings().group(ItemGroup.COMBAT))); +        RegisterItems.register(); 
-    public static final Item WOOL_LEGGINGS = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.LEGS, (new Item.Settings().group(ItemGroup.COMBAT))); +    }
-    public static final Item WOOL_BOOTS = new ArmorItem(CustomArmorMaterial.WOOL, EquipmentSlot.FEET, (new Item.Settings().group(ItemGroup.COMBAT))); +
-}+
 </code> </code>
 +
  
 ==== Registering Armor Items ==== ==== Registering Armor Items ====
Line 167: Line 154:
 { {
     "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