enchantment.modid.enchantname
) is what appears as the book name.tutorial:enchantments
This is an old revision of the document!
Adding Enchantments
To add enchantments to your mod, you'll need to:
- create a class that extends
Enchantment
or another existing Enchantment (such asDamageEnchantment
) - register your enchantment
- add custom functionality or mechanics if needed
- add translations for your enchantment 1)
Enchantments can either have custom functionality implemented separately (such as smelting ores mined) or can use already existing mechanics (such as DamageEnchantment
), which are applied when appropriate.
Creating Enchantment Class
We'll be creating an enchantment called Wrath, which adds an extra 1.5 points of damage, per level, to a melee weapon. The easiest way to do this is by creating a class that extends DamageEnchantment
:
public class WrathEnchantment extends DamageEnchantment { public WrathEnchantment(Weight weight, int typeIndex, EquipmentSlot... slots) { super(weight, typeIndex, slots) } @Override public float getAttackDamage(int level, EntityGroup group) { // .... } @Override public int getMinimumPower(int int_1) { // .... } @Override public int getMaximumLevel() { // .... } @Override public boolean differs(Enchantment enchantment) { // .... } }
getAttackDamage
, as you would expect, is the additional damage provided by the enchantment. level
is the level of the enchantment:
public float getAttackDamage(int level, EntityGroup group) { return level * 1.5f; }
1)
When you register enchantments, books are automatically added to the game for each level. The translated name of the enchantment (
tutorial/enchantments.1562098084.txt.gz · Last modified: 2019/07/02 20:08 by draylar