diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index a465843c2..580640e21 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -93,10 +93,20 @@ abstract class BaseInventory implements Inventory{ } /** + * @param bool $includeEmpty + * * @return Item[] */ - public function getContents() : array{ - return array_filter($this->slots->toArray(), function(Item $item = null){ return $item !== null; }); + public function getContents(bool $includeEmpty = false) : array{ + $contents = []; + for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ + $item = $this->getItem($i); + if($includeEmpty or !$item->isNull()){ + $contents[$i] = $item; + } + } + + return $contents; } /** diff --git a/src/pocketmine/inventory/DoubleChestInventory.php b/src/pocketmine/inventory/DoubleChestInventory.php index 7755b5f2a..32a6530dd 100644 --- a/src/pocketmine/inventory/DoubleChestInventory.php +++ b/src/pocketmine/inventory/DoubleChestInventory.php @@ -71,15 +71,6 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{ return $index < $this->left->getSize() ? $this->left->clear($index, $send) : $this->right->clear($index - $this->right->getSize(), $send); } - public function getContents() : array{ - $contents = []; - for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ - $contents[$i] = $this->getItem($i); - } - - return $contents; - } - /** * @param Item[] $items * @param bool $send diff --git a/src/pocketmine/inventory/Inventory.php b/src/pocketmine/inventory/Inventory.php index abe48afa6..7e23b1935 100644 --- a/src/pocketmine/inventory/Inventory.php +++ b/src/pocketmine/inventory/Inventory.php @@ -108,9 +108,11 @@ interface Inventory{ public function removeItem(Item ...$slots) : array; /** + * @param bool $includeEmpty + * * @return Item[] */ - public function getContents() : array; + public function getContents(bool $includeEmpty = false) : array; /** * @param Item[] $items