From c931437a303de526be3dc28858f7ed5dbefc7503 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 31 Aug 2025 21:45:55 +0100 Subject: [PATCH] InventoryTransaction: Remove action shuffling we used to have this to prevent dependence on client ordering, and make ordering consistently not work. However, since the introduction of the ItemStackRequest protocol, we don't expect to see client actions in the wrong order anymore, so this shouldn't be needed anymore. closes #6701 --- .../transaction/InventoryTransaction.php | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/inventory/transaction/InventoryTransaction.php b/src/inventory/transaction/InventoryTransaction.php index 6e010c7b8..99fa6a097 100644 --- a/src/inventory/transaction/InventoryTransaction.php +++ b/src/inventory/transaction/InventoryTransaction.php @@ -95,10 +95,13 @@ class InventoryTransaction{ } /** - * Returns an **unordered** set of actions involved in this transaction. + * Returns a 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. + * 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. * * @return InventoryAction[] * @phpstan-return array @@ -119,19 +122,6 @@ class InventoryTransaction{ } } - /** - * Shuffles actions in the transaction to prevent external things relying on any implicit ordering. - */ - private function shuffleActions() : void{ - $keys = array_keys($this->actions); - shuffle($keys); - $actions = []; - foreach($keys as $key){ - $actions[$key] = $this->actions[$key]; - } - $this->actions = $actions; - } - /** * @param Item[] $needItems * @param Item[] $haveItems @@ -308,8 +298,6 @@ class InventoryTransaction{ throw new TransactionValidationException("Transaction has already been executed"); } - $this->shuffleActions(); - $this->validate(); if(!$this->callExecuteEvent()){