en
Switch Language
  1. PowerNukkitX
  2. Get Started
  3. Config

    1. server.properties
    2. nukkit.yml
    3. pnx-cli-config.ini
    4. Anti-xray
    5. Resource Encryption
    6. Compression Acceleration
    7. PNX with WaterDogPE
    8. Flat World
  4. FAQ

    1. To Newcomers
    2. How to use PNX-CLI
    3. Common Questions
    4. Terra Questions
    5. Spawn-point Questions
    6. Convert Worlds
  5. For Devs

    1. Java

      1. Goto JavaDoc
      2. Mod API

        1. Custom Block
        2. Custom Item
        3. Custom Entity
        4. Custom Enchantment
      3. Entity AI

        1. Behavior
        2. Memory
        3. Sensor
        4. Motion Controller
        5. Navigator
        6. Behavior Group
        7. Work Cycle
    2. JavaScript

      1. setup dev env
      2. Base LLSELib dev
      3. Hello World
      4. Basic knowledge
      5. Event Listener
      6. FAQ
    3. Resources

      1. Event List
      2. IDs(block & item)

4. custom enchantment

author: Cool_Loong*

Implementing Custom Enchantment

To implement a custom enchantment, you first need to extends from Enchantment and choose to use this constructor
protected Enchantment(@NotNull Identifier identifier, String name, Rarity rarity, @NotNull EnchantmentType type)
where Identifier is the identifier of the enchantment, such as pnx:test, reserved for the minecraft namespace and not allowed to be used with other plugins
String is the display name of the enchantment
Rarity is the rarity of the enchantment
EnchantmentType is the type of the enchantment, different types allow different items to be enchanted

Note that custom enchantments do not have numeric IDs, and the only way to get custom enchantments is through strings.
Use Item#hasCustomEnchantment(String id) to determine if the item has the specified custom enchantment
Get the item's specified custom enchantment by using Item#getCustomEnchantment(String id).
Get the custom enchantment level specified by the item by using Item#getCustomEnchantmentLevel(String id).

Implementing custom enchantment logic

The core only provides the registration of custom enchantment, the logic of custom enchantment needs to be implemented by the plugin author.
You can implement the logic of a specific process by overriding some of the methods in enchanting
For example:
doPostAttack is triggered when entity is wearing enchanted armor and is attacked by entity attacker
doAttack is triggered when the entity attacker attacks the entity with an enchanted weapon
You can also implement your own enchantment logic by listening for events See javadoc for more details

Registering custom enchantment

Use Enchantment#(Enchantment enchantment, boolean registerItem) to register a custom enchantment registerItem means whether you also need to register custom enchantment book items


© PowerNukkitX Dev team