mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Updated Register Enchantments (markdown)
parent
3b06021748
commit
668b0c4c35
1 changed files with 17 additions and 18 deletions
|
|
@ -1,44 +1,43 @@
|
||||||
Registering your enchantment allow Custom Anvil to use your enchantment.
|
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.
|
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.
|
||||||
|
|
||||||
***
|
## Create the Custom Anvil enchantment
|
||||||
|
|
||||||
If you were able to register your enchantment to the bukkit registry. Then you should use or extend `CABukkitEnchantment`
|
### If you were able to register your enchantment to the bukkit registry.
|
||||||
|
Then you should use or extend `CABukkitEnchantment`
|
||||||
|
|
||||||
```java
|
```java
|
||||||
CAEnchantment enchantment = new CABukkitEnchantment(bukkitEnchant);
|
CAEnchantment enchantment = new CABukkitEnchantment(bukkitEnchant);
|
||||||
```
|
```
|
||||||
|
|
||||||
<br></br>
|
### If your enchantment is not registered into the bukkit registry
|
||||||
If your enchantment does not register into the bukkit registry (for example, if you store via persistent data), then you should preferably create a class extending `CAEnchantmentBase` and implement the required functions:
|
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.
|
* `getLevel`: To get the enchantment level using item and item meta.
|
||||||
* `isEnchantmentPresent`: To test is an enchantment is present in item or an 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.
|
* `addEnchantmentUnsafe`: To add the enchantment with the specified level using item or an item meta.
|
||||||
* `removeFrom`: To remove the enchantment from the specified item.
|
* `removeFrom`: To remove the enchantment from the specified item.
|
||||||
|
|
||||||
You can add optional features by implementing other function:
|
You can add optional features by implementing other function:
|
||||||
* `isCleanOptimised` and `isCleanOptimised`: Indicate if a bulk operation exist for this echantment. (wiki in WIP)
|
* `isCleanOptimised` and `isCleanOptimised`: Indicate if a bulk operation exists for this enchantment. (wiki in WIP)
|
||||||
* `isAllowed`: Allow the enchantment to be combined by only certain player. usefull for example if you like to allow only player with a specific permission.
|
* `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 object as constructor:
|
You also need 3 objects for the constructor:
|
||||||
* `key`: Namespaced key of your enchantment.
|
* `key`: Namespaced key of your enchantment.
|
||||||
* `defaultRarity`: Default rarity of your enchantment. Please note "rarity" is how custom anvil name the concept of "Multipler by book/item". ([minecraft wiki](https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments))
|
* `defaultRarity`: Default rarity of your enchantment. Please note "rarity" is how custom anvil name the concept of "Multiplier by book/item". ([minecraft wiki](https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments))
|
||||||
* `defaultMaxLevel`: Default maximum enchantment level.
|
* `defaultMaxLevel`: Default maximum enchantment level.
|
||||||
|
|
||||||
<br></br>
|
<br></br>
|
||||||
You can also directly implement `CAEnchantment`, but it is not recommended.
|
You can also directly implement `CAEnchantment`, but it is not recommended.
|
||||||
|
|
||||||
***
|
## Registering your custom anvil enchantment
|
||||||
|
|
||||||
Here is the function to use to register your enchantment:
|
|
||||||
|
|
||||||
```java
|
```java
|
||||||
EnchantmentApi.registerEnchantment(enchantment);
|
EnchantmentApi.registerEnchantment(enchantment);
|
||||||
```
|
```
|
||||||
|
|
||||||
You should use it on only when and after the `CAEnchantRegistryReadyEvent` event is triggered.
|
|
||||||
|
|
||||||
To register the enchantment present on startup, you should listen to the `CAEnchantRegistryReadyEvent` event and register your 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:
|
It should look something like this example:
|
||||||
|
|
||||||
|
|
@ -54,10 +53,10 @@ It should look something like this example:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
***
|
***
|
||||||
|
|
||||||
You can register or unregister an enchantment at runtime via the `EnchantmentApi` facade. But every enchantment using previously written conflict should be registered on the event trigger. If you do not register the enchantment in time, the conflict will not find your enchantment and will cause issue.
|
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)
|
It is recommended to register conflict alongside its enchantment when `CAConfigReadyEvent` is triggered. (wiki in WIP)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue