Item events
ItemExpiredCallback lets a mod act on a dropped item before vanilla removes it after a while
on the ground. Use it to give an expiring item a use instead of letting it vanish.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
ItemExpiredCallback |
Fired when a dropped item reaches its despawn age, just before it is removed. | Experimental | 2.6.0 | server | server |
Quick start
Section titled “Quick start”In your mod’s common initializer, with plant, the mod’s method that places a sapling and
returns whether it did:
ItemExpiredCallback.EVENT.register((item, level) -> { ItemStack stack = item.getItem(); if (stack.is(ItemTags.SAPLINGS) && plant(level, item.blockPosition(), stack)) { stack.shrink(1); }});ItemExpiredCallback
Section titled “ItemExpiredCallback”Experimental · Since 2.6.0 · Side: server · Thread: server
Edge cases
Section titled “Edge cases”- Two stacks of the same item that merge on the ground become one item entity, and the merged entity’s age decides when it expires.
- An item in a hopper, in a player’s inventory, or in a container is not an item entity and never expires.
See also
Section titled “See also”- Mob events: deaths, the equipment a dying mob drops, and natural spawns.
- Lifecycle events: the level tick, for work an item event does not cover.