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
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
$actions
protected
array<string|int, InventoryAction>
$actions
= []
$hasExecuted
protected
bool
$hasExecuted
= false
$inventories
protected
array<string|int, Inventory>
$inventories
= []
$source
protected
Player
$source
Methods
__construct()
public
__construct(Player $source[, array<string|int, InventoryAction> $actions = [] ]) : mixed
Parameters
- $source : Player
- $actions : array<string|int, InventoryAction> = []
Return values
mixed —addAction()
public
addAction(InventoryAction $action) : void
Parameters
- $action : InventoryAction
Return values
void —execute()
Executes the group of actions, returning whether the transaction executed successfully or not.
public
execute() : void
Tags
Return values
void —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> —getInventories()
public
getInventories() : array<string|int, Inventory>
Return values
array<string|int, Inventory> —getSource()
public
getSource() : Player
Return values
Player —hasExecuted()
public
hasExecuted() : bool
Return values
bool —validate()
Verifies that the transaction can execute.
public
validate() : void
Tags
Return values
void —callExecuteEvent()
protected
callExecuteEvent() : bool
Return values
bool —findResultItem()
protected
findResultItem(Item $needOrigin, array<string|int, SlotChangeAction> $possibleActions) : Item|null
Parameters
- $needOrigin : Item
- $possibleActions : array<string|int, SlotChangeAction>
Return values
Item|null —matchItems()
protected
matchItems(array<string|int, Item> &$needItems, array<string|int, Item> &$haveItems) : void
Parameters
Tags
Return values
void —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