hasTag(Container::TAG_ITEMS, ListTag::class)){ $inventoryTag = $tag->getListTag(Container::TAG_ITEMS); $inventory = $this->getRealInventory(); /** @var CompoundTag $itemNBT */ foreach($inventoryTag as $itemNBT){ $inventory->setItem($itemNBT->getByte("Slot"), Item::nbtDeserialize($itemNBT)); } } if($tag->hasTag(Container::TAG_LOCK, StringTag::class)){ $this->lock = $tag->getString(Container::TAG_LOCK); } } protected function saveItems(CompoundTag $tag) : void{ $items = []; foreach($this->getRealInventory()->getContents() as $slot => $item){ $items[] = $item->nbtSerialize($slot); } $tag->setTag(new ListTag(Container::TAG_ITEMS, $items, NBT::TAG_Compound)); if($this->lock !== null){ $tag->setString(Container::TAG_LOCK, $this->lock); } } /** * @see Container::canOpenWith() * * @param string $key * * @return bool */ public function canOpenWith(string $key) : bool{ return $this->lock === null or $this->lock === $key; } }