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 revision
Previous revision
Next revisionBoth sides next revision
tutorial:enchantments [2020/07/03 18:33] – formatting changes + mapping updates draylartutorial:enchantments [2020/07/03 19:02] 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 ''UNCOMMON'' 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.UNCOMMONEnchantmentTarget.WEAPONnew EquipmentSlot[] {EquipmentSlot.MAINHAND});
     }     }
 } }
Line 22: Line 22:
 We will now override a few basic methods for basic functionality: We will now override a few basic methods for basic functionality:
  
-''getMinPower'' is related to the minimum level needed to see the enchant in a 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.+''getMinPower'' is related to the minimum level needed to see the enchant in a 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. Note that the max power of an enchantment is set to ''min(level) + 5'' by default, which means this enchantment will only appear at very low levels. You will have to tweak your enchantment properties on your own and look at similar enchantment values to find the sweet number spot.
 <code java [enable_line_numbers="false"]> <code java [enable_line_numbers="false"]>
 @Override @Override
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''. All non-treasure enchantments are available in an enchanting tableincluding the ones you register.
  
 ==== Adding Translations & Testing ==== ==== Adding Translations & Testing ====
tutorial/enchantments.txt · Last modified: 2023/01/04 13:52 by datsuns