item = ItemFactory::get(Item::AIR, 0, 0); parent::__construct($level, $pos); } protected function readSaveData(CompoundTag $nbt) : void{ if($nbt->hasTag(self::TAG_ITEM, ShortTag::class) and $nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){ $this->item = ItemFactory::get($nbt->getShort(self::TAG_ITEM, 0), $nbt->getInt(self::TAG_ITEM_DATA, 0), 1); } } protected function writeSaveData(CompoundTag $nbt) : void{ $nbt->setShort(self::TAG_ITEM, $this->item->getId()); $nbt->setInt(self::TAG_ITEM_DATA, $this->item->getDamage()); } public function canAddItem(Item $item) : bool{ if(!$this->isEmpty()){ return false; } switch($item->getId()){ /** @noinspection PhpMissingBreakStatementInspection */ case Item::TALL_GRASS: if($item->getDamage() === 1){ return false; } case Item::SAPLING: case Item::DEAD_BUSH: case Item::DANDELION: case Item::RED_FLOWER: case Item::BROWN_MUSHROOM: case Item::RED_MUSHROOM: case Item::CACTUS: return true; default: return false; } } public function getItem() : Item{ return clone $this->item; } public function setItem(Item $item){ $this->item = clone $item; $this->onChanged(); } public function removeItem(){ $this->setItem(ItemFactory::get(Item::AIR, 0, 0)); } public function isEmpty() : bool{ return $this->getItem()->isNull(); } protected function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setShort(self::TAG_ITEM, $this->item->getId()); $nbt->setInt(self::TAG_ITEM_DATA, $this->item->getDamage()); } }