User Tools

Site Tools


tutorial:enchantments

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:enchantments [2020/05/10 11:37] – addPotionEffect -> addStatusEffect sirwindfieldtutorial:enchantments [2020/07/03 18:33] – formatting changes + mapping updates draylar
Line 10: Line 10:
  
 ==== Creating Enchantment Class ==== ==== Creating Enchantment Class ====
-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.+Our new enchantment is called //Frost// and slows mobs on hit. The slowness effectdurability, and potency will grow relative to the level of the enchantment.
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public class FrostEnchantment extends Enchantment  +public class FrostEnchantment extends Enchantment { 
-+ 
-    public FrostEnchantment(Weight weight, EnchantmentTarget target, EquipmentSlot[] slots) +    public FrostEnchantment(Rarity rarity, EnchantmentTarget type, EquipmentSlot[] slots) { 
-    +        super(raritytype, slots)
-        super(weighttarget, slots)+
     }     }
 } }
 </code> </code>
  
-You'll have to override a few basic methods for basic functionality:+We will now override a few basic methods for basic functionality:
  
-''getMinimumPower'' is the minimum level required to get the enchant in an enchanting table. We'll set it to 1, so you can get it at any level:+''getMinPower'' is related to the minimum level needed to see the enchant in table, but it is not a 1:1 ratio. Most enchantments return something like ''10 * level''with different scales depending on the max level and rarity of the enchantment. We will return 1 so it is always available.
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
 @Override @Override
-public int getMinimumPower(int int_1) +public int getMinPower(int level) {
-{+
     return 1;     return 1;
 } }
 </code> </code>
  
-''getMaximumLevel'' is the number of tiers the enchantment has. ((Enchantments with more than a single tier will have roman numerals after the name to show the level. If the enchantment only has a single level, nothing is added.))+''getMaxLevel'' is the number of levels the enchantment has. Sharpness has a max level of 5. ((Enchantments with more than a single level will have roman numerals after the name to show the level. If the enchantment only has a single level, nothing is added.))
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
 @Override @Override
-public int getMaximumLevel() +public int getMaxLevel() {
-{+
     return 3;     return 3;
 } }
 </code> </code>
  
-Finally, we'll implement our slowness effect in the ''onTargetDamage'' method, which is called when you whack an enemy with a tool that has your enchantment.+Finally, we will implement our slowness effect in the ''onTargetDamage'' method, which is called when you whack an enemy with a tool that has your enchantment.
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
 @Override @Override
-public void onTargetDamaged(LivingEntity user, Entity target, int level) +public void onTargetDamaged(LivingEntity user, Entity target, int level) { 
-+    if(target instanceof LivingEntity) {
-    if(target instanceof LivingEntity) +
-    {+
         ((LivingEntity) target).addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 20 * 2 * level, level - 1));         ((LivingEntity) target).addStatusEffect(new StatusEffectInstance(StatusEffects.SLOWNESS, 20 * 2 * level, level - 1));
     }     }
Line 54: Line 49:
 } }
 </code> </code>
-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.+If the entity we are hitting can have status effects (''LivingEntity''s can have status effects, but not ''Entity''), give it the slowness effect. The duration of the effect is 2 seconds per level, and the potency is equivalent to the level.
  
 ==== Registering Enchantment ==== ==== Registering Enchantment ====
Line 62: Line 57:
  
 @Override @Override
-public void onInitialize() +public void onInitialize() {
-{+
     FROST = Registry.register(     FROST = Registry.register(
         Registry.ENCHANTMENT,         Registry.ENCHANTMENT,
Line 90: Line 84:
  
 If you go in-game, [[https://i.imgur.com/31nFl2H.png|you should be able to enchant main hand weapons with your new enchant.]] If you go in-game, [[https://i.imgur.com/31nFl2H.png|you should be able to enchant main hand weapons with your new enchant.]]
- 
  
  
  
  
tutorial/enchantments.txt · Last modified: 2023/01/04 13:52 by datsuns