Interface EnchantmentBehaviour


public interface EnchantmentBehaviour
Server-side behaviour of an enchantment.

The behaviours of an enchantment run in the following order: the supported effect components of its data, the behaviour of its definition, then the behaviours attached to it. Each modifying hook receives the value returned by the previous one.

Hooks related to an attack only consider the weapon held in the main hand. Other hooks consider every stack worn or held in one of the slots of the enchantment.

Every hook does nothing by default. Hooks run on the thread of the region owning EnchantedItem.owner(); an exception thrown by a hook is logged and ignored.

Since:
0.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the attribute modifiers granted while the stack is worn or held in one of the slots of the enchantment, like minecraft:attributes.
    default boolean
    Tests whether the wearer ignores the damage entirely, like minecraft:damage_immunity.
    default float
    modifyArmorEffectiveness(EnchantedItem item, LivingEntity victim, DamageSource source, float effectiveness)
    Modifies the fraction of the damage absorbed by the armor of the victim, like minecraft:armor_effectiveness.
    default float
    modifyDamage(EnchantedItem item, LivingEntity victim, DamageSource source, float damage)
    Modifies the damage of a melee attack dealt with the enchanted weapon, like minecraft:damage.
    default float
    modifyKnockback(EnchantedItem item, LivingEntity victim, DamageSource source, float knockback)
    Modifies the knockback bonus of a melee attack dealt with the enchanted weapon, like minecraft:knockback.
    default float
    modifyProtection(EnchantedItem item, DamageSource source, float protection)
    Modifies the protection points against damage taken by the wearer, like minecraft:damage_protection.
    default void
    onAttack(EnchantedItem item, LivingEntity victim, DamageSource source, float damage)
    Called after the owner damaged an entity with a melee attack, like the minecraft:post_attack effects targeting the attacker.
    default void
    Called when the stack starts being worn or held in one of the slots of the enchantment, including when the owner joins the server.
    default void
    onHurt(EnchantedItem item, @Nullable LivingEntity attacker, DamageSource source, float damage)
    Called after the owner was damaged by an attack, like the minecraft:post_attack effects targeting the victim.
    default void
    Called every tick while the stack is worn or held in one of the slots of the enchantment, like minecraft:tick.
    default void
    Called when the stack stops being worn or held in one of the slots of the enchantment, when it is modified, or when the owner leaves the server or dies.
    default boolean
    Tests whether a player outside of creative mode is prevented from removing the stack from its armor slot, like minecraft:prevent_armor_change.
    default boolean
    Tests whether the stack is destroyed instead of dropped when the owner dies without keeping their inventory, like minecraft:prevent_equipment_drop.
  • Method Details

    • modifyDamage

      default float modifyDamage(EnchantedItem item, LivingEntity victim, DamageSource source, float damage)
      Modifies the damage of a melee attack dealt with the enchanted weapon, like minecraft:damage.

      The difference with the base damage is scaled by the attack strength and is not affected by critical hits.

      Parameters:
      item - the enchanted weapon
      victim - the entity attacked
      source - the source of the damage
      damage - the current damage
      Returns:
      the modified damage
      Since:
      0.1.0
    • modifyProtection

      default float modifyProtection(EnchantedItem item, DamageSource source, float protection)
      Modifies the protection points against damage taken by the wearer, like minecraft:damage_protection.

      Protection points are summed over all stacks and capped at 20; each point reduces the damage by 4%.

      Parameters:
      item - the enchanted stack
      source - the source of the damage
      protection - the current protection points
      Returns:
      the modified protection points
      Since:
      0.1.0
    • isImmuneTo

      default boolean isImmuneTo(EnchantedItem item, DamageSource source)
      Tests whether the wearer ignores the damage entirely, like minecraft:damage_immunity.
      Parameters:
      item - the enchanted stack
      source - the source of the damage
      Returns:
      true to cancel the damage
      Since:
      0.1.0
    • modifyKnockback

      default float modifyKnockback(EnchantedItem item, LivingEntity victim, DamageSource source, float knockback)
      Modifies the knockback bonus of a melee attack dealt with the enchanted weapon, like minecraft:knockback.

      The bonus uses the vanilla scale: Knockback I adds 1, and each point adds 0.5 to the knockback strength.

      Parameters:
      item - the enchanted weapon
      victim - the entity attacked
      source - the source of the damage
      knockback - the current knockback bonus, 0 by default
      Returns:
      the modified knockback bonus
      Since:
      0.1.0
    • modifyArmorEffectiveness

      default float modifyArmorEffectiveness(EnchantedItem item, LivingEntity victim, DamageSource source, float effectiveness)
      Modifies the fraction of the damage absorbed by the armor of the victim, like minecraft:armor_effectiveness.
      Parameters:
      item - the enchanted weapon
      victim - the entity attacked
      source - the source of the damage
      effectiveness - the current fraction, between 0 and 1
      Returns:
      the modified fraction, clamped between 0 and 1 once every hook ran
      Since:
      0.1.0
    • onAttack

      default void onAttack(EnchantedItem item, LivingEntity victim, DamageSource source, float damage)
      Called after the owner damaged an entity with a melee attack, like the minecraft:post_attack effects targeting the attacker.
      Parameters:
      item - the enchanted stack of the attacker
      victim - the entity damaged
      source - the source of the damage
      damage - the damage dealt
      Since:
      0.1.0
    • onHurt

      default void onHurt(EnchantedItem item, @Nullable LivingEntity attacker, DamageSource source, float damage)
      Called after the owner was damaged by an attack, like the minecraft:post_attack effects targeting the victim.
      Parameters:
      item - the enchanted stack of the victim
      attacker - the living entity responsible for the attack, or null
      source - the source of the damage
      damage - the damage taken
      Since:
      0.1.0
    • onTick

      default void onTick(EnchantedItem item)
      Called every tick while the stack is worn or held in one of the slots of the enchantment, like minecraft:tick.
      Parameters:
      item - the enchanted stack
      Since:
      0.1.0
    • onEquip

      default void onEquip(EnchantedItem item)
      Called when the stack starts being worn or held in one of the slots of the enchantment, including when the owner joins the server.
      Parameters:
      item - the enchanted stack
      Since:
      0.1.0
    • onUnequip

      default void onUnequip(EnchantedItem item)
      Called when the stack stops being worn or held in one of the slots of the enchantment, when it is modified, or when the owner leaves the server or dies.
      Parameters:
      item - the enchanted stack, as it was while equipped
      Since:
      0.1.0
    • attributeModifiers

      default List<AttributeModifier> attributeModifiers(EnchantedItem item)
      Gets the attribute modifiers granted while the stack is worn or held in one of the slots of the enchantment, like minecraft:attributes. They are synchronised with the client of a player.

      AttributeModifier.id() must be unique per attribute; the server appends the slot to it. AttributeModifier.slot() is ignored.

      Parameters:
      item - the enchanted stack
      Returns:
      the attribute modifiers, possibly empty
      Since:
      0.1.0
    • preventsArmorChange

      default boolean preventsArmorChange(EnchantedItem item)
      Tests whether a player outside of creative mode is prevented from removing the stack from its armor slot, like minecraft:prevent_armor_change.
      Parameters:
      item - the enchanted stack, worn in an armor slot
      Returns:
      true to keep the stack in its slot
      Since:
      0.1.0
    • preventsDrop

      default boolean preventsDrop(EnchantedItem item)
      Tests whether the stack is destroyed instead of dropped when the owner dies without keeping their inventory, like minecraft:prevent_equipment_drop.
      Parameters:
      item - the enchanted stack, anywhere in the inventory
      Returns:
      true to destroy the stack
      Since:
      0.1.0