Add general damage hook for items. Closes #5502 (#5670)

This commit is contained in:
Vincent Lee authored and LexManos committed 2019-07-08 20:43:02 -07:00
1 parent f79da3edf7
commit d88e4fbf36
2 files changed
+30 -7

No files matched your search

@@ -20,6 +20,7 @@
package net.minecraftforge.common.extensions;
import java.util.Set;
import java.util.function.Consumer;
import javax.annotation.Nullable;
@@ -768,4 +769,18 @@ public interface IForgeItem
* This should be used in favor of TagCollection.getOwningTags, as this caches the result and automatically updates when the TagCollection changes.
*/
Set<ResourceLocation> getTags();
/**
* Reduce the durability of this item by the amount given.
* This can be used to e.g. consume power from NBT before durability.
*
* @param stack The itemstack to damage
* @param amount The amount to damage
* @param entity The entity damaging the item
* @param onBroken The on-broken callback from vanilla
* @return The amount of damage to pass to the vanilla logic
*/
default <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) {
return amount;
}
}