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:33] – formatting changes + mapping updates 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 | + | private static Enchantment |
@Override | @Override | ||
- | public void onInitialize() | + | public void onInitialize() { |
- | { | + | |
- | | + | |
Registry.ENCHANTMENT, | Registry.ENCHANTMENT, | ||
- | new Identifier(" | + | new Identifier(" |
- | new WrathEnchantment( | + | new FrostEnchantment( |
Enchantment.Weight.VERY_RARE, | Enchantment.Weight.VERY_RARE, | ||
- | | + | |
- | EquipmentSlot.MAINHAND | + | |
+ | EquipmentSlot.MAINHAND | ||
+ | } | ||
) | ) | ||
); | ); | ||
Line 101: | Line 72: | ||
</ | </ | ||
- | This registers our enchantment under the namespace '' | + | This registers our enchantment under the namespace '' |
==== Adding Translations & Testing ==== | ==== Adding Translations & Testing ==== | ||
Line 108: | Line 79: | ||
<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