*/ private \SplFixedArray $changedSlots; public function __construct( private Inventory $actualInventory ){ parent::__construct(); $this->changedSlots = new \SplFixedArray($this->actualInventory->getSize()); } public function getActualInventory() : Inventory{ return $this->actualInventory; } protected function internalSetContents(array $items) : void{ for($i = 0, $size = $this->getSize(); $i < $size; ++$i){ if(!isset($items[$i])){ $this->clear($i); }else{ $this->setItem($i, $items[$i]); } } } protected function internalSetItem(int $index, Item $item) : void{ if(!$item->equalsExact($this->actualInventory->getItem($index))){ $this->changedSlots[$index] = $item->isNull() ? VanillaItems::AIR() : clone $item; } } public function getSize() : int{ return $this->actualInventory->getSize(); } public function getItem(int $index) : Item{ return $this->changedSlots[$index] !== null ? clone $this->changedSlots[$index] : $this->actualInventory->getItem($index); } public function getContents(bool $includeEmpty = false) : array{ $contents = $this->actualInventory->getContents($includeEmpty); foreach($this->changedSlots as $index => $item){ if($item !== null){ if($includeEmpty || !$item->isNull()){ $contents[$index] = clone $item; }else{ unset($contents[$index]); } } } return $contents; } /** * @return SlotChangeAction[] */ public function generateActions() : array{ $result = []; foreach($this->changedSlots as $index => $newItem){ if($newItem !== null){ $oldItem = $this->actualInventory->getItem($index); if(!$newItem->equalsExact($oldItem)){ $result[] = new SlotChangeAction($this->actualInventory, $index, $oldItem, $newItem); } } } return $result; } }