22declare(strict_types=1);
26use pocketmine\block\utils\ChiseledBookshelfSlot;
46 parent::__construct($world, $pos);
47 $this->inventory =
new SimpleInventory(count(ChiseledBookshelfSlot::cases()));
51 return $this->inventory;
55 return $this->inventory;
58 public function readSaveData(
CompoundTag $nbt) :
void{
59 $this->loadItems($nbt);
63 $this->saveItems($nbt);
66 protected function loadItems(
CompoundTag $tag) : void{
67 if(($inventoryTag = $tag->getTag(
Container::TAG_ITEMS)) instanceof
ListTag && $inventoryTag->getTagType() ===
NBT::TAG_Compound){
68 $inventory = $this->getRealInventory();
74 foreach($inventoryTag as $slot => $itemNBT){
76 $count = $itemNBT->getByte(SavedItemStackData::TAG_COUNT);
83 \GlobalLogger::get()->logException($e);
92 if(($lockTag = $tag->
getTag(Container::TAG_LOCK)) instanceof StringTag){
93 $this->lock = $lockTag->getValue();
97 protected function saveItems(CompoundTag $tag) : void{
99 foreach($this->getRealInventory()->getContents(
true) as $slot => $item){
101 $items[$slot] = CompoundTag::create()
102 ->setByte(SavedItemStackData::TAG_COUNT, 0)
103 ->setShort(SavedItemData::TAG_DAMAGE, 0)
104 ->setString(SavedItemData::TAG_NAME,
"")
105 ->setByte(SavedItemStackData::TAG_WAS_PICKED_UP, 0);
107 $items[$slot] = $item->nbtSerialize();
111 $tag->setTag(Container::TAG_ITEMS,
new ListTag($items, NBT::TAG_Compound));
113 if($this->lock !==
null){
114 $tag->setString(Container::TAG_LOCK, $this->lock);
writeSaveData(CompoundTag $nbt)
setContents(array $items)
static nbtDeserialize(CompoundTag $tag)