*/ protected \SplFixedArray $slots; public function __construct(int $size){ $this->slots = new \SplFixedArray($size); parent::__construct(); } /** * Returns the size of the inventory. */ public function getSize() : int{ return $this->slots->getSize(); } public function getItem(int $index) : Item{ return $this->slots[$index] !== null ? clone $this->slots[$index] : VanillaItems::AIR(); } protected function internalSetItem(int $index, Item $item) : void{ $this->slots[$index] = $item->isNull() ? null : $item; } /** * @return Item[] */ public function getContents(bool $includeEmpty = false) : array{ $contents = []; foreach($this->slots as $i => $slot){ if($slot !== null){ $contents[$i] = clone $slot; }elseif($includeEmpty){ $contents[$i] = VanillaItems::AIR(); } } return $contents; } protected function internalSetContents(array $items) : void{ for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ if(!isset($items[$i]) || $items[$i]->isNull()){ $this->slots[$i] = null; }else{ $this->slots[$i] = clone $items[$i]; } } } }