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/07/03 18:33] – formatting changes + mapping updates draylartutorial:enchantments [2020/07/03 18:36] – more formatting fixes draylar
Line 10: Line 10:
  
 ==== Creating Enchantment Class ==== ==== Creating Enchantment Class ====
-Our new enchantment is called //Frost// and slows mobs on hit. The slowness effect, durability, and potency will grow relative to the level of the enchantment.+Our new enchantment is called //Frost// and slows mobs on hit. The slowness effect, durability, and potency will grow relative to the level of the enchantment. In our enchantment class, we pass up ''VERY_RARE'' as the enchantment rarity, ''WEAPON'' as the enchantment target, and ''MAINHAND'' as the only valid tool type for our 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(Rarity rarity, EnchantmentTarget type, EquipmentSlot[] slots) { +    public FrostEnchantment() { 
-        super(raritytypeslots)+        super(Enchantment.Rarity.VERY_RAREEnchantmentTarget.WEAPONnew EquipmentSlot[] {EquipmentSlot.MAINHAND});
     }     }
 } }
Line 54: Line 54:
 Registering enchantments follows the same process as usual: Registering enchantments follows the same process as usual:
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
-private static Enchantment FROST;+public class EnchantingExample implements ModInitializer {
  
-@Override +    private static Enchantment FROST = Registry.register( 
-public void onInitialize() { +            Registry.ENCHANTMENT, 
-    FROST = Registry.register( +            new Identifier("tutorial", "frost"), 
-        Registry.ENCHANTMENT, +            new FrostEnchantment()
- new Identifier("tutorial", "frost"), +
- new FrostEnchantment( +
-     Enchantment.Weight.VERY_RARE, +
-     EnchantmentTarget.WEAPON, +
-     new EquipmentSlot[] { +
- EquipmentSlot.MAINHAND +
-     } +
- )+
     );     );
 +
 +    @Override
 +    public void onInitialize() {
 +
 +    }
 } }
 </code> </code>
  
-This registers our enchantment under the namespace ''tutorial:frost'', sets it as a very rare enchantment, and only allows it on main hand tools.+This registers our enchantment under the namespace ''tutorial:frost''.
  
 ==== Adding Translations & Testing ==== ==== Adding Translations & Testing ====
tutorial/enchantments.txt · Last modified: 2023/01/04 13:52 by datsuns