tutorial:enchantments
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:enchantments [2020/07/03 18:36] – more formatting fixes draylar | tutorial:enchantments [2023/01/04 13:52] (current) – [Registering Enchantment] In Sample Code: pass FROST variable to the 3rd param of Registry#register(). datsuns | ||
---|---|---|---|
Line 10: | Line 10: | ||
==== Creating Enchantment Class ==== | ==== Creating Enchantment Class ==== | ||
- | Our new enchantment is called //Frost// and slows mobs on hit. The slowness effect, durability, and potency will grow relative to the level of the enchantment. In our enchantment class, we pass up '' | + | Our new enchantment is called //Frost// and slows mobs on hit. The slowness effect, durability, and potency will grow relative to the level of the enchantment. In our enchantment class, we pass up '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class FrostEnchantment extends Enchantment { | public class FrostEnchantment extends Enchantment { | ||
- | |||
public FrostEnchantment() { | public FrostEnchantment() { | ||
- | super(Enchantment.Rarity.VERY_RARE, EnchantmentTarget.WEAPON, | + | super(Enchantment.Rarity.UNCOMMON, EnchantmentTarget.WEAPON, |
} | } | ||
} | } | ||
Line 22: | Line 21: | ||
We will now override a few basic methods for basic functionality: | We will now override a few basic methods for basic functionality: | ||
- | '' | + | '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
Line 50: | Line 49: | ||
</ | </ | ||
If the entity we are hitting can have status effects ('' | If the entity we are hitting can have status effects ('' | ||
+ | |||
+ | The final enchantment file should look like this. | ||
+ | <code java [enable_line_numbers=" | ||
+ | public class FrostEnchantment extends Enchantment { | ||
+ | public FrostEnchantment() { | ||
+ | super(Enchantment.Rarity.UNCOMMON, | ||
+ | } | ||
+ | | ||
+ | @Override | ||
+ | public int getMinPower(int level) { | ||
+ | return 1; | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public int getMaxLevel() { | ||
+ | return 3; | ||
+ | } | ||
+ | |||
+ | public void onTargetDamaged(LivingEntity user, Entity target, int level) { | ||
+ | if(target instanceof LivingEntity) { | ||
+ | ((LivingEntity) target).addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, | ||
+ | } | ||
+ | |||
+ | super.onTargetDamaged(user, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
==== Registering Enchantment ==== | ==== Registering Enchantment ==== | ||
Line 55: | Line 81: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class EnchantingExample implements ModInitializer { | public class EnchantingExample implements ModInitializer { | ||
- | + | public | |
- | private | + | |
- | Registry.ENCHANTMENT, | + | |
- | new Identifier(" | + | |
- | | + | |
- | | + | |
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
+ | Registry.register(Registries.ENCHANTMENT, | ||
} | } | ||
} | } | ||
</ | </ | ||
- | This registers our enchantment under the namespace '' | + | This registers our enchantment under the namespace '' |
==== Adding Translations & Testing ==== | ==== Adding Translations & Testing ==== |
tutorial/enchantments.1593801406.txt.gz · Last modified: 2020/07/03 18:36 by draylar