Skip to main content

Action On Item Use (Power Type)

Runs an entity action or an item action when the player uses an item, such as eating food or drinking a potion.

Type ID: apoli:action_on_item_use

Fields

FieldTypeDefaultDescription
entity_actionEntity Action TypeoptionalIf set, this action runs on the player after they use an item.
item_actionItem Action TypeoptionalIf set, this action runs on the item that remains after use.
item_conditionItem Condition TypeoptionalIf set, the actions only run when the item passes this condition before it is used.
triggerString"finish"When the actions run. The table below lists the values.
priorityInteger0The order when several of these powers fire on the same trigger (higher runs first), and which phase the power runs in. A priority of 0 or more runs before the vanilla item logic at the trigger point, and a negative priority runs after it.

Triggers

NameDescription
finishRuns when the entity finishes using an item that has a use duration, such as eating food.
startRuns when the entity starts using an item that has a use duration.
stopRuns when the entity stops using an item that has a use duration before reaching the maximum use duration. Unlike finish, this can detect shooting a bow, for example.
duringRuns every tick while the entity is using an item that has a use duration.
instantDoesn't run for items with a use duration. It runs when the entity uses an item whose effect is instant, such as an ender pearl or a splash potion.

Notes

  • The actions run on the server only.
  • instant and start powers with a negative priority, which run after vanilla, only fire if the use succeeded. With the default priority they fire when the use is attempted.
  • Items blocked by apoli:prevent_item_use don't fire instant or start powers.

Examples

{
    "type": "apoli:action_on_item_use",
    "entity_action": {
        "type": "apoli:feed",
        "food": 1.0,
        "saturation": 1.0
    },
    "item_condition": {
        "type": "apoli:ingredient",
        "ingredient": {
            "item": "minecraft:potion"
        }
    }
}

This gives the player half a shank of hunger and 1 point of saturation whenever they drink any potion.

{
    "type": "apoli:action_on_item_use",
    "trigger": "instant",
    "entity_action": {
        "type": "apoli:apply_effect",
        "effect": {
            "effect": "minecraft:invisibility",
            "duration": 400,
            "amplifier": 0
        }
    },
    "item_condition": {
        "type": "apoli:ingredient",
        "ingredient": {
            "item": "minecraft:ender_pearl"
        }
    }
}

This gives the player 20 seconds of invisibility whenever they throw an ender pearl.