namedtag->hasTag("TileID", IntTag::class)){ $blockId = $this->namedtag->getInt("TileID"); }elseif($this->namedtag->hasTag("Tile", ByteTag::class)){ $blockId = $this->namedtag->getByte("Tile"); $this->namedtag->removeTag("Tile"); } if($blockId === 0){ throw new \UnexpectedValueException("Invalid " . get_class($this) . " entity: block ID is 0 or missing"); } $damage = $this->namedtag->getByte("Data", 0); $this->block = BlockFactory::get($blockId, $damage); $this->propertyManager->setInt(self::DATA_VARIANT, $this->block->getRuntimeId()); } public function canCollideWith(Entity $entity) : bool{ return false; } public function canBeMovedByCurrents() : bool{ return false; } public function attack(EntityDamageEvent $source) : void{ if($source->getCause() === EntityDamageEvent::CAUSE_VOID){ parent::attack($source); } } public function entityBaseTick(int $tickDiff = 1) : bool{ if($this->closed){ return false; } $hasUpdate = parent::entityBaseTick($tickDiff); if(!$this->isFlaggedForDespawn()){ $pos = Position::fromObject($this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor(), $this->getLevel()); $this->block->position($pos); $blockTarget = null; if($this->block instanceof Fallable){ $blockTarget = $this->block->tickFalling(); } if($this->onGround or $blockTarget !== null){ $this->flagForDespawn(); $block = $this->level->getBlock($pos); if(($block->isTransparent() and !$block->canBeReplaced()) or ($this->onGround and abs($this->y - $this->getFloorY()) > 0.001)){ //FIXME: anvils are supposed to destroy torches $this->getLevel()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage())); }else{ $ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block); $ev->call(); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($pos, $ev->getTo(), true); } } $hasUpdate = true; } } return $hasUpdate; } public function getBlock() : int{ return $this->block->getId(); } public function getDamage() : int{ return $this->block->getDamage(); } public function saveNBT() : void{ parent::saveNBT(); $this->namedtag->setInt("TileID", $this->block->getId(), true); $this->namedtag->setByte("Data", $this->block->getDamage()); } }