Origins: Powerful Powers
» Power inventoriesPage 14 of 17

Power inventories

An origins:inventory power keeps its items inside Origins' power data. There are two ways to reach them:

You want to…UseReaches
Check or change your own power inventory from power JSONOrigins' own types, belowonly the entity running the condition or action
Read it from a function, or copy/move items between players, or between a power and a normal slot/opp powerinv (OPP)any entity, any power, any vanilla slot

Vanilla /item and /data can't see power inventories.

Slots: a power's slots are container.0container.<size-1>, as in Origins' item_slot docs. The size depends on the power's container_type: dropper has 9 (the default), hopper 5, chest 27.


From power JSON (Origins, no OPP needed)

The inventory is named by its power id. Four Origins types accept it:

TypeField that selects power inventoriesPlus
origins:inventory (entity condition)"inventory_types": ["power"], an array"power": "<id>"
origins:modify_inventory (entity action)"inventory_type": "power", a single value"power": "<id>"
origins:replace_inventory (entity action)"inventory_type": "power""power": "<id>"
origins:drop_inventory (entity action)"inventory_type": "power""power": "<id>"

Catches:

  • You need both fields. With power alone, the player's normal inventory is used. With inventory_type(s) alone, no power inventory is used.
  • Slots past the power's size are skipped silently.
  • Only your own inventory. All four types act only on the entity they run on, with no bi-entity version. To move items between players, use /opp powerinv.

Example: does slot 0 of mypack:satchel hold at least 1 item?

json
{
  "type": "origins:inventory",
  "inventory_types": [
    "power"
  ],
  "power": "mypack:satchel",
  "slot": "container.0",
  "comparison": ">=",
  "compare_to": 1
}

Example: use up one item from each of the first three slots.

json
{
  "type": "origins:modify_inventory",
  "inventory_type": "power",
  "power": "mypack:satchel",
  "slots": [
    "container.0",
    "container.1",
    "container.2"
  ],
  "item_action": {
    "type": "origins:consume",
    "amount": 1
  }
}

From commands: /opp powerinv

Needs permission level 2, like /item.

mcfunction
opp powerinv get   <target> <power> <slot>
opp powerinv id    <target> <power> <slot>
opp powerinv set   <target> <power> <slot> <item> [count]
opp powerinv clear <target> <power> [slot]
opp powerinv copy  <from> <to>
opp powerinv move  <from> <to>

<from> and <to> are each one of:

  • power <target> <power> <slot>: a slot in a power inventory, such as power @s mypack:satchel container.3
  • entity <target> <slot>: any vanilla slot, such as entity @s hotbar.0 or entity @s enderchest.5

<target> must be exactly one entity holding the power, and the power must be an origins:inventory power. Otherwise the command fails with the reason.

SubcommandWhat it doesResult (for execute store result)
getShows the stack in the slotthe item count, or 0 if empty
idPrints the item's id on its own, as plain text: minecraft:spruce_log, or minecraft:air for an empty slotthe item's number in the item registry
setReplaces the slot with a new stackthe count set
clearEmpties one slot, or the whole power if no slot is givenitems removed (one slot) or stacks removed (whole power)
copyCopies the source stack over the destination, overwriting it. The source keeps its item.the count copied
moveMoves the stack and empties the source. It only moves into an empty destination, so items are never duplicated or lost.the count moved, or 0 if the source was empty

Examples:

How many items are in slot 0, stored in a score:

mcfunction
execute store result score @s satchel_0 run opp powerinv get @s mypack:satchel container.0

Hand one player's slot 0 to another player's matching slot:

mcfunction
opp powerinv move power @s mypack:satchel container.0 power @p[tag=partner] mypack:satchel container.0

Pull a power slot into the hotbar, or put the held item into the power:

mcfunction
opp powerinv move power @s mypack:satchel container.0 entity @s hotbar.0
opp powerinv move entity @s weapon.mainhand power @s mypack:satchel container.4

Reading item types

Three ways to find out what is in a slot:

FromUse
Variable code, conditions, ${…}Item.id(power, slot) and Item.count(power, slot)
Power JSON, as a list you can loop overorigins-powerful-powers:item_list
Commands and functionsopp powerinv id

