mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +00:00
Add onStopUsing hook to IForgeItem (#9343)
This commit is contained in:
1 parent
3c75e1269d
commit
8f72c143a1
5 files changed
+198
No files matched your search
@@ -201,6 +201,28 @@ public interface IForgeItem
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity stops using an item for any reason, notably when selecting another item without releasing or finishing.
|
||||
* This method is called in addition to any other hooks called when an item is finished using; when another hook is also called it will be called before this method.
|
||||
*
|
||||
* Note that if you break an item while using it (that is, it becomes empty without swapping the stack instance), this hook may not be called on the serverside as you are
|
||||
* technically still using the empty item (thus this hook is called on air instead). It is necessary to call {@link LivingEntity#stopUsingItem()} as part of your
|
||||
* {@link ItemStack#hurtAndBreak(int, LivingEntity, Consumer)} callback to prevent this issue.
|
||||
*
|
||||
* For most uses, you likely want one of the following:
|
||||
* <ul>
|
||||
* <li>{@link Item#finishUsingItem(ItemStack, Level, LivingEntity)} for when the player releases and enough ticks have passed
|
||||
* <li>{@link Item#releaseUsing(ItemStack, Level, LivingEntity, int)} (ItemStack, Level, LivingEntity)} for when the player releases but the full timer has not passed
|
||||
* </ul>
|
||||
*
|
||||
* @param stack The Item being used
|
||||
* @param entity The entity using the item, typically a player
|
||||
* @param count The amount of time in tick the item has been used for continuously
|
||||
*/
|
||||
default void onStopUsing(ItemStack stack, LivingEntity entity, int count)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the player Left Clicks (attacks) an entity. Processed before
|
||||
* damage is done, if return value is true further processing is canceled and
|
||||
|
||||
@@ -255,6 +255,17 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundTag>
|
||||
self().getItem().onUsingTick(self(), player, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an entity stops using an item item for any reason.
|
||||
*
|
||||
* @param entity The entity using the item, typically a player
|
||||
* @param count The amount of time in tick the item has been used for continuously
|
||||
*/
|
||||
default void onStopUsing(LivingEntity entity, int count)
|
||||
{
|
||||
self().getItem().onStopUsing(self(), entity, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the normal 'lifespan' of this item when it is dropped on the ground
|
||||
* as a EntityItem. This is in ticks, standard result is 6000, or 5 mins.
|
||||
|
||||
Reference in new issue
Block a user