User Tools

Site Tools


items:item_events

Item Events

Sometimes you want to do something that an item component alone cannot achieve. So, this is why item events exist! With item events you can act upon something happening to an item yourself. All events and their handlers are found in a list in the events field on an item. Below is a list with all item events describing when they occur.

Fields

Name Description Type Default Value
event The event to target. An item event
entry The action to execute when running this event. An action

Example

{
  "base": {
    "translation_key": "item.minecraft.milk_bucket"
  },
  // ...
  "events": [
    {
      "event": "minecraft:consume_item",
      "entry": {
        "action": {
          "type": "minecraft:clear_status_effects",
          "entity": "this"
        }
      }
    }
  ]
}

Events

This is a list with all item events describing when they occur. It also contains a table with its appropriate Action Context.

minecraft:use

Occurs when a player used the item.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
Item Stack The item stack held by the player.

minecraft:stopped_using

Occurs when a player stopped using the item before its use duration was reached.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
Item Stack The item stack held by the player.

minecraft:finished_using

Occurs when a player used the item for its use duration.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
Item Stack The item stack held by the player.

minecraft:consume_item

Occurs when the item with the minecraft:consumable item component is consumed. Runs after minecraft:finished_using.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
Item Stack The item stack about to be consumed by the player.

minecraft:eat_item

Occurs when the item with the minecraft:food item component is consumed. Runs before minecraft:finished_using and minecraft:consume_item.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
Item Stack The item stack about to be eaten by the player.

minecraft:use_on_block

Occurs when the item is used on a block after its original usage on the block failed.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
target The position of the block the player used the item stack on.
Side The side of the block the player used the item stack on.
Item Stack The item stack used on the block.

minecraft:broke_block

Occurs when the item is used to break a block.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
target The position of the block the player broke.
Item Stack The item stack used to break the block.

minecraft:placed_block

Occurs when a block from the item with the minecraft:block item component is placed.

Parameter Description
Entity this The player holding the item stack.
Position this The position of the player holding the item stack.
target The position the block was placed at.
Item Stack The item stack used to place the block.

minecraft:use_on_entity

Occurs when the item it used on an entity after its original usage on the entity failed.

Parameter Description
Entity this The player holding the item stack.
target The entity the item stack was used on.
Position this The position of the player holding the item stack.
target The position of the entity the item stack was used on.
Item Stack The item stack used on the entity.

minecraft:hit_entity

Occurs when the item is used to hit an entity.

Parameter Description
Entity this The player holding the item stack.
target The entity the item stack was used to hit with.
Position this The position of the player holding the item stack.
target The position of the entity the item stack was used to hit with.
Item Stack The item stack used to hit the entity with.

minecraft:spawn_entity

Occurs when the item placed an entity.

Parameter Description
Entity this The player holding the item stack.
target The entity that was spawned.
Position this The position of the player holding the item stack.
target The position of the spawned entity.
Side The side of the block the item stack was used on to spawn the entity.
Item Stack The item stack used to spawn the entity.

minecraft:damage_item

Occurs when the item with the minecraft:damageable item component was damaged. The specific context depends on the origin the item stack was damaged from, but the item stack in the context is always the item stack that was damaged.


minecraft:break_item

Occurs when the item with the minecraft:damageable item component reaches its maximum damage and breaks. Runs after the item stack size is decremented, but before the minecraft:damage data component is set back to 0. The specific context depends on the origin the item stack was broken from, but the item stack in the context is always the item stack that was broken.


minecraft:use_tool

Occurs when the item with the minecraft:tool item component is used to break a block. Runs before minecraft:damage_item and minecraft:broke_block.

Parameter Description
Entity this The player using the item stack to break a block.
Position this The position of the player holding the item stack.
target The position of the block the tool was used on.
Item Stack The item stack used as a tool.

minecraft:use_weapon

Occurs when the item with the minecraft:weapon item component is used to hit an entity. Runs before minecraft:damage_item and minecraft:hit_entity.

Parameter Description
Entity this The player using the item stack to hit an entity.
target The entity that was damaged with the item stack.
Position this The position of the player holding the item stack.
target The position of the entity that was damaged with the item stack.
Item Stack The item stack used as a weapon.

minecraft:equip_item

Occurs when the item with the minecraft:equipment item component is equipped by swapping. Runs before minecraft:use.

Parameter Description
Entity this The player equipping the item stack.
Position this The position of the player equipping the item stack.
Item Stack The item stack to be equipped.

minecraft:throw_projectile

Occurs when the item with the minecraft:throwable item component is thrown.

Parameter Description
Entity this The player throwing the projectile.
target The projectile that was created.
Position this The position of the player throwing the projectile.
target The position of the projectile that was created.
Item Stack The item stack that was thrown.
items/item_events.txt · Last modified: 2024/05/08 00:51 by errorcraft