From c7e803372c7b37c800280e885c01638ae4bdfc8b Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 26 Mar 2018 09:24:00 +0100 Subject: [PATCH] Inventory: added API method isSlotEmpty() --- src/pocketmine/inventory/BaseInventory.php | 4 ++++ src/pocketmine/inventory/Inventory.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index 17ec10dfb..cb1bb478d 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -237,6 +237,10 @@ abstract class BaseInventory implements Inventory{ return -1; } + public function isSlotEmpty(int $index) : bool{ + return $this->slots[$index] === null or $this->slots[$index]->isNull(); + } + public function canAddItem(Item $item) : bool{ $item = clone $item; $checkDamage = !$item->hasAnyDamageValue(); diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index 7e23b1935..1f1fc266f 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -171,6 +171,15 @@ interface Inventory{ */ public function firstEmpty() : int; + /** + * Returns whether the given slot is empty. + * + * @param int $index + * + * @return bool + */ + public function isSlotEmpty(int $index) : bool; + /** * Will remove all the Items that has the same id and metadata (if not null) *