teleport(); return true; } public function onAttack(Item $item, int $face, ?Player $player = null) : bool{ $this->teleport(); return true; } public function teleport() : void{ for($tries = 0; $tries < 16; ++$tries){ $block = $this->world->getBlockAt( $this->x + mt_rand(-16, 16), max(0, min(World::Y_MAX - 1, $this->y + mt_rand(-8, 8))), $this->z + mt_rand(-16, 16) ); if($block instanceof Air){ $ev = new BlockTeleportEvent($this, $block); $ev->call(); if($ev->isCancelled()){ break; }else{ $block = $ev->getTo(); } $this->world->addParticle($this, new DragonEggTeleportParticle($this->x - $block->x, $this->y - $block->y, $this->z - $block->z)); $this->world->setBlock($this, VanillaBlocks::AIR()); $this->world->setBlock($block, $this); break; } } } }