Item.id and Item.count

java
held = Item.id("mypack:satchel", 0);          // "minecraft:spruce_log", or "minecraft:air" when empty
stack = Item.count("mypack:satchel", 0);      // 5
weapon = Item.id("weapon.mainhand");          // a vanilla slot
theirs = Item.id(other, "mypack:satchel", 0); // the target's satchel, in bientity code
gotLogs = Item.id("mypack:satchel", 0).endsWith("_log");
CallReturns
Item.id(power, slot)Stringthe item in a power inventory slot: its full id, namespace:item. An empty slot is minecraft:air.
Item.count(power, slot)intthe stack size there, 0 when empty
Item.id(slot)Stringthe item in a vanilla slot, named as in /item
Item.count(slot)intthe stack size there
  • Power slots: the power is its id as a String, and the slot is a plain number, so Item.id("mypack:satchel", 3) is container.3.
  • Vanilla slots: weapon.mainhand, weapon.offhand, armor.head, armor.chest, armor.legs, armor.feet, hotbar.0 to hotbar.8, inventory.0 to inventory.26, enderchest.0 to enderchest.26. The short forms mainhand, offhand, head, chest, legs and feet work too. Hands and armor work on any living entity. The rest are players only.
  • Whose inventory: the power holder by default, or the actor in bi-entity code. Put self or other first to choose: Item.count(other, "weapon.mainhand"). other only exists in bi-entity actions and conditions (page 8).
  • They're read-only, so they work in execute code, expression conditions, modify_variable values and ${…} (page 9). Field initializers can't use them.
  • An unknown power, a power the entity lacks, a power of another type, an unknown slot name, or a slot outside the inventory is an error. The action stops there, a condition counts as false, and the message says which.

Example: in a bi-entity action, take note of what the entity you hit is holding.

json
{
  "type": "origins:action_on_hit",
  "bientity_action": {
    "type": "origins-powerful-powers:execute",
    "code": "lastVictimWeapon = Item.id(other, \"weapon.mainhand\");"
  }
}

Example: true when slot 0 holds logs or is empty.

json
{
  "type": "origins-powerful-powers:expression",
  "expression": "Item.id(\"mypack:satchel\", 0).endsWith(\"_log\") || Item.count(\"mypack:satchel\", 0) == 0"
}

Item.cooldown

java
pearl = Item.cooldown("minecraft:ender_pearl");  // 20 right after throwing one, 0 when it's ready
held = Item.cooldown("weapon.mainhand");         // the item in your main hand
theirs = Item.cooldown(other, "weapon.offhand"); // the target's offhand, in bientity code
CallReturns
Item.cooldown(itemOrSlot)intticks left on the item's vanilla cooldown (the one ender pearls use), 0 when it has none
  • The argument is an item id (minecraft:ender_pearl) or a vanilla slot name as in Item.id. A slot name reads the item in that slot.
  • It's 0 for non-players.
  • An unknown item id or slot name is an error.
  • The item_on_cooldown condition reads the same value. Set it with set_item_cooldown.

opp powerinv id

mcfunction
opp powerinv id @s mypack:satchel container.0

prints exactly:

text
minecraft:spruce_log

Its result is the item's number in the item registry, so a score can track a slot's item:

mcfunction
execute store result score @s slot0_item run opp powerinv id @s mypack:satchel container.0

Every spruce log has the same number, and stone has a different one. The numbers can change when mods or versions change, so only compare readings from the same session. Code can read the score with Scoreboard.get.

Watching a slot for changes

Item.id plus Item.count fingerprints a slot. It catches a stack growing or shrinking and a same-size swap (5 logs for 5 stone). Keep last tick's fingerprints in a list and compare:

java
now = Item.id("mypack:satchel", index) + " x" + Item.count("mypack:satchel", index);
changed = !value.equals(now);

A complete power that keeps several players' satchels in step is in the cookbook.


Two players sharing items

move makes a duplication-free outbox: one player puts an item in their own power slot, and a function moves it into the partner's matching slot. If the partner's slot is full, the item stays where it is.

Mirroring an inventory with copy in both directions can duplicate items, because a command can't tell whether an item was taken out or never there.