namedtag->TileID)){ $blockId = (int) $this->namedtag["TileID"]; }elseif(isset($this->namedtag->Tile)){ $blockId = (int) $this->namedtag["Tile"]; $this->namedtag["TileID"] = new IntTag("TileID", $blockId); } if(isset($this->namedtag->Data)){ $damage = (int) $this->namedtag["Data"]; } if($blockId === 0){ $this->close(); return; } $this->block = Block::get($blockId, $damage); $this->setDataProperty(self::DATA_VARIANT, self::DATA_TYPE_INT, $this->block->getId() | ($this->block->getDamage() << 8)); } public function canCollideWith(Entity $entity) : bool{ return false; } public function attack(EntityDamageEvent $source){ 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->isAlive()){ $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->kill(); $block = $this->level->getBlock($pos); if($block->getId() > 0 and $block->isTransparent() and !$block->canBeReplaced()){ //FIXME: anvils are supposed to destroy torches $this->getLevel()->dropItem($this, ItemFactory::get($this->getBlock(), $this->getDamage())); }else{ $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block)); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($pos, $ev->getTo(), true); } } $hasUpdate = true; } } return $hasUpdate; } public function getBlock(){ return $this->block->getId(); } public function getDamage(){ return $this->block->getDamage(); } public function saveNBT(){ $this->namedtag->TileID = new IntTag("TileID", $this->block->getId()); $this->namedtag->Data = new ByteTag("Data", $this->block->getDamage()); } public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->type = FallingSand::NETWORK_ID; $pk->entityRuntimeId = $this->getId(); $pk->position = $this->asVector3(); $pk->motion = $this->getMotion(); $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = $this->dataProperties; $player->dataPacket($pk); parent::spawnTo($player); } }