tutorial:armor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext 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 descuddlebat | tutorial: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 | + | 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 | ||
+ | There' | ||
==== 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 ArmorMaterial and will be an enum type. It' | + | This class will implement ArmorMaterial, and it' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public | + | public |
- | | + | |
- | + | | |
- | } | + | |
+ | // In which A is helmet, B chestplate, C leggings and D boots. | ||
+ | // For reference, Leather uses {1, 2, 3, 1}, and Diamond/ | ||
} | } | ||
</ | </ | ||
- | Since there' | + | The next arguments |
- | - A String name. This will be used as a sort of "armor tag" for later. | + | - getDurability: |
- | - A durability multiplier. This will be the number that will be used to determine the durability based on the base values. | + | - getPretectionAmount: |
- | - Armor values, or " | + | - getEnchantability: |
- | - Enchantability. | + | - SoundEvent getEquipSound: |
- | - A sound event. | + | - Ingredient getRepairIngridient: |
- | - 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 " |
- | - A repair ingredient. This will be a '' | + | - getToughness: |
- | With those arguments, it should now look something like this: | + | And the new value introduced on 1.16 |
+ | - getKnockbackResistance: | ||
- | <code java [enable_line_numbers=" | ||
- | public enum CustomArmorMaterial implements ArmorMaterial { | ||
- | CustomArmorMaterial(String name, int durabilityMultiplier, | ||
- | | ||
- | } | ||
- | } | ||
- | </ | ||
- | We' | + | I' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public | + | public |
- | private | + | private |
- | private | + | private |
- | private final int[] armorValues; | + | |
- | private final int enchantability; | + | |
- | private final SoundEvent equipSound; | + | |
- | private final float toughness; | + | |
- | 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.repairIngredient = new Lazy(repairIngredient); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | '' | + | @Override |
- | + | public int getDurability(EquipmentSlot | |
- | We'll also have to add our base durability values, so for now we'll use the vanilla values '' | + | return BASE_DURABILITY[slot.getEntitySlotId()] * X; |
- | + | ||
- | <code java [enable_line_numbers=" | + | |
- | 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< | + | |
- | + | ||
- | CustomArmorMaterial(String name, int durabilityMultiplier, | + | |
- | 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 | + | |
- | return BASE_DURABILITY[equipmentSlot_1.getEntitySlotId()] * this.durabilityMultiplier; | + | |
} | } | ||
- | public int getProtectionAmount(EquipmentSlot | + | |
- | return | + | |
+ | return | ||
} | } | ||
+ | @Override | ||
public int getEnchantability() { | public int getEnchantability() { | ||
- | return | + | return |
} | } | ||
+ | @Override | ||
public SoundEvent getEquipSound() { | public SoundEvent getEquipSound() { | ||
- | return | + | return |
} | } | ||
+ | @Override | ||
public Ingredient getRepairIngredient() { | public Ingredient getRepairIngredient() { | ||
- | | + | |
- | return this.repairIngredientSupplier.get(); | + | |
} | } | ||
- | @Environment(EnvType.CLIENT) | + | @Override |
public String getName() { | public String getName() { | ||
- | return | + | return |
} | } | ||
+ | @Override | ||
public float getToughness() { | public float getToughness() { | ||
- | return | + | return |
+ | } | ||
+ | |||
+ | @Override | ||
+ | public float getKnockbackResistance() { | ||
+ | return 0.XF; | ||
} | } | ||
} | } | ||
</ | </ | ||
- | 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=" | ||
- | public enum CustomArmorMaterial implements ArmorMaterial { | ||
- | WOOL(" | ||
- | return Ingredient.ofItems(Items.WHITE_WOOL); | ||
- | }); | ||
- | [...] | ||
- | } | ||
- | </ | ||
- | 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: | ||
{ | { | ||
" | " | ||
- | " | + | " |
- | " | + | " |
} | } | ||
} | } |
tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p