Skip to main content

Inventory Action (Entity Action Type)

Goes through the items in the entity's inventory or in an apoli:inventory power, and does one operation on each matching slot. This one action covers Apace's modify_inventory, replace_inventory and drop_inventory, and the operation field picks which behaviour you get.

Type ID: apoli:inventory_action

note

The three legacy IDs still work and select the matching operation: apoli:modify_inventory is operation: modify, apoli:replace_inventory is operation: replace and apoli:drop_inventory is operation: drop. Both the apoli: and origins: namespaces resolve, so data packs written for either load unchanged.

Operations

operationWhat happens to each slotEmpty slots
modify (default)Runs item_action on the stack.skipped
replaceSwaps the stack for stack, then runs item_action (if any) on the replacement.included
dropRuns item_action (if any) on the stack, then drops it into the world.skipped
warning

replace visits empty slots on purpose, so it can put an item into an empty slot. That is how you keep an item pinned in the offhand. It also means a replace with no slot or slots and no item_condition fills the entity's whole inventory with stack, so always narrow it down.

Fields

FieldTypeDefaultDescription
operationString"modify"One of modify, replace or drop, as in the table above.
inventory_typeInventory Type"inventory"Whether to go through the entity's own inventory or a power's inventory.
entity_actionEntity Action TypeoptionalRuns on the entity once, before any slots are visited.
item_conditionItem Condition TypeoptionalOnly items that pass this condition are affected.
slotItem SlotoptionalLimits the action to one slot.
slotsArray of Item SlotoptionalLimits the action to these slots. For a power inventory, use the container.N form (the raw slot index).
powerIdentifieroptionalThe apoli:inventory power to go through when inventory_type is "power".
process_modeProcess Mode"stacks"How stacks count toward limit. Used by modify, while replace and drop always act once per stack.
limitInteger0The most stacks (or items, in items mode) to affect. 0 or less means no limit.
item_actionItem Action TypeoptionalWhat modify does, so without it modify does nothing. For replace and drop it is an optional extra step.
stackItem StackoptionalFor replace only: the replacement item.
merge_nbtBooleanfalseFor replace only: merges the old item's data onto the replacement (the NBT tag on 1.20.1, data components on 1.21.1).
throw_randomlyBooleanfalseFor drop only: scatters items in random directions, the way a death drop does.
retain_ownershipBooleantrueFor drop only: keeps the dropping entity as the item's thrower.
amountIntegeroptionalFor drop only: splits this many off each matching stack instead of dropping the whole stack.

Examples

"entity_action": {
    "type": "apoli:inventory_action",
    "operation": "modify",
    "item_condition": {
        "type": "apoli:armor_value",
        "comparison": ">",
        "compare_to": 0
    },
    "item_action": {
        "type": "apoli:damage",
        "amount": 1,
        "ignore_unbreaking": true
    }
}

This slightly damages every item in the entity's inventory that has an armour value.

"entity_action": {
    "type": "apoli:inventory_action",
    "operation": "replace",
    "slot": "weapon.offhand",
    "stack": { "item": "minecraft:barrier" }
}

This replaces the entity's offhand item with a barrier, even when the offhand is empty. It is the same as the legacy apoli:replace_inventory.

"entity_action": {
    "type": "apoli:drop_inventory",
    "slots": ["hotbar.0", "hotbar.1", "hotbar.2"]
}

An example with a legacy ID, which drops the first three hotbar slots. It resolves to operation: drop.

"entity_action": {
    "type": "apoli:inventory_action",
    "operation": "modify",
    "inventory_type": "power",
    "power": "example:extra_inventory",
    "item_action": { "type": "apoli:consume" }
}

This goes through the stored container of the example:extra_inventory inventory power and consumes one of each item. Power inventory slots are addressed as container.N, such as "slots": ["container.0", "container.1"], and this only runs on the server.