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:13] – finished class creation section draylar | tutorial:enchantments [2019/07/02 22:39] – 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 | + | 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 WrathEnchantment(Weight weight, | + | public WrathEnchantment(Weight weight, |
{ | { | ||
- | 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=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public | + | public |
{ | { | ||
- | return | + | return 1; |
} | } | ||
</ | </ | ||
- | '' | + | '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public int getMinimumPower(int int_1) | + | public int getMaximumLevel() |
{ | { | ||
- | return | + | return |
} | } | ||
</ | </ | ||
- | '' | + | Finally, we'll implement our slowness effect in the '' |
<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. | ||
- | Finally, '' | + | ==== Registering Enchantment ==== |
+ | Registering | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
+ | private static Enchantment FROST; | ||
+ | |||
@Override | @Override | ||
- | public | + | public |
{ | { | ||
- | | + | |
+ | Registry.ENCHANTMENT, | ||
+ | new Identifier(" | ||
+ | new FrostEnchantment( | ||
+ | Enchantment.Weight.VERY_RARE, | ||
+ | EnchantmentTarget.WEAPON, | ||
+ | new EquipmentSlot[] { | ||
+ | EquipmentSlot.MAINHAND | ||
+ | } | ||
+ | ) | ||
+ | ); | ||
} | } | ||
</ | </ | ||
+ | |||
+ | 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