diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 08cee3c74..8e4402c79 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1370,9 +1370,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->isSpectator()){ $this->setFlying(true); $this->keepMovement = true; + $this->onGround = false; + + //TODO: HACK! this syncs the onground flag with the client so that flying works properly + //this is a yucky hack but we don't have any other options :( + $this->sendPosition($this, null, null, MovePlayerPacket::MODE_TELEPORT); + $this->despawnFromAll(); }else{ $this->keepMovement = $this->allowMovementCheats; + $this->checkGroundState(0, 0, 0, 0, 0, 0); if($this->isSurvival()){ $this->setFlying(false); } @@ -1493,11 +1500,15 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz) : void{ - $bb = clone $this->boundingBox; - $bb->minY = $this->y - 0.2; - $bb->maxY = $this->y + 0.2; + if($this->isSpectator()){ + $this->onGround = false; + }else{ + $bb = clone $this->boundingBox; + $bb->minY = $this->y - 0.2; + $bb->maxY = $this->y + 0.2; - $this->onGround = $this->isCollided = count($this->level->getCollisionBlocks($bb, true)) > 0; + $this->onGround = $this->isCollided = count($this->level->getCollisionBlocks($bb, true)) > 0; + } } public function canBeMovedByCurrents() : bool{