From b38c81c96ff3a3b8d5735eb53b9abcb9c9e17ca2 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 22 Mar 2019 18:11:32 +0000 Subject: [PATCH] backport f84a1729c: Inventory: added swap() function --- src/pocketmine/inventory/BaseInventory.php | 7 +++++++ src/pocketmine/inventory/Inventory.php | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 6f32492fc..bc6f7dcfb 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -378,6 +378,13 @@ abstract class BaseInventory implements Inventory{ } } + public function swap(int $slot1, int $slot2) : void{ + $i1 = $this->getItem($slot1); + $i2 = $this->getItem($slot2); + $this->setItem($slot1, $i2); + $this->setItem($slot2, $i1); + } + /** * @return Player[] */ diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index 94677a75e..1bf84060f 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -215,6 +215,14 @@ interface Inventory{ */ public function clearAll(bool $send = true) : void; + /** + * Swaps the specified slots. + * + * @param int $slot1 + * @param int $slot2 + */ + public function swap(int $slot1, int $slot2) : void; + /** * Gets all the Players viewing the inventory * Players will view their inventory at all times, even when not open.