Interface EnchantmentBehaviour
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 TypeMethodDescriptiondefault List<AttributeModifier> Gets the attribute modifiers granted while the stack is worn or held in one of the slots of the enchantment, likeminecraft:attributes.default booleanisImmuneTo(EnchantedItem item, DamageSource source) Tests whether the wearer ignores the damage entirely, likeminecraft:damage_immunity.default floatmodifyArmorEffectiveness(EnchantedItem item, LivingEntity victim, DamageSource source, float effectiveness) Modifies the fraction of the damage absorbed by the armor of the victim, likeminecraft:armor_effectiveness.default floatmodifyDamage(EnchantedItem item, LivingEntity victim, DamageSource source, float damage) Modifies the damage of a melee attack dealt with the enchanted weapon, likeminecraft:damage.default floatmodifyKnockback(EnchantedItem item, LivingEntity victim, DamageSource source, float knockback) Modifies the knockback bonus of a melee attack dealt with the enchanted weapon, likeminecraft:knockback.default floatmodifyProtection(EnchantedItem item, DamageSource source, float protection) Modifies the protection points against damage taken by the wearer, likeminecraft:damage_protection.default voidonAttack(EnchantedItem item, LivingEntity victim, DamageSource source, float damage) Called after the owner damaged an entity with a melee attack, like theminecraft:post_attackeffects targeting the attacker.default voidonEquip(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.default voidonHurt(EnchantedItem item, @Nullable LivingEntity attacker, DamageSource source, float damage) Called after the owner was damaged by an attack, like theminecraft:post_attackeffects targeting the victim.default voidonTick(EnchantedItem item) Called every tick while the stack is worn or held in one of the slots of the enchantment, likeminecraft:tick.default voidonUnequip(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.default booleanTests whether a player outside of creative mode is prevented from removing the stack from its armor slot, likeminecraft:prevent_armor_change.default booleanpreventsDrop(EnchantedItem item) Tests whether the stack is destroyed instead of dropped when the owner dies without keeping their inventory, likeminecraft: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, likeminecraft:damage.The difference with the base damage is scaled by the attack strength and is not affected by critical hits.
- Parameters:
item- the enchanted weaponvictim- the entity attackedsource- the source of the damagedamage- the current damage- Returns:
- the modified damage
- Since:
- 0.1.0
-
modifyProtection
Modifies the protection points against damage taken by the wearer, likeminecraft:damage_protection.Protection points are summed over all stacks and capped at
20; each point reduces the damage by4%.- Parameters:
item- the enchanted stacksource- the source of the damageprotection- the current protection points- Returns:
- the modified protection points
- Since:
- 0.1.0
-
isImmuneTo
Tests whether the wearer ignores the damage entirely, likeminecraft:damage_immunity.- Parameters:
item- the enchanted stacksource- the source of the damage- Returns:
trueto 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, likeminecraft:knockback.The bonus uses the vanilla scale: Knockback I adds
1, and each point adds0.5to the knockback strength.- Parameters:
item- the enchanted weaponvictim- the entity attackedsource- the source of the damageknockback- the current knockback bonus,0by 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, likeminecraft:armor_effectiveness.- Parameters:
item- the enchanted weaponvictim- the entity attackedsource- the source of the damageeffectiveness- the current fraction, between0and1- Returns:
- the modified fraction, clamped between
0and1once every hook ran - Since:
- 0.1.0
-
onAttack
Called after the owner damaged an entity with a melee attack, like theminecraft:post_attackeffects targeting the attacker.- Parameters:
item- the enchanted stack of the attackervictim- the entity damagedsource- the source of the damagedamage- 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 theminecraft:post_attackeffects targeting the victim.- Parameters:
item- the enchanted stack of the victimattacker- the living entity responsible for the attack, ornullsource- the source of the damagedamage- the damage taken- Since:
- 0.1.0
-
onTick
Called every tick while the stack is worn or held in one of the slots of the enchantment, likeminecraft:tick.- Parameters:
item- the enchanted stack- Since:
- 0.1.0
-
onEquip
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
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
Gets the attribute modifiers granted while the stack is worn or held in one of the slots of the enchantment, likeminecraft: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
Tests whether a player outside of creative mode is prevented from removing the stack from its armor slot, likeminecraft:prevent_armor_change.- Parameters:
item- the enchanted stack, worn in an armor slot- Returns:
trueto keep the stack in its slot- Since:
- 0.1.0
-
preventsDrop
Tests whether the stack is destroyed instead of dropped when the owner dies without keeping their inventory, likeminecraft:prevent_equipment_drop.- Parameters:
item- the enchanted stack, anywhere in the inventory- Returns:
trueto destroy the stack- Since:
- 0.1.0
-