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/12/26 22:10] – Fix class name modmuss50 | tutorial:enchantments [2020/07/03 18:33] – formatting changes + mapping updates draylar | ||
---|---|---|---|
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 FrostEnchantment(Weight weight, EnchantmentTarget | + | public FrostEnchantment(Rarity rarity, EnchantmentTarget |
- | | + | super(rarity, type, slots) |
- | 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 49: | ||
} | } | ||
</ | </ | ||
- | Pretty simple logic: if the entity we' | + | If the entity we are hitting can have status effects |
==== Registering Enchantment ==== | ==== Registering Enchantment ==== | ||
Line 62: | Line 57: | ||
@Override | @Override | ||
- | public void onInitialize() | + | public void onInitialize() { |
- | { | + | |
FROST = Registry.register( | FROST = Registry.register( | ||
Registry.ENCHANTMENT, | Registry.ENCHANTMENT, | ||
Line 90: | Line 84: | ||
If you go in-game, [[https:// | If you go in-game, [[https:// | ||
- | |||
tutorial/enchantments.txt · Last modified: 2023/01/04 13:52 by datsuns