tutorial:armor
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
tutorial:armor [2020/10/09 19:04] – Knockback warning sakira | tutorial:armor [2020/10/09 19:34] – [Creating an Armor Material class] sakira | ||
---|---|---|---|
Line 9: | Line 9: | ||
==== 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: |
- | If you' | + | And the new value introduced |
- | - Knockback Resistance. This is the scale of the amount of knockback | + | - getKnockbackResistance: |
- | 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 |
- | 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' | + | |
<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 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); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | '' | + | @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 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.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() { | public float getKnockbackResistance() { | ||
- | return | + | return |
} | } | ||
} | } | ||
</ | </ | ||
- | 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 ==== |
tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p