use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\serializer\PacketSerializer; use pocketmine\network\mcpe\protocol\types\InputMode; use pocketmine\network\mcpe\protocol\types\PlayerAuthInputFlags; use pocketmine\network\mcpe\protocol\types\PlayMode; use function assert; 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; /** @var int */ private $tick; /** @var Vector3 */ private $delta; /** * @param int $inputFlags @see InputFlags * @param int $inputMode @see InputMode * @param int $playMode @see PlayMode * @param Vector3|null $vrGazeDirection only used when PlayMode::VR */ public static function create(Vector3 $position, float $pitch, float $yaw, float $headYaw, float $moveVecX, float $moveVecZ, int $inputFlags, int $inputMode, int $playMode, ?Vector3 $vrGazeDirection, int $tick, Vector3 $delta) : 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){ $result->vrGazeDirection = $vrGazeDirection->asVector3(); } $result->tick = $tick; $result->delta = $delta; 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; } /** * @see PlayerAuthInputFlags */ public function getInputFlags() : int{ return $this->inputFlags; } /** * @see InputMode */ public function getInputMode() : int{ return $this->inputMode; } /** * @see PlayMode */ public function getPlayMode() : int{ return $this->playMode; } public function getVrGazeDirection() : ?Vector3{ return $this->vrGazeDirection; } protected function decodePayload(PacketSerializer $in) : void{ $this->pitch = $in->getLFloat(); $this->yaw = $in->getLFloat(); $this->position = $in->getVector3(); $this->moveVecX = $in->getLFloat(); $this->moveVecZ = $in->getLFloat(); $this->headYaw = $in->getLFloat(); $this->inputFlags = $in->getUnsignedVarLong(); $this->inputMode = $in->getUnsignedVarInt(); $this->playMode = $in->getUnsignedVarInt(); if($this->playMode === PlayMode::VR){ $this->vrGazeDirection = $in->getVector3(); } $this->tick = $in->getUnsignedVarLong(); $this->delta = $in->getVector3(); } protected function encodePayload(PacketSerializer $out) : void{ $out->putLFloat($this->pitch); $out->putLFloat($this->yaw); $out->putVector3($this->position); $out->putLFloat($this->moveVecX); $out->putLFloat($this->moveVecZ); $out->putLFloat($this->headYaw); $out->putUnsignedVarLong($this->inputFlags); $out->putUnsignedVarInt($this->inputMode); $out->putUnsignedVarInt($this->playMode); if($this->playMode === PlayMode::VR){ assert($this->vrGazeDirection !== null); $out->putVector3($this->vrGazeDirection); } $out->putUnsignedVarLong($this->tick); $out->putVector3($this->delta); } public function handle(PacketHandlerInterface $handler) : bool{ return $handler->handlePlayerAuthInput($this); } }