namedtag->id = new String("id", "FallingSand"); if(isset($this->namedtag->TileID)){ $this->blockId = $this->namedtag["TileID"]; } elseif(isset($this->namedtag->Tile)){ $this->blockId = $this->namedtag["Tile"]; $this->namedtag["TileID"] = new Int("TileID", $this->blockId); } if($this->blockId === 0){ $this->close(); } } public function canCollideWith(Entity $entity){ return false; } public function getData(){ return []; } public function onUpdate($currentTick){ if($this->closed){ return false; } $this->timings->startTiming(); $tickDiff = max(1, $currentTick - $this->lastUpdate); $this->lastUpdate = $currentTick; $hasUpdate = $this->entityBaseTick($tickDiff); if(!$this->dead){ if($this->ticksLived === 1){ $block = $this->level->getBlock($this->floor()); if($block->getID() != $this->blockId){ $this->kill(); return true; } $this->level->setBlock($this->floor(), Block::get(0), true); } $this->motionY -= $this->gravity; $this->move($this->motionX, $this->motionY, $this->motionZ); $friction = 1 - $this->drag; $this->motionX *= $friction; $this->motionY *= 1 - $this->drag; $this->motionZ *= $friction; $pos = $this->floor(); if($this->onGround){ $this->kill(); $block = $this->level->getBlock($pos); if(!$block->isFullBlock){ $this->getLevel()->dropItem($this, Item::get($this->getBlock(), $this->getDamage(), 1)); }else{ $this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage()))); if(!$ev->isCancelled()){ $this->getLevel()->setBlock($pos, $ev->getTo(), true); } } $hasUpdate = true; } $this->updateMovement(); } return $hasUpdate or !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0); } public function getBlock(){ return $this->blockId; } public function getDamage(){ return $this->damage; } public function saveNBT(){ $this->namedtag->TileID = new Int("TileID", $this->blockId); $this->namedtag->Data = new Byte("Data", $this->damage); } public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){ } public function heal($amount, $source = EntityRegainHealthEvent::CAUSE_MAGIC){ } public function spawnTo(Player $player){ $pk = new AddEntityPacket; $pk->type = FallingBlock::NETWORK_ID; $pk->eid = $this->getID(); $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->did = -$this->getBlock(); $player->dataPacket($pk); $pk = new SetEntityMotionPacket; $pk->entities = [ [$this->getID(), $this->motionX, $this->motionY, $this->motionZ] ]; $player->dataPacket($pk); parent::spawnTo($player); } }