Class ItemExpireEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.entity.EntityEvent
net.neoforged.neoforge.event.entity.item.ItemEvent
net.neoforged.neoforge.event.entity.item.ItemExpireEvent
Event that is fired when an
ItemEntity
's age has reached its maximum
lifespan. Adding extra life time will prevent the ItemEntity
from being
flagged as dead, thus staying its removal from the world.
Note that using this event, you can ony extend the lifespan up to Short.MAX_VALUE
- 1 ticks (27.5 minutes).
To extend an item's lifespan above that, use either ItemEntity.setExtendedLifetime()
or ItemEntity.setUnlimitedLifetime()
.
This event will only be fired server-side.
-
Nested Class Summary
Nested classes/interfaces inherited from class net.neoforged.neoforge.event.entity.EntityEvent
EntityEvent.EnteringSection, EntityEvent.EntityConstructing, EntityEvent.Size
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionItemExpireEvent
(net.minecraft.world.entity.item.ItemEntity itemEntity) Creates a new event for an expiringItemEntity
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExtraLife
(int extraLife) Adds to the amount of extra life time (in ticks) to give thisItemEntity
.int
Query the amount of extra time that will be added.void
setExtraLife
(int extraLife) Sets the amount of extra life time (in ticks) to give thisItemEntity
.
-
Field Details
-
extraLife
private int extraLife
-
-
Constructor Details
-
ItemExpireEvent
public ItemExpireEvent(net.minecraft.world.entity.item.ItemEntity itemEntity) Creates a new event for an expiringItemEntity
.- Parameters:
itemEntity
- TheItemEntity
being deleted.
-
-
Method Details
-
getExtraLife
public int getExtraLife()Query the amount of extra time that will be added.Note that this is the event result. If you need data from the entity, query it directly.
ItemEntity.lifespan
is the entities maximum lifespan and also its current age.- Returns:
- Extra time to be added in ticks.
-
setExtraLife
public void setExtraLife(int extraLife) Sets the amount of extra life time (in ticks) to give thisItemEntity
.Consider using
addExtraLife(int)
in case another mod also adds extra time.- Parameters:
extraLife
- The amount of time to be added to this entities lifespan.
-
addExtraLife
public void addExtraLife(int extraLife) Adds to the amount of extra life time (in ticks) to give thisItemEntity
.- Parameters:
extraLife
- The amount of time to be added to this entities lifespan.
-