tutorial:enchantments
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:enchantments [2019/07/02 22:38] – change enchantment type so tut makes more sense draylar | tutorial:enchantments [2022/06/23 00:42] – Updated tutorial to 1.19 outercloudstudio | ||
---|---|---|---|
Line 10: | Line 10: | ||
==== Creating Enchantment Class ==== | ==== Creating Enchantment Class ==== | ||
- | We'll be creating an enchantment called //Frost//, which slows mobs. The slowness effect durability | + | Our new enchantment |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class FrostEnchantment extends Enchantment | + | public class FrostEnchantment extends Enchantment { |
- | { | + | public |
- | public | + | super(Enchantment.Rarity.UNCOMMON, EnchantmentTarget.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND}); |
- | | + | |
- | super(weight, target, slots) | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | You'll have to 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 | ||
- | public int getMinimumPower(int int_1) | + | public int getMinPower(int level) { |
- | { | + | |
return 1; | return 1; | ||
} | } | ||
</ | </ | ||
- | '' | + | '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public int getMaximumLevel() | + | public int getMaxLevel() { |
- | { | + | |
return 3; | return 3; | ||
} | } | ||
</ | </ | ||
- | Finally, we' | + | Finally, we will implement our slowness effect in the '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public void onTargetDamaged(LivingEntity user, Entity target, int level) | + | public void onTargetDamaged(LivingEntity user, Entity target, int level) { |
- | { | + | if(target instanceof LivingEntity) { |
- | if(target instanceof LivingEntity) | + | ((LivingEntity) target).addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, |
- | | + | |
- | ((LivingEntity) target).addPotionEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, | + | |
} | } | ||
Line 54: | Line 48: | ||
} | } | ||
</ | </ | ||
- | Pretty simple logic: if the entity we' | + | 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 ==== | ||
Registering enchantments follows the same process as usual: | Registering enchantments follows the same process as usual: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | private | + | public class EnchantingExample implements ModInitializer { |
+ | public | ||
- | @Override | + | |
- | public void onInitialize() | + | public void onInitialize() { |
- | { | + | Registry.register(Registry.ENCHANTMENT, |
- | FROST = Registry.register( | + | |
- | | + | |
- | new Identifier(" | + | |
- | new FrostEnchantment( | + | |
- | Enchantment.Weight.VERY_RARE, | + | |
- | EnchantmentTarget.WEAPON, | + | |
- | new EquipmentSlot[] { | + | |
- | EquipmentSlot.MAINHAND | + | |
- | } | + | |
- | ) | + | |
- | | + | |
} | } | ||
</ | </ | ||
- | This registers our enchantment under the namespace '' | + | This registers our enchantment under the namespace '' |
==== Adding Translations & Testing ==== | ==== Adding Translations & Testing ==== | ||
Line 89: | Line 101: | ||
</ | </ | ||
- | If you go in-game, you should be able to enchant main hand weapons with your new enchant: | + | If you go in-game, |
tutorial/enchantments.txt · Last modified: 2023/01/04 13:52 by datsuns