PocketMine-MP 5.35.1 git-05a71d8cc5185aa9e46ef5f9754bb862464c13e0
Loading...
Searching...
No Matches
pocketmine\inventory\transaction\InventoryTransaction Class Reference
+ Inheritance diagram for pocketmine\inventory\transaction\InventoryTransaction:
+ Collaboration diagram for pocketmine\inventory\transaction\InventoryTransaction:

Public Member Functions

 __construct (protected Player $source, array $actions=[])
 
 addAction (InventoryAction $action)
 
 execute ()
 
 getActions ()
 
 getInventories ()
 
 getSource ()
 
 hasExecuted ()
 
 validate ()
 

Protected Member Functions

 callExecuteEvent ()
 
 findResultItem (Item $needOrigin, array $possibleActions)
 
 matchItems (array &$needItems, array &$haveItems)
 
 squashDuplicateSlotChanges ()
 

Protected Attributes

array $actions = []
 
bool $hasExecuted = false
 
array $inventories = []
 

Detailed Description

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.

See also
InventoryAction

Definition at line 56 of file InventoryTransaction.php.

Constructor & Destructor Documentation

◆ __construct()

pocketmine\inventory\transaction\InventoryTransaction::__construct ( protected Player $source,
array $actions = [] )
Parameters
InventoryAction[]$actions

Definition at line 74 of file InventoryTransaction.php.

Member Function Documentation

◆ addAction()

pocketmine\inventory\transaction\InventoryTransaction::addAction ( InventoryAction $action)

Definition at line 111 of file InventoryTransaction.php.

◆ callExecuteEvent()

pocketmine\inventory\transaction\InventoryTransaction::callExecuteEvent ( )
protected

Definition at line 283 of file InventoryTransaction.php.

◆ execute()

pocketmine\inventory\transaction\InventoryTransaction::execute ( )

Executes the group of actions, returning whether the transaction executed successfully or not.

Exceptions
TransactionException

Reimplemented in pocketmine\inventory\transaction\EnchantingTransaction.

Definition at line 294 of file InventoryTransaction.php.

◆ findResultItem()

pocketmine\inventory\transaction\InventoryTransaction::findResultItem ( Item $needOrigin,
array $possibleActions )
protected
Parameters
SlotChangeAction[]$possibleActions@phpstan-param array<int, SlotChangeAction> $possibleActions

Definition at line 227 of file InventoryTransaction.php.

◆ getActions()

pocketmine\inventory\transaction\InventoryTransaction::getActions ( )

Returns a set of actions involved in this transaction.

Note: This system is designed to care only about item balances. While you can usually assume that the actions are provided in the correct order, it will still successfully complete transactions whose actions are provided in the "wrong" order, as long as the transaction balances. For example, you may see that an action setting a slot to a particular item may appear before the action that removes that item from its original slot. While unintuitive, this is still valid.

Returns
InventoryAction[] @phpstan-return array<int, InventoryAction>

Definition at line 107 of file InventoryTransaction.php.

◆ getInventories()

pocketmine\inventory\transaction\InventoryTransaction::getInventories ( )
Returns
Inventory[] @phpstan-return array<int, Inventory>

Definition at line 91 of file InventoryTransaction.php.

◆ getSource()

pocketmine\inventory\transaction\InventoryTransaction::getSource ( )

Definition at line 83 of file InventoryTransaction.php.

◆ hasExecuted()

pocketmine\inventory\transaction\InventoryTransaction::hasExecuted ( )

Definition at line 318 of file InventoryTransaction.php.

◆ matchItems()

pocketmine\inventory\transaction\InventoryTransaction::matchItems ( array & $needItems,
array & $haveItems )
protected
Parameters
Item[]$needItems
Item[]$haveItems@phpstan-param-out list<Item> $needItems @phpstan-param-out list<Item> $haveItems
Exceptions
TransactionValidationException

Definition at line 131 of file InventoryTransaction.php.

◆ squashDuplicateSlotChanges()

pocketmine\inventory\transaction\InventoryTransaction::squashDuplicateSlotChanges ( )
protected

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.

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.

Definition at line 182 of file InventoryTransaction.php.

◆ validate()

pocketmine\inventory\transaction\InventoryTransaction::validate ( )

Verifies that the transaction can execute.

Exceptions
TransactionValidationException

Reimplemented in pocketmine\inventory\transaction\CraftingTransaction, and pocketmine\inventory\transaction\EnchantingTransaction.

Definition at line 265 of file InventoryTransaction.php.

Member Data Documentation

◆ $actions

array pocketmine\inventory\transaction\InventoryTransaction::$actions = []
protected

Definition at line 69 of file InventoryTransaction.php.

◆ $hasExecuted

bool pocketmine\inventory\transaction\InventoryTransaction::$hasExecuted = false
protected

Definition at line 57 of file InventoryTransaction.php.

◆ $inventories

array pocketmine\inventory\transaction\InventoryTransaction::$inventories = []
protected

Definition at line 63 of file InventoryTransaction.php.


The documentation for this class was generated from the following file: