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:17] – finished registry section draylar | tutorial:enchantments [2019/12/26 22:10] – Fix class name modmuss50 | ||
---|---|---|---|
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 | + | We'll be creating an enchantment called //Frost//, which slows mobs. The slowness effect durability & potency will grow relative to the level of the enchantment. |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public class WrathEnchantment | + | public class FrostEnchantment |
{ | { | ||
- | public | + | public |
{ | { | ||
- | super(weight, | + | super(weight, |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public float getAttackDamage(int level, EntityGroup group) | + | |
- | { | + | |
- | // .... | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int getMinimumPower(int int_1) | + | |
- | { | + | |
- | // .... | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public int getMaximumLevel() | + | |
- | { | + | |
- | // .... | + | |
- | } | + | |
- | + | ||
- | @Override | + | |
- | public boolean differs(Enchantment enchantment) | + | |
- | { | + | |
- | // .... | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | '' | + | You'll have to override a few basic methods for basic functionality: |
- | <code java [enable_line_numbers=" | + | |
- | @Override | + | |
- | public float getAttackDamage(int level, EntityGroup group) | + | |
- | { | + | |
- | return level * 1.5f; | + | |
- | } | + | |
- | </ | + | |
'' | '' | ||
Line 59: | Line 28: | ||
public int getMinimumPower(int int_1) | public int getMinimumPower(int int_1) | ||
{ | { | ||
- | return 1;; | + | return 1; |
} | } | ||
</ | </ | ||
Line 68: | Line 37: | ||
public int getMaximumLevel() | public int getMaximumLevel() | ||
{ | { | ||
- | return | + | return |
} | } | ||
</ | </ | ||
- | Finally, '' | + | Finally, |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public | + | public |
{ | { | ||
- | | + | |
+ | { | ||
+ | ((LivingEntity) target).addPotionEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, | ||
+ | } | ||
+ | |||
+ | super.onTargetDamaged(user, | ||
} | } | ||
</ | </ | ||
+ | Pretty simple logic: if the entity we're hitting can have status effects, give it slowness. The time is 2 seconds per level, and the potency is equivalent to the level. | ||
==== 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 78: | ||
</ | </ | ||
- | This registers our enchantment under the namespace '' | + | This registers our enchantment under the namespace '' |
+ | |||
+ | ==== Adding Translations & Testing ==== | ||
+ | You'll need to add a translation to your enchantment as well. Head over to your [[tutorial: | ||
+ | |||
+ | <code json [enable_line_numbers=" | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | If you go in-game, [[https:// | ||
+ | |||
+ | |||
+ | |||
+ |
tutorial/enchantments.txt · Last modified: 2023/01/04 13:52 by datsuns