tutorial:enchantments
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:enchantments [2019/07/02 20:08] – initial kermit 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 | + | You'll have to override a few basic methods for basic functionality: |
- | public float getAttackDamage(int level, EntityGroup group) | + | |
- | { | + | |
- | // .... | + | |
- | } | + | |
- | | + | '' |
- | public int getMinimumPower(int int_1) | + | <code java [enable_line_numbers=" |
- | { | + | @Override |
- | // .... | + | public int getMinimumPower(int int_1) |
- | } | + | { |
+ | | ||
+ | } | ||
+ | </ | ||
- | | + | '' |
- | public int getMaximumLevel() | + | <code java [enable_line_numbers=" |
- | { | + | @Override |
- | // .... | + | public int getMaximumLevel() |
- | } | + | { |
+ | | ||
+ | } | ||
+ | </ | ||
- | | + | Finally, we'll implement our slowness effect in the '' |
- | public | + | <code java [enable_line_numbers=" |
+ | @Override | ||
+ | public | ||
+ | { | ||
+ | if(target instanceof LivingEntity) | ||
{ | { | ||
- | | + | |
} | } | ||
+ | |||
+ | 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 enchantments follows the same process | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
- | public | + | private static Enchantment FROST; |
+ | |||
+ | @Override | ||
+ | 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