diff --git a/src/pocketmine/network/mcpe/protocol/PlayerAuthInputPacket.php b/src/pocketmine/network/mcpe/protocol/PlayerAuthInputPacket.php index 26b018f5c..91cac5c16 100644 --- a/src/pocketmine/network/mcpe/protocol/PlayerAuthInputPacket.php +++ b/src/pocketmine/network/mcpe/protocol/PlayerAuthInputPacket.php @@ -25,17 +25,148 @@ namespace pocketmine\network\mcpe\protocol; #include +use pocketmine\math\Vector3; use pocketmine\network\mcpe\NetworkSession; +use pocketmine\network\mcpe\protocol\types\InputMode; +use pocketmine\network\mcpe\protocol\types\PlayMode; +use function assert; -class PlayerAuthInputPacket extends DataPacket{ +class PlayerAuthInputPacket extends DataPacket/* implements ServerboundPacket*/{ public const NETWORK_ID = ProtocolInfo::PLAYER_AUTH_INPUT_PACKET; + /** @var Vector3 */ + private $position; + /** @var float */ + private $pitch; + /** @var float */ + private $yaw; + /** @var float */ + private $headYaw; + /** @var float */ + private $moveVecX; + /** @var float */ + private $moveVecZ; + /** @var int */ + private $inputFlags; + /** @var int */ + private $inputMode; + /** @var int */ + private $playMode; + /** @var Vector3|null */ + private $vrGazeDirection = null; + + /** + * @param Vector3 $position + * @param float $pitch + * @param float $yaw + * @param float $headYaw + * @param float $moveVecX + * @param float $moveVecZ + * @param int $inputFlags + * @param int $inputMode @see InputMode + * @param int $playMode @see PlayMode + * @param Vector3|null $vrGazeDirection only used when PlayMode::VR + * + * @return self + */ + public static function create(Vector3 $position, float $pitch, float $yaw, float $headYaw, float $moveVecX, float $moveVecZ, int $inputFlags, int $inputMode, int $playMode, ?Vector3 $vrGazeDirection = null) : self{ + if($playMode === PlayMode::VR and $vrGazeDirection === null){ + //yuck, can we get a properly written packet just once? ... + throw new \InvalidArgumentException("Gaze direction must be provided for VR play mode"); + } + $result = new self; + $result->position = $position->asVector3(); + $result->pitch = $pitch; + $result->yaw = $yaw; + $result->headYaw = $headYaw; + $result->moveVecX = $moveVecX; + $result->moveVecZ = $moveVecZ; + $result->inputFlags = $inputFlags; + $result->inputMode = $inputMode; + $result->playMode = $playMode; + if($vrGazeDirection !== null){ + $this->vrGazeDirection = $vrGazeDirection->asVector3(); + } + return $result; + } + + public function getPosition() : Vector3{ + return $this->position; + } + + public function getPitch() : float{ + return $this->pitch; + } + + public function getYaw() : float{ + return $this->yaw; + } + + public function getHeadYaw() : float{ + return $this->headYaw; + } + + public function getMoveVecX() : float{ + return $this->moveVecX; + } + + public function getMoveVecZ() : float{ + return $this->moveVecZ; + } + + public function getInputFlags() : int{ + return $this->inputFlags; + } + + /** + * @see InputMode + * @return int + */ + public function getInputMode() : int{ + return $this->inputMode; + } + + /** + * @see PlayMode + * @return int + */ + public function getPlayMode() : int{ + return $this->playMode; + } + + public function getVrGazeDirection() : ?Vector3{ + return $this->vrGazeDirection; + } + protected function decodePayload() : void{ - //TODO + $this->yaw = $this->getLFloat(); + $this->pitch = $this->getLFloat(); + $this->position = $this->getVector3(); + $this->moveVecX = $this->getLFloat(); + $this->moveVecZ = $this->getLFloat(); + $this->headYaw = $this->getLFloat(); + $this->inputFlags = $this->getUnsignedVarLong(); + $this->inputMode = $this->getUnsignedVarInt(); + $this->playMode = $this->getUnsignedVarInt(); + if($this->playMode === PlayMode::VR){ + $this->vrGazeDirection = $this->getVector3(); + } } protected function encodePayload() : void{ - //TODO + $this->putLFloat($this->yaw); + $this->putLFloat($this->pitch); + $this->putVector3($this->position); + $this->putLFloat($this->moveVecX); + $this->putLFloat($this->moveVecZ); + $this->putLFloat($this->headYaw); + $this->putUnsignedVarLong($this->inputFlags); + $this->putUnsignedVarInt($this->inputMode); + $this->putUnsignedVarInt($this->playMode); + if($this->playMode === PlayMode::VR){ + assert($this->vrGazeDirection !== null); + $this->putVector3($this->vrGazeDirection); + } } public function handle(NetworkSession $handler) : bool{ diff --git a/src/pocketmine/network/mcpe/protocol/types/InputMode.php b/src/pocketmine/network/mcpe/protocol/types/InputMode.php new file mode 100644 index 000000000..48b1dccb7 --- /dev/null +++ b/src/pocketmine/network/mcpe/protocol/types/InputMode.php @@ -0,0 +1,36 @@ +