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 20:23] – finish up end of tut draylar | tutorial:enchantments [2020/07/03 18:36] – more formatting fixes draylar | ||
---|---|---|---|
Line 7: | Line 7: | ||
* add translations for your enchantment ((When you register enchantments, | * add translations for your enchantment ((When you register enchantments, | ||
- | Enchantments can either have custom functionality implemented separately (such as smelting ores mined) or can use already existing mechanics (such as '' | + | Enchantments can either have custom functionality implemented separately (such as smelting ores mined) or can use already existing mechanics (such as '' |
==== Creating Enchantment Class ==== | ==== 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 | + | Our new enchantment |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class WrathEnchantment | + | public class FrostEnchantment |
- | { | + | |
- | public WrathEnchantment(Weight weight, int typeIndex, EquipmentSlot... slots) | + | |
- | { | + | |
- | super(weight, | + | |
- | } | + | |
- | | + | public |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int getMinimumPower(int int_1) | + | |
- | { | + | |
- | // .... | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int getMaximumLevel() | + | |
- | | + | |
- | // .... | + | |
- | | + | |
- | + | ||
- | @Override | + | |
- | public boolean differs(Enchantment enchantment) | + | |
- | { | + | |
- | // .... | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | '' | + | We will now override a few basic methods for basic functionality: |
+ | |||
+ | '' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public | + | public |
- | { | + | return 1; |
- | return | + | |
} | } | ||
</ | </ | ||
- | '' | + | '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public int getMinimumPower(int int_1) | + | public int getMaxLevel() { |
- | { | + | return |
- | return | + | |
} | } | ||
</ | </ | ||
- | '' | + | Finally, we will implement our slowness effect in the '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public | + | public |
- | { | + | |
- | | + | ((LivingEntity) target).addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, |
- | } | + | } |
- | </ | + | |
- | Finally, '' | + | |
- | <code java [enable_line_numbers=" | + | |
- | @Override | + | |
- | public boolean differs(Enchantment enchantment) | + | |
- | { | + | |
- | return | + | |
} | } | ||
</ | </ | ||
+ | If the entity we are hitting can have status effects ('' | ||
==== 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 static Enchantment WRATH; | + | public class EnchantingExample implements ModInitializer { |
- | @Override | + | private static Enchantment FROST = Registry.register( |
- | public void onInitialize() | + | Registry.ENCHANTMENT, |
- | { | + | new Identifier(" |
- | WRATH = Registry.register( | + | new FrostEnchantment() |
- | Registry.ENCHANTMENT, | + | |
- | new Identifier(" | + | |
- | new WrathEnchantment( | + | |
- | Enchantment.Weight.VERY_RARE, | + | |
- | 0, | + | |
- | EquipmentSlot.MAINHAND | + | |
- | ) | + | |
); | ); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | |||
+ | } | ||
} | } | ||
</ | </ | ||
- | This registers our enchantment under the namespace '' | + | This registers our enchantment under the namespace '' |
==== Adding Translations & Testing ==== | ==== Adding Translations & Testing ==== | ||
Line 108: | Line 76: | ||
<code json [enable_line_numbers=" | <code json [enable_line_numbers=" | ||
{ | { | ||
- | " | + | " |
} | } | ||
</ | </ | ||
- | 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