Package net.fabricmc.fabric.api.item.v1
Interface CustomDamageHandler
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Allows an item to run custom logic when
ItemStack.damage(int, LivingEntity, EquipmentSlot)
is called.
This is useful for items that, for example, may drain durability from some other source before damaging
the stack itself.
Custom damage handlers can be set with FabricItem.Settings.customDamage(net.fabricmc.fabric.api.item.v1.CustomDamageHandler)
.
-
Method Summary
Modifier and TypeMethodDescriptionint
damage
(ItemStack stack, int amount, LivingEntity entity, EquipmentSlot slot, Runnable breakCallback) Called to apply damage to the given stack.
-
Method Details
-
damage
int damage(ItemStack stack, int amount, LivingEntity entity, EquipmentSlot slot, Runnable breakCallback) Called to apply damage to the given stack. This can be used to e.g. drain from a battery before actually damaging the item. Note that this does not get called if non-entities, such as dispensers, are damaging the item, or for thrown tridents. CallingbreakCallback
breaks the item, bypassing the vanilla logic. The return value is ignored in this case.- Parameters:
amount
- the amount of damage originally requested- Returns:
- The amount of damage to pass to vanilla's logic
-