diff --git a/src/network/protocol/packet/AddMobPacket.php b/src/network/protocol/packet/AddMobPacket.php index 56620be3..2bce53a9 100644 --- a/src/network/protocol/packet/AddMobPacket.php +++ b/src/network/protocol/packet/AddMobPacket.php @@ -25,8 +25,8 @@ class AddMobPacket extends RakNetDataPacket{ $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); - $this->putByte($this->yaw); - $this->putByte($this->pitch); + $this->putByte(Utils::rotDegreesToChar($this->yaw)); + $this->putByte(Utils::rotDegreesToChar($this->pitch)); $this->put(Utils::writeMetadata($this->metadata)); } diff --git a/src/network/protocol/packet/AddPlayerPacket.php b/src/network/protocol/packet/AddPlayerPacket.php index 166a27e1..b59af0ed 100644 --- a/src/network/protocol/packet/AddPlayerPacket.php +++ b/src/network/protocol/packet/AddPlayerPacket.php @@ -40,8 +40,8 @@ class AddPlayerPacket extends RakNetDataPacket{ $this->putFloat($this->x); $this->putFloat($this->y); $this->putFloat($this->z); - $this->putByte($this->yaw); - $this->putByte($this->pitch); + $this->putByte(Utils::rotDegreesToChar($this->yaw)); + $this->putByte(Utils::rotDegreesToChar($this->pitch)); $this->putShort($this->itemID); $this->putShort($this->itemAuxValue); //Example: bow shooting power $this->put(Utils::writeMetadata($this->metadata)); diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 66c36938..8215e5db 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -457,6 +457,16 @@ class Utils{ return substr(pack("N", $value), 1); } + public static function rotDegreesToChar(float $deg) : int{ + return ((int)(($deg / 360.0) * 256.0)) & 0xFF; + } + + public static function rotCharToDegrees(int $char) : float{ + $char = $char & 0xFF; + if($char >= 128) $char -= 256; + return $char * 360.0 / 256.0; + } + public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0){ return $raw ? random_bytes($length) : bin2hex(random_bytes($length)); //nobody would ever notice other parameters }