diff --git a/src/pocketmine/inventory/BaseInventory.php b/src/pocketmine/inventory/BaseInventory.php index cb1bb478d..6905bad75 100644 --- a/src/pocketmine/inventory/BaseInventory.php +++ b/src/pocketmine/inventory/BaseInventory.php @@ -99,10 +99,13 @@ abstract class BaseInventory implements Inventory{ */ 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; + $air = null; + + foreach($this->slots as $i => $slot){ + if($slot !== null){ + $contents[$i] = clone $slot; + }elseif($includeEmpty){ + $contents[$i] = $air ?? ($air = ItemFactory::get(Item::AIR, 0, 0)); } }