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 [2020/10/09 19:04] – Knockback warning sakira | tutorial:armor [2020/10/09 19:58] – [Creating Armor Items] 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, | + | |
+ | Now that you have the basics of the armor material class, | ||
+ | |||
+ | ==== Creating Armor Items ==== | ||
+ | |||
+ | We're gonna make a new class called RegisterItems to implement | ||
+ | |||
+ | The syntax of groups is // | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public | + | public |
- | WOOL(" | + | |
- | return Ingredient.ofItems(Items.WHITE_WOOL); | + | |
- | | + | |
- | | + | // If you made a new material, this is where you would note it. |
+ | public static final Item CUSTOM_MATERIAL_HELMET = new ArmorItem(CustomArmorMaterial, EquipmentSlot.HEAD, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); | ||
+ | public static final Item CUSTOM_MATERIAL_CHESTPLATE = new ArmorItem(CustomArmorMaterial, EquipmentSlot.CHEST, new Item.Settings().group(ExampleMod.EXAMPLE_MOD_GROUP)); | ||
+ | | ||
+ | | ||
} | } | ||
</ | </ | ||
- | 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=" |
+ | | ||
+ | Registry.register(Registry.ITEM, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | Registry.register(Registry.ITEM, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Your armor items are done. Now we'll just call the Registry on our main class. | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class ExampleMod implements ModInitializer { | + | @Override |
- | public | + | public |
- | | + | |
- | | + | } |
- | public static final Item WOOL_BOOTS = new ArmorItem(CustomArmorMaterial.WOOL, | + | |
- | } | + | |
</ | </ | ||
+ | |||
==== Registering Armor Items ==== | ==== Registering Armor Items ==== |
tutorial/armor.txt · Last modified: 2023/08/20 10:19 by wjz_p