Documentation

InventoryTransaction
in package

This is the basic type for an inventory transaction. This is used for moving items between inventories, dropping items and more. It allows transactions with multiple inputs and outputs.

Validation does not depend on ordering. This means that the actions can appear in any order and still be valid. The only validity requirement for this transaction type is that the balance of items must add up to zero. This means:

  • No new outputs without matching input amounts
  • No inputs without matching output amounts
  • No userdata changes (item state, NBT, etc)

A transaction is composed of "actions", which are pairs of inputs and outputs which target a specific itemstack in a specific location. There are multiple types of inventory actions which might be involved in a transaction.

Tags
see
InventoryAction

Table of Contents

$actions  : array<string|int, InventoryAction>
$hasExecuted  : bool
$inventories  : array<string|int, Inventory>
$source  : Player
__construct()  : mixed
addAction()  : void
execute()  : void
Executes the group of actions, returning whether the transaction executed successfully or not.
getActions()  : array<string|int, InventoryAction>
Returns an **unordered** set of actions involved in this transaction.
getInventories()  : array<string|int, Inventory>
getSource()  : Player
hasExecuted()  : bool
validate()  : void
Verifies that the transaction can execute.
callExecuteEvent()  : bool
findResultItem()  : Item|null
matchItems()  : void
squashDuplicateSlotChanges()  : void
Iterates over SlotChangeActions in this transaction and compacts any which refer to the same slot in the same inventory so they can be correctly handled.
shuffleActions()  : void
Shuffles actions in the transaction to prevent external things relying on any implicit ordering.

Properties

Methods

getActions()

Returns an **unordered** set of actions involved in this transaction.

public getActions() : array<string|int, InventoryAction>

WARNING: This system is explicitly designed NOT to care about ordering. Any order seen in this set has NO significance and should not be relied on.

Return values
array<string|int, InventoryAction>

squashDuplicateSlotChanges()

Iterates over SlotChangeActions in this transaction and compacts any which refer to the same slot in the same inventory so they can be correctly handled.

protected squashDuplicateSlotChanges() : void

Under normal circumstances, the same slot would never be changed more than once in a single transaction. However, due to the way things like the crafting grid are "implemented" in MCPE 1.2 (a.k.a. hacked-in), we may get multiple slot changes referring to the same slot in a single transaction. These multiples are not even guaranteed to be in the correct order (slot splitting in the crafting grid for example, causes the actions to be sent in the wrong order), so this method also tries to chain them into order.

Return values
void

shuffleActions()

Shuffles actions in the transaction to prevent external things relying on any implicit ordering.

private shuffleActions() : void
Return values
void

Search results