Creating an Enchantment
Tutorial
Creating a new Enchantment
The first thing you need to do in order to create a new enchantment is create a new class that extends CustomEnchantment.
public class LifestealEnchantment extends CustomEnchantment
After you have a class, you need to add a Constructor that passes the enchantment name and the applicable items for the enchantment. The parameters to pass to 'super' are:
- String - the name of the enchantment (must be unique to other custom enchantments else it won't register)
- String - the description for your enchantment in the detailed list and the book
- Material[] - the types of items that can receive this enchantment through an enchanting table
- String - the conflict group of the enchantment (same group means they conflict, no group means doesn't conflict with anything)
- int - the enchantment weight (how likely it is to get the enchantment, generally between 1 and 10 where 1 is rare, 10 is common)
Note: Enchantment names must be unique to other custom enchantments
Note: You can mix and match various combinations of those parameters, but the order stays the same
// Items able to be enchanted with lifesteal static final Material[] LIFESTEAL_ITEMS = new Material[] { Material.WOOD_SWORD, Material.STONE_SWORD, Material.IRON_SWORD, Material.GOLD_SWORD, Material.DIAMOND_SWORD }; // Constructor public LifestealEnchantment() { super("Lifesteal", LIFESTEAL_ITEMS, 2); // These are optional things you can change // This is the maximum level for your enchantment // Default is 1 this.max = 5; // This changes the minimum modified level needed to get your enchant // On not normally enchanted items like blaze rods or pumpkin seeds, you should keep it as 1 // Default is 1 this.base = 10; // This one changes how easily you can get higher tiers of the enchantment // If you have a high maximum level, you probably want a small interval // Default is 10 this.interval = 8; }
For more details on the base and interval values, see the tutorial on them
Next, you can create whatever effects for the enchantment you want by overriding one or more of a few methods.
- applyEffect(LivingEntity, LivingEntity, int, EntityDamageByEntityEvent) is for on-hit effects (when you attack something)
- applyDefenseEffect(LivingEntity, LivingEntity, int, EntityDamageEvent) is for defensive effects (when you take damage)
- applyToolEffect(Player, Block, int BlockEvent) is for tool effects (when breaking blocks)
- applyMiscEffect(Player, int, PlayerInteractEvent) is for interact events (when left/right clicking)
- applyEquipEffect(Player, int) is for equipping effects (putting on armor)
- applyUnequipEffect(Player, int) is for unequipping effects (taking off armor)
- applyEntityEffect(Player, int, PlayerInteractEntityEvent) is for right clicking on entities
- applyProjectileEffect(LivingEntity, int, ProjectileLaunchEvent) is for the initial shot of a projectile
Each of these methods is optional, but you can use as many as you want (e.g. a chestplate that conjures lightning when you attack, reflects damage when you are attacked, and causes diamonds to drop from every block you break with only one enchantment is possible). In order to use one of these, simply override it and throw in whatever effect you want like this:
// An on-hit enchantment example @Override public void applyEffect(LivingEntity user, LivingEntity target, int enchantLevel, EntityDamageByEntityEvent, event) { // Gain health depending on enchantment level int health = user.getHealth() + enchantLevel; if (health > user.getMaxHealth()) health = user.getMaxHealth(); user.setHealth(health); }
Each of the types of enchantments give you the event that caused it to be activated, so you can change the outcomes of the event such as damage dealt or if a block is instantly broken.
I love that the max level is an int! *Happy creepy clowny face* and not a short *yawn*
Could you please right an article or documentation about how to use all the applyies, and their variables inside the brackets.
how do you get the lifesteal enchantment
Please can someone make an armour example for me, also maybe a youtube tutorial?
I have tried to make this Leaping enchant but there are errors in my Eclipse so I don't know why it's not working... This is what I have so does anyone know what I should do?:
public class LeapingEnchantment extends CustomEnchant
static final Material[] LEAPING_ITEMS = new Material [] {Material.LEATHER_BOOTS, Material.IRON_BOOTS, Material.GOLD_BOOTS, Material.CHAINMAIL_BOOTS, Material.DIAMOND_BOOTS};
public LeapingEnchantment() { super ("Leaping", LEAPING_ITEMS, 2);
this.max= 2; this.base= 12; this.interval= 4;
@Override public void applyEquipEffect (Player, int) {
}
@DarcyPolites public class LeapingEnchantment extends CustomEnchant <
missing {static final Material[] LEAPING_ITEMS = new Material [] {Material.LEATHER_BOOTS, Material.IRON_BOOTS, Material.GOLD_BOOTS, Material.CHAINMAIL_BOOTS, Material.DIAMOND_BOOTS};
public LeapingEnchantment() { super ("Leaping", LEAPING_ITEMS, 2);
this.max= 2; this.base= 12; this.interval= 4;
@Override public void applyEquipEffect (Player, int) {
}
how do i add the enchants at is it the config cause i when i see the config its like this EnchantmentAPI: Settings: Generate Unique Name: true Max Enchantments: 5 Anvil Enabled: true Visible Settings: Vanilla Enchantments: Enabled: true Table: true Weight: true Items: true Groups: true Max Level: true Base: true Interval: true Custom Enchantments: Enabled: true Table: true Weight: true Items: true Groups: true Max Level: true Base: true Interval: true Stacks: true Vanilla Enchantments: ARROW_DAMAGE: Enabled: true Table: true Weight: 10 Group: Default Max Level: 5 Base: 1.0 Interval: 10.0 Items: - BOW ARROW_FIRE: Enabled: true Table: true Weight: 2 Group: Default Max Level: 1 Base: 20.0 Interval: 20.0 Items: - BOW ARROW_INFINITE: Enabled: true Table: true Weight: 1 Group: Default Max Level: 1 Base: 20.0 Interval: 20.0 Items: - BOW ARROW_KNOCKBACK: Enabled: true Table: true Weight: 2 Group: Default Max Level: 2 Base: 12.0 Interval: 20.0 Items: - BOW DAMAGE_ALL: Enabled: true Table: true Weight: 10 Group: Bonus_Damage Max Level: 5 Base: 1.0 Interval: 11.0 Items: - WOOD_SWORD - STONE_SWORD - IRON_SWORD - GOLD_SWORD - DIAMOND_SWORD DAMAGE_ARTHROPODS: Enabled: true Table: true Weight: 4 Group: Bonus_Damage Max Level: 5 Base: 5.0 Interval: 8.0 Items: - WOOD_SWORD - STONE_SWORD - IRON_SWORD - GOLD_SWORD - DIAMOND_SWORD DAMAGE_UNDEAD: Enabled: true Table: true Weight: 4 Group: Bonus_Damage Max Level: 5 Base: 5.0 Interval: 8.0 Items: - WOOD_SWORD - STONE_SWORD - IRON_SWORD - GOLD_SWORD - DIAMOND_SWORD DIG_SPEED: Enabled: true Table: true Weight: 10 Group: Default Max Level: 5 Base: 1.0 Interval: 10.0 Items: - WOOD_AXE - STONE_AXE - IRON_AXE - GOLD_AXE - DIAMOND_AXE - WOOD_SPADE - STONE_SPADE - IRON_SPADE - GOLD_SPADE - DIAMOND_SPADE - WOOD_PICKAXE - STONE_PICKAXE - IRON_PICKAXE - GOLD_PICKAXE - DIAMOND_PICKAXE DURABILITY: Enabled: true Table: true Weight: 5 Group: Default Max Level: 3 Base: 5.0 Interval: 8.0 Items: - WOOD_AXE - STONE_AXE - IRON_AXE - GOLD_AXE - DIAMOND_AXE - WOOD_SPADE - STONE_SPADE - IRON_SPADE - GOLD_SPADE - DIAMOND_SPADE - WOOD_PICKAXE - STONE_PICKAXE - IRON_PICKAXE - GOLD_PICKAXE - DIAMOND_PICKAXE FIRE_ASPECT: Enabled: true Table: true Weight: 2 Group: Default Max Level: 2 Base: 9.0 Interval: 20.0 Items: - WOOD_SWORD - STONE_SWORD - IRON_SWORD - GOLD_SWORD - DIAMOND_SWORD KNOCKBACK: Enabled: true Table: true Weight: 8 Group: Default Max Level: 2 Base: 4.0 Interval: 20.0 Items: - WOOD_SWORD - STONE_SWORD - IRON_SWORD - GOLD_SWORD - DIAMOND_SWORD LOOT_BONUS_BLOCKS: Enabled: true Table: true Weight: 2 Group: Block_Modifier Max Level: 3 Base: 15.0 Interval: 9.0 Items: - WOOD_AXE - STONE_AXE - IRON_AXE - GOLD_AXE - DIAMOND_AXE - WOOD_SPADE - STONE_SPADE - IRON_SPADE - GOLD_SPADE - DIAMOND_SPADE - WOOD_PICKAXE - STONE_PICKAXE - IRON_PICKAXE - GOLD_PICKAXE - DIAMOND_PICKAXE LOOT_BONUS_MOBS: Enabled: true Table: true Weight: 2 Group: Default Max Level: 3 Base: 14.0 Interval: 9.0 Items: - WOOD_SWORD - STONE_SWORD - IRON_SWORD - GOLD_SWORD - DIAMOND_SWORD OXYGEN: Enabled: true Table: true Weight: 2 Group: Default Max Level: 3 Base: 10.0 Interval: 10.0 Items: - LEATHER_HELMET - CHAINMAIL_HELMET - IRON_HELMET - GOLD_HELMET - DIAMOND_HELMET PROTECTION_ENVIRONMENTAL: Enabled: true Table: true Weight: 10 Group: Damage_Reduction Max Level: 4 Base: 1.0 Interval: 11.0 Items: - LEATHER_CHESTPLATE - CHAINMAIL_CHESTPLATE - IRON_CHESTPLATE - GOLD_CHESTPLATE - DIAMOND_CHESTPLATE - LEATHER_HELMET - CHAINMAIL_HELMET - IRON_HELMET - GOLD_HELMET - DIAMOND_HELMET - LEATHER_LEGGINGS - CHAINMAIL_LEGGINGS - IRON_LEGGINGS - GOLD_LEGGINGS - DIAMOND_LEGGINGS - LEATHER_BOOTS - CHAINMAIL_BOOTS - IRON_BOOTS - GOLD_BOOTS - DIAMOND_BOOTS PROTECTION_EXPLOSIONS: Enabled: true Table: true Weight: 2 Group: Damage_Reduction Max Level: 4 Base: 5.0 Interval: 8.0 Items: - LEATHER_CHESTPLATE - CHAINMAIL_CHESTPLATE - IRON_CHESTPLATE - GOLD_CHESTPLATE - DIAMOND_CHESTPLATE - LEATHER_HELMET - CHAINMAIL_HELMET - IRON_HELMET - GOLD_HELMET - DIAMOND_HELMET - LEATHER_LEGGINGS - CHAINMAIL_LEGGINGS - IRON_LEGGINGS - GOLD_LEGGINGS - DIAMOND_LEGGINGS - LEATHER_BOOTS - CHAINMAIL_BOOTS - IRON_BOOTS - GOLD_BOOTS - DIAMOND_BOOTS PROTECTION_FALL: Enabled: true Table: true Weight: 5 Group: Default Max Level: 4 Base: 5.0 Interval: 6.0 Items: - LEATHER_BOOTS - CHAINMAIL_BOOTS - IRON_BOOTS - GOLD_BOOTS - DIAMOND_BOOTS PROTECTION_FIRE: Enabled: true Table: true Weight: 5 Group: Damage_Reduction Max Level: 4 Base: 10.0 Interval: 8.0 Items: - LEATHER_CHESTPLATE - CHAINMAIL_CHESTPLATE - IRON_CHESTPLATE - GOLD_CHESTPLATE - DIAMOND_CHESTPLATE - LEATHER_HELMET - CHAINMAIL_HELMET - IRON_HELMET - GOLD_HELMET - DIAMOND_HELMET - LEATHER_LEGGINGS - CHAINMAIL_LEGGINGS - IRON_LEGGINGS - GOLD_LEGGINGS - DIAMOND_LEGGINGS - LEATHER_BOOTS - CHAINMAIL_BOOTS - IRON_BOOTS - GOLD_BOOTS - DIAMOND_BOOTS PROTECTION_PROJECTILE: Enabled: true Table: true Weight: 5 Group: Damage_Reduction Max Level: 4 Base: 3.0 Interval: 6.0 Items: - LEATHER_CHESTPLATE - CHAINMAIL_CHESTPLATE - IRON_CHESTPLATE - GOLD_CHESTPLATE - DIAMOND_CHESTPLATE - LEATHER_HELMET - CHAINMAIL_HELMET - IRON_HELMET - GOLD_HELMET - DIAMOND_HELMET - LEATHER_LEGGINGS - CHAINMAIL_LEGGINGS - IRON_LEGGINGS - GOLD_LEGGINGS - DIAMOND_LEGGINGS - LEATHER_BOOTS - CHAINMAIL_BOOTS - IRON_BOOTS - GOLD_BOOTS - DIAMOND_BOOTS SILK_TOUCH: Enabled: true Table: true Weight: 1 Group: Block_Modifier Max Level: 1 Base: 15.0 Interval: 20.0 Items: - WOOD_AXE - STONE_AXE - IRON_AXE - GOLD_AXE - DIAMOND_AXE - WOOD_SPADE - STONE_SPADE - IRON_SPADE - GOLD_SPADE - DIAMOND_SPADE - WOOD_PICKAXE - STONE_PICKAXE - IRON_PICKAXE - GOLD_PICKAXE - DIAMOND_PICKAXE THORNS: Enabled: true Table: true Weight: 1 Group: Default Max Level: 3 Base: 10.0 Interval: 20.0 Items: - LEATHER_CHESTPLATE - CHAINMAIL_CHESTPLATE - IRON_CHESTPLATE - GOLD_CHESTPLATE - DIAMOND_CHESTPLATE WATER_WORKER: Enabled: true Table: true Weight: 2 Group: Default Max Level: 1 Base: 1.0 Interval: 20.0 Items: - LEATHER_HELMET - CHAINMAIL_HELMET - IRON_HELMET - GOLD_HELMET - DIAMOND_HELMET Language: Anvil Component: - '&2Anvil Components' - '&dPlace components' - '&dover here!' Anvil Separator: - '&2Anvil Book' - '&d<- Components' - '&8
--' - '&dResults ->' Anvil Result: - '&2Anvil Result' - '&dResults will' - '&dshow up over' - '&dhere!' Table Enchantable: - '&2Placeholder' - '&dEnchantable' Table Unenchantable: - '&2Placeholder' - '&4Unenchantable' Name Format: - '{adjective} {weapon} of {suffix}'what do i need to add when im gonna make a custom enchantments?
I'm following these directions, but I can't create a constructor because it says either (with fields) "the selected type contains no fiends which may be initialized in a constructor" or (with superclass) "there are no constructors from the superclass which may be added". Help!
To almost everyone replying:
GO BACK TO YOUTUBE AND LEARN YOUR SHIT.
would it work if i make it like this
public class UndeadWreathe extends Enchant {
Random rand = new Random();
public void activateDefenceEnchant(Player defender, LivingEntity attacker, ItemStack armor, double damage, int level){ if(Util.randPercent(2)){ int amountOfZombies = rand.nextInt((int)Math.ceil(level/2)) + (int)Math.floor(level/2);
int difference = 360/amountOfZombies; Location loc = attacker.getLocation(); for(int i=0; i<amountOfZombies; i){ Location loc2 = loc.clone().add(Math.sin(Math.toRadians(difference*i))*3, 0, Math.cos(Math.toRadians(difference*i))*3); UndeadWreatheZombie zombie = new UndeadWreatheZombie(loc.getWorld(), (EntityLiving)((CraftEntity)attacker).getHandle()); CustomEntities.spawnEntity(zombie, loc2); } } }
public int getMaxLevel() { return 10;
@DarcyPolites
Public class Leap extends CustomEnchantment {
Static final Material[] LEAP_ITEMS = new Material() { Material.DIAMOND_BOOTS };
Public Leap() { Super("Leap", JUMP_ITEMS, 2); This.max = 2; This.base = 12; This.interval = 4; } @Override Public void applyequipeffect(Player player, int level) { Player.addpotioneffect(new potioneffect(potioneffecttype.JUMP, 20 * 60 * 100 * 500, level + 1)); } }
How do we make a class?