hasTag("TileID", IntTag::class)){ $blockId = $nbt->getInt("TileID"); }elseif($nbt->hasTag("Tile", ByteTag::class)){ $blockId = $nbt->getByte("Tile"); } if($blockId === 0){ throw new \UnexpectedValueException("Invalid " . get_class($this) . " entity: block ID is 0 or missing"); } $damage = $nbt->getByte("Data", 0); $this->block = BlockFactory::get($blockId, $damage); } 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); } } protected function entityBaseTick(int $tickDiff = 1) : bool{ if($this->closed){ return false; } $hasUpdate = parent::entityBaseTick($tickDiff); if(!$this->isFlaggedForDespawn()){ $pos = $this->add(-$this->width / 2, $this->height, -$this->width / 2)->floor(); $this->block->position($this->world, $pos->x, $pos->y, $pos->z); $blockTarget = null; if($this->block instanceof Fallable){ $blockTarget = $this->block->tickFalling(); } if($this->onGround or $blockTarget !== null){ $this->flagForDespawn(); $block = $this->world->getBlock($pos); if(($block->isTransparent() and !$block->canBeReplaced()) or !$this->world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ())){ //FIXME: anvils are supposed to destroy torches $this->getWorld()->dropItem($this, $this->block->asItem()); }else{ $ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block); $ev->call(); if(!$ev->isCancelled()){ $this->getWorld()->setBlock($pos, $ev->getTo()); } } $hasUpdate = true; } } return $hasUpdate; } public function getBlock() : Block{ return $this->block; } public function saveNBT() : CompoundTag{ $nbt = parent::saveNBT(); $nbt->setInt("TileID", $this->block->getId()); $nbt->setByte("Data", $this->block->getMeta()); return $nbt; } protected function syncNetworkData() : void{ parent::syncNetworkData(); $this->networkProperties->setInt(EntityMetadataProperties::VARIANT, $this->block->getRuntimeId()); } }