hasTag(self::TAG_ITEM, ShortTag::class)){ $nbt->setShort(self::TAG_ITEM, 0, true); } if(!$nbt->hasTag(self::TAG_ITEM_DATA, IntTag::class)){ $nbt->setInt(self::TAG_ITEM_DATA, 0, true); } parent::__construct($level, $nbt); } 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 ItemFactory::get($this->namedtag->getShort(self::TAG_ITEM), $this->namedtag->getInt(self::TAG_ITEM_DATA), 1); } public function setItem(Item $item){ $this->namedtag->setShort(self::TAG_ITEM, $item->getId()); $this->namedtag->setInt(self::TAG_ITEM_DATA, $item->getDamage()); $this->onChanged(); } public function removeItem(){ $this->setItem(ItemFactory::get(Item::AIR, 0, 0)); } public function isEmpty() : bool{ return $this->getItem()->isNull(); } public function addAdditionalSpawnData(CompoundTag $nbt) : void{ $nbt->setTag($this->namedtag->getTag(self::TAG_ITEM)); $nbt->setTag($this->namedtag->getTag(self::TAG_ITEM_DATA)); } protected static function createAdditionalNBT(CompoundTag $nbt, Vector3 $pos, ?int $face = null, ?Item $item = null, ?Player $player = null) : void{ $nbt->setShort(self::TAG_ITEM, 0); $nbt->setInt(self::TAG_ITEM_DATA, 0); } }