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, Consumer)
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 FabricItemSettings.customDamage(net.fabricmc.fabric.api.item.v1.CustomDamageHandler)
.
-
Method Summary
-
Method Details
-
damage
int damage(net.minecraft.item.ItemStack stack, int amount, net.minecraft.entity.LivingEntity entity, Consumer<net.minecraft.entity.LivingEntity> 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.- Parameters:
amount
- The amount of damage originally requestedbreakCallback
- Callback when the stack reaches zero damage. SeeItemStack.damage(int, LivingEntity, Consumer)
and its callsites for more information.- Returns:
- The amount of damage to pass to vanilla's logic
-