PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
pocketmine\inventory\transaction\CraftingTransaction Class Reference
+ Inheritance diagram for pocketmine\inventory\transaction\CraftingTransaction:
+ Collaboration diagram for pocketmine\inventory\transaction\CraftingTransaction:

Public Member Functions

 __construct (Player $source, CraftingManager $craftingManager, array $actions=[], ?CraftingRecipe $recipe=null, ?int $repetitions=null)
 
 addAction (InventoryAction $action)
 
 addInventory (Inventory $inventory)
 
 execute ()
 
 getActions ()
 
 getInventories ()
 
 getSource ()
 
 hasExecuted ()
 
 validate ()
 

Static Public Member Functions

static matchIngredients (array $providedItems, array $recipeIngredients, int $expectedIterations)
 

Protected Member Functions

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

Protected Attributes

array $actions = []
 
bool $hasExecuted = false
 
array $inputs = []
 
array $inventories = []
 
array $outputs = []
 
CraftingRecipe $recipe = null
 
int $repetitions = null
 

Detailed Description

This transaction type is specialized for crafting validation. It shares most of the same semantics of the base inventory transaction type, but the requirement for validity is slightly different.

It is expected that the actions in this transaction type will produce an unbalanced result, i.e. some inputs won't have corresponding outputs, and vice versa. The reason why is because the unmatched inputs are recipe inputs, and the unmatched outputs are recipe results.

Therefore, the validity requirement is that the imbalance of the transaction should match the expected inputs and outputs of a registered crafting recipe.

This transaction allows multiple repetitions of the same recipe to be crafted in a single batch. In the case of batch crafting, the number of unmatched inputs and outputs must be exactly divisible by the expected recipe ingredients and results, with no remainder. Any leftovers are expected to be emitted back to the crafting grid.

Definition at line 56 of file CraftingTransaction.php.

Constructor & Destructor Documentation

◆ __construct()

pocketmine\inventory\transaction\CraftingTransaction::__construct ( Player  $source,
CraftingManager  $craftingManager,
array  $actions = [],
?CraftingRecipe  $recipe = null,
?int  $repetitions = null 
)

Definition at line 67 of file CraftingTransaction.php.

Member Function Documentation

◆ addAction()

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

Definition at line 101 of file InventoryTransaction.php.

◆ addInventory()

pocketmine\inventory\transaction\InventoryTransaction::addInventory ( Inventory  $inventory)
inherited

Definition at line 127 of file InventoryTransaction.php.

◆ callExecuteEvent()

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

◆ execute()

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

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

Exceptions
TransactionException

Reimplemented in pocketmine\inventory\transaction\EnchantingTransaction.

Definition at line 304 of file InventoryTransaction.php.

◆ findResultItem()

pocketmine\inventory\transaction\InventoryTransaction::findResultItem ( Item  $needOrigin,
array  $possibleActions 
)
protectedinherited
Parameters
SlotChangeAction[]$possibleActions

Definition at line 237 of file InventoryTransaction.php.

◆ getActions()

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

Returns an unordered set of actions involved in this transaction.

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.

Returns
InventoryAction[]

Definition at line 97 of file InventoryTransaction.php.

◆ getInventories()

pocketmine\inventory\transaction\InventoryTransaction::getInventories ( )
inherited
Returns
Inventory[]

Definition at line 85 of file InventoryTransaction.php.

◆ getSource()

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

Definition at line 78 of file InventoryTransaction.php.

◆ hasExecuted()

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

Definition at line 330 of file InventoryTransaction.php.

◆ matchIngredients()

static pocketmine\inventory\transaction\CraftingTransaction::matchIngredients ( array  $providedItems,
array  $recipeIngredients,
int  $expectedIterations 
)
static
Parameters
Item[]$providedItems
RecipeIngredient[]$recipeIngredients

Definition at line 98 of file CraftingTransaction.php.

◆ matchItems()

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

Definition at line 141 of file InventoryTransaction.php.

◆ matchOutputs()

pocketmine\inventory\transaction\CraftingTransaction::matchOutputs ( array  $txItems,
array  $recipeItems 
)
protected
Parameters
Item[]$txItems
Item[]$recipeItems
Exceptions
TransactionValidationException

Definition at line 177 of file CraftingTransaction.php.

◆ squashDuplicateSlotChanges()

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

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 190 of file InventoryTransaction.php.

◆ validate()

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

Verifies that the transaction can execute.

Exceptions
TransactionValidationException

Reimplemented from pocketmine\inventory\transaction\InventoryTransaction.

Definition at line 242 of file CraftingTransaction.php.

Member Data Documentation

◆ $actions

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

Definition at line 64 of file InventoryTransaction.php.

◆ $hasExecuted

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

Definition at line 58 of file InventoryTransaction.php.

◆ $inputs

array pocketmine\inventory\transaction\CraftingTransaction::$inputs = []
protected

Definition at line 61 of file CraftingTransaction.php.

◆ $inventories

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

Definition at line 61 of file InventoryTransaction.php.

◆ $outputs

array pocketmine\inventory\transaction\CraftingTransaction::$outputs = []
protected

Definition at line 63 of file CraftingTransaction.php.

◆ $recipe

CraftingRecipe pocketmine\inventory\transaction\CraftingTransaction::$recipe = null
protected

Definition at line 57 of file CraftingTransaction.php.

◆ $repetitions

int pocketmine\inventory\transaction\CraftingTransaction::$repetitions = null
protected

Definition at line 58 of file CraftingTransaction.php.


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