From 2b02fcfe2c5bc09c6c2982289df0be940643448d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 4 Jun 2017 16:54:25 +0100 Subject: [PATCH] fixed #992 --- src/pocketmine/network/mcpe/protocol/DataPacket.php | 8 ++++++++ .../network/mcpe/protocol/MobEquipmentPacket.php | 2 +- .../network/mcpe/protocol/MoveEntityPacket.php | 12 ++++++------ src/pocketmine/utils/BinaryStream.php | 4 ++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/pocketmine/network/mcpe/protocol/DataPacket.php b/src/pocketmine/network/mcpe/protocol/DataPacket.php index 7ac620149..4e09d5c32 100644 --- a/src/pocketmine/network/mcpe/protocol/DataPacket.php +++ b/src/pocketmine/network/mcpe/protocol/DataPacket.php @@ -355,4 +355,12 @@ abstract class DataPacket extends BinaryStream{ $this->putLFloat($y); $this->putLFloat($z); } + + public function getByteRotation() : float{ + return (float) ($this->getByte() * (360 / 256)); + } + + public function putByteRotation(float $rotation){ + $this->putByte((int) ($rotation / (360 / 256))); + } } diff --git a/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php index d87d294a1..d06722265 100644 --- a/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MobEquipmentPacket.php @@ -33,7 +33,7 @@ class MobEquipmentPacket extends DataPacket{ public $item; public $inventorySlot; public $hotbarSlot; - public $unknownByte; + public $unknownByte = 0; public function decode(){ $this->eid = $this->getEntityRuntimeId(); diff --git a/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php index 0a9ad2078..d8613bc13 100644 --- a/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php +++ b/src/pocketmine/network/mcpe/protocol/MoveEntityPacket.php @@ -42,9 +42,9 @@ class MoveEntityPacket extends DataPacket{ public function decode(){ $this->eid = $this->getEntityRuntimeId(); $this->getVector3f($this->x, $this->y, $this->z); - $this->pitch = $this->getByte() * (360.0 / 256); - $this->headYaw = $this->getByte() * (360.0 / 256); - $this->yaw = $this->getByte() * (360.0 / 256); + $this->pitch = $this->getByteRotation(); + $this->headYaw = $this->getByteRotation(); + $this->yaw = $this->getByteRotation(); $this->onGround = $this->getBool(); $this->teleported = $this->getBool(); } @@ -53,9 +53,9 @@ class MoveEntityPacket extends DataPacket{ $this->reset(); $this->putEntityRuntimeId($this->eid); $this->putVector3f($this->x, $this->y, $this->z); - $this->putByte($this->pitch / (360.0 / 256)); - $this->putByte($this->headYaw / (360.0 / 256)); - $this->putByte($this->yaw / (360.0 / 256)); + $this->putByteRotation($this->pitch); + $this->putByteRotation($this->headYaw); + $this->putByteRotation($this->yaw); $this->putBool($this->onGround); $this->putBool($this->teleported); } diff --git a/src/pocketmine/utils/BinaryStream.php b/src/pocketmine/utils/BinaryStream.php index 423fc8207..0f6e213fa 100644 --- a/src/pocketmine/utils/BinaryStream.php +++ b/src/pocketmine/utils/BinaryStream.php @@ -178,11 +178,11 @@ class BinaryStream{ $this->buffer .= Binary::writeLTriad($v); } - public function getByte(){ + public function getByte() : int{ return ord($this->buffer{$this->offset++}); } - public function putByte($v){ + public function putByte(int $v){ $this->buffer .= chr($v); }