-
Notifications
You must be signed in to change notification settings - Fork 3
Register Enchantments
Registering your enchantment allow Custom Anvil to use your enchantment.
To register your enchantment, you need into a CAEnchantment instance and then register it.
This is so Custom Anvil know how to handle action with your enchantment like adding/removing and getting level of it from an item.
Then you should use or extend CABukkitEnchantment
CAEnchantment enchantment = new CABukkitEnchantment(bukkitEnchant);For example if you store via persistent data:
Then you should preferably create a class extending CAEnchantmentBase and implement the required functions:
-
getLevel: To get the enchantment level using item and item meta. -
isEnchantmentPresent: To test is an enchantment is present in an item or an item meta. -
addEnchantmentUnsafe: To add the enchantment with the specified level using item or an item meta. -
removeFrom: To remove the enchantment from the specified item.
You can add optional features by implementing other function:
-
isCleanOptimisedandisCleanOptimised: Indicate if a bulk operation exists for this enchantment. (wiki in WIP) -
isAllowed: Allow the enchantment to be combined by only certain players. Useful for example if you like to allow only player with a specific permission.
You also need 3 objects for the constructor:
-
key: Namespaced key of your enchantment. -
defaultRarity: Default rarity of your enchantment. Please note "rarity" is how custom anvil name the concept of "Multiplier by book/item". (minecraft wiki) -
defaultMaxLevel: Default maximum enchantment level.
You can also directly implement CAEnchantment, but it is not recommended.
EnchantmentApi.registerEnchantment(enchantment);To register the enchantment present on startup, you should listen to the CAEnchantRegistryReadyEvent event and register your enchantment.
It should look something like this example:
@EventHandler
public void onEnchantmentRegistry(CAEnchantRegistryReadyEvent event){
// you could also get a list of your enchantment object and create CAEnchant object from your object.
List<CAEnchantment> enchantments = getEnchantmentList();
for (CAEnchantment enchantment : enchantments) {
EnchantmentApi.registerEnchantment(enchantment);
}
}You can register/unregister enchantments at runtime via the EnchantmentApi facade. But every enchantment using previously written conflict should be registered when the CAEnchantRegistryReadyEvent event is called.
If you do not register the enchantment in time, the conflict will not find your enchantment and will cause issue.
It is recommended to register conflict alongside its enchantment when CAConfigReadyEvent is triggered. (wiki in WIP)