Interface Enchantments


public interface Enchantments
The behaviour of the enchantments, and the helpers applying them to stacks.

The enchantments themselves are held by the RegistryKey.ENCHANTMENT registry: a definition built by define(TypedKey) is registered through GameRegistries.writable(RegistryKey).

Since:
0.1.0
See Also:
  • Method Details

    • define

      Returns a new builder for the enchantment identified by key.
      Parameters:
      key - the key of the enchantment
      Returns:
      a new builder for the enchantment identified by key
      Since:
      0.1.0
    • attach

      void attach(TypedKey<EnchantmentDefinition> key, EnchantmentBehaviour behaviour, Plugin owner)
      Adds a behaviour to an enchantment, on top of its existing ones.
      Parameters:
      key - the key of the enchantment, vanilla or not
      behaviour - the behaviour to add
      owner - the plugin adding it
      Throws:
      IllegalArgumentException - if no enchantment is registered under key
      Since:
      0.1.0
    • detach

      boolean detach(TypedKey<EnchantmentDefinition> key, Plugin owner)
      Removes the behaviours a plugin added to an enchantment.
      Parameters:
      key - the key of the enchantment
      owner - the plugin that added them
      Returns:
      true if at least one behaviour was removed
      Since:
      0.1.0
    • supportedEffectComponents

      @Contract(pure=true) Set<Key> supportedEffectComponents()
      Returns the effect components run by the server.

      Other components are still sent to clients, but have no effect on the server.

      Returns:
      the effect components run by the server
      Since:
      0.1.0
      See Also:
    • isSupportedItem

      boolean isSupportedItem(TypedKey<EnchantmentDefinition> enchantment, TypedKey<Item> item)
      Returns whether enchantment can be applied to item.

      An item registered by a plugin is also tested as the vanilla item it is rendered as.

      Parameters:
      enchantment - the key of the enchantment
      item - the item, such as minecraft:diamond_sword
      Returns:
      whether enchantment can be applied to item
      Since:
      0.1.0
    • areCompatible

      boolean areCompatible(TypedKey<EnchantmentDefinition> first, TypedKey<EnchantmentDefinition> second)
      Returns whether the two enchantments can be applied to the same stack.

      Two enchantments are compatible when they differ and neither belongs to the exclusive set of the other.

      Parameters:
      first - the key of an enchantment
      second - the key of another enchantment
      Returns:
      whether the two enchantments can be applied to the same stack
      Since:
      0.1.0
    • canEnchant

      boolean canEnchant(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment)
      Returns whether enchantment can be applied to stack, as /enchant checks it: the item is supported and the enchantment is compatible with those already on the stack.
      Parameters:
      stack - the stack
      enchantment - the key of the enchantment
      Returns:
      whether enchantment can be applied to stack, as /enchant checks it: the item is supported and the enchantment is compatible with those already on the stack
      Since:
      0.1.0
    • level

      int level(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment)
      Returns the level of enchantment on stack, or 0 if absent.
      Parameters:
      stack - the stack
      enchantment - the key of the enchantment
      Returns:
      the level of enchantment on stack, or 0 if absent
      Since:
      0.1.0
    • level

      int level(LivingEntity entity, TypedKey<EnchantmentDefinition> enchantment)
      Returns the highest level of enchantment among the stacks entity wears or holds in the slots of the enchantment, or 0 if absent.
      Parameters:
      entity - the entity
      enchantment - the key of the enchantment
      Returns:
      the highest level of enchantment among the stacks entity wears or holds in the slots of the enchantment, or 0 if absent
      Since:
      0.1.0
    • enchant

      ItemStack enchant(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment, int level)
      Applies an enchantment to a stack, or changes its level. Enchanted books receive it as a stored enchantment.

      No compatibility check is performed; see canEnchant(ItemStack, TypedKey).

      Parameters:
      stack - the stack
      enchantment - the key of the enchantment
      level - the level, between 1 and 255
      Returns:
      the enchanted stack
      Throws:
      IllegalArgumentException - if the enchantment is not registered or the level is out of range
      Since:
      0.1.0
    • disenchant

      ItemStack disenchant(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment)
      Removes an enchantment from a stack.
      Parameters:
      stack - the stack
      enchantment - the key of the enchantment
      Returns:
      the stack without the enchantment, or stack if it was absent
      Since:
      0.1.0
    • enchantedBook

      ItemStack enchantedBook(TypedKey<EnchantmentDefinition> enchantment, int level)
      Returns an enchanted book storing enchantment.
      Parameters:
      enchantment - the key of the enchantment
      level - the level, between 1 and 255
      Returns:
      an enchanted book storing enchantment
      Throws:
      IllegalArgumentException - if the enchantment is not registered or the level is out of range
      Since:
      0.1.0
    • displayName

      Component displayName(TypedKey<EnchantmentDefinition> enchantment, int level)
      Returns the name of an enchantment followed by its level, as displayed in item tooltips.

      The name is gray, or red for a curse (#minecraft:curse). The level is omitted when both the level and the maximum level are 1.

      Parameters:
      enchantment - the key of the enchantment
      level - the level
      Returns:
      the name of an enchantment followed by its level, as displayed in item tooltips
      Since:
      0.1.0