From 979107126250514509bee756c8a19280909f0c9e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Tue, 12 May 2015 00:21:02 +0200 Subject: [PATCH] Added Player->teleportImmediate() for tp force --- src/pocketmine/Player.php | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7a06de4ab..90d7a9d8e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2931,8 +2931,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } public function sendPosition(Vector3 $pos, $yaw = null, $pitch = null, $mode = 0, $channel = Network::CHANNEL_PRIORITY){ - $yaw = $yaw === null ? $pos->yaw : $yaw; - $pitch = $pitch === null ? $pos->pitch : $pitch; + $yaw = $yaw === null ? $this->yaw : $yaw; + $pitch = $pitch === null ? $this->pitch : $pitch; $pk = new MovePlayerPacket(); $pk->eid = $this->getId(); @@ -2994,6 +2994,35 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ } } + /** + * This method may not be reliable. Clients don't like to be moved into unloaded chunks. + * Use teleport() for a delayed teleport after chunks have been sent. + * + * @param Vector3 $pos + * @param float $yaw + * @param float $pitch + */ + public function teleportImmediate(Vector3 $pos, $yaw = null, $pitch = null){ + if(parent::teleport($pos, $yaw, $pitch)){ + + foreach($this->windowIndex as $window){ + if($window === $this->inventory){ + continue; + } + $this->removeWindow($window); + } + + $this->forceMovement = new Vector3($this->x, $this->y, $this->z); + $this->sendPosition($this, $this->yaw, $this->pitch, 1, Network::CHANNEL_WORLD_EVENTS); + + + $this->resetFallDistance(); + $this->orderChunks(); + $this->nextChunkOrderRun = 0; + $this->newPosition = null; + } + } + /** * @param Inventory $inventory