Skip to content

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.

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

In your mod’s common initializer, with plant, the mod’s method that places a sapling and returns whether it did:

Plant one sapling from a stack that despawns
ItemExpiredCallback.EVENT.register((item, level) -> {
ItemStack stack = item.getItem();
if (stack.is(ItemTags.SAPLINGS) && plant(level, item.blockPosition(), stack)) {
stack.shrink(1);
}
});

Experimental · Since 2.6.0 · Side: server · Thread: server

  • 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.
  • 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.