13declare(strict_types=1);
15namespace pocketmine\network\mcpe\protocol;
33 public const NETWORK_ID = ProtocolInfo::PLAYER_AUTH_INPUT_PACKET;
38 private float $headYaw;
39 private float $moveVecX;
40 private float $moveVecZ;
41 private int $inputFlags;
42 private int $inputMode;
43 private int $playMode;
44 private int $interactionMode;
45 private ?
Vector3 $vrGazeDirection =
null;
51 private ?array $blockActions =
null;
53 private float $analogMoveVecX;
54 private float $analogMoveVecZ;
82 float $analogMoveVecX,
85 if($playMode ===
PlayMode::VR and $vrGazeDirection === null){
87 throw new \InvalidArgumentException(
"Gaze direction must be provided for VR play mode");
90 $result->position = $position->
asVector3();
91 $result->pitch = $pitch;
93 $result->headYaw = $headYaw;
94 $result->moveVecX = $moveVecX;
95 $result->moveVecZ = $moveVecZ;
97 $result->inputFlags = $inputFlags & ~((1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST) | (1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION) | (1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS));
98 if($itemStackRequest !==
null){
99 $result->inputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST;
101 if($itemInteractionData !==
null){
102 $result->inputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION;
104 if($blockActions !==
null){
105 $result->inputFlags |= 1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS;
107 if($vehicleInfo !==
null){
108 $result->inputFlags |= 1 << PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE;
111 $result->inputMode = $inputMode;
112 $result->playMode = $playMode;
113 $result->interactionMode = $interactionMode;
114 if($vrGazeDirection !==
null){
115 $result->vrGazeDirection = $vrGazeDirection->
asVector3();
117 $result->tick = $tick;
118 $result->delta = $delta;
119 $result->itemInteractionData = $itemInteractionData;
120 $result->itemStackRequest = $itemStackRequest;
121 $result->blockActions = $blockActions;
122 $result->vehicleInfo = $vehicleInfo;
123 $result->analogMoveVecX = $analogMoveVecX;
124 $result->analogMoveVecZ = $analogMoveVecZ;
129 return $this->position;
132 public function getPitch() : float{
136 public function getYaw() : float{
140 public function getHeadYaw() : float{
141 return $this->headYaw;
144 public function getMoveVecX() : float{
145 return $this->moveVecX;
148 public function getMoveVecZ() : float{
149 return $this->moveVecZ;
156 return $this->inputFlags;
163 return $this->inputMode;
170 return $this->playMode;
177 return $this->interactionMode;
180 public function getVrGazeDirection() : ?
Vector3{
181 return $this->vrGazeDirection;
184 public function getTick() : int{
188 public function getDelta() : Vector3{
192 public function getItemInteractionData() : ?ItemInteractionData{
193 return $this->itemInteractionData;
196 public function getItemStackRequest() : ?ItemStackRequest{
197 return $this->itemStackRequest;
204 return $this->blockActions;
209 public function getAnalogMoveVecX() : float{ return $this->analogMoveVecX; }
211 public function getAnalogMoveVecZ() : float{ return $this->analogMoveVecZ; }
213 public function hasFlag(
int $flag) : bool{
214 return ($this->inputFlags & (1 << $flag)) !== 0;
218 $this->pitch = $in->getLFloat();
228 if($this->playMode === PlayMode::VR){
233 if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
234 $this->itemInteractionData = ItemInteractionData::read($in);
236 if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST)){
237 $this->itemStackRequest = ItemStackRequest::read($in);
239 if($this->hasFlag(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS)){
240 $this->blockActions = [];
242 for($i = 0; $i < $max; ++$i){
244 $this->blockActions[] = match(
true){
245 PlayerBlockActionWithBlockInfo::isValidActionType($actionType) => PlayerBlockActionWithBlockInfo::read($in, $actionType),
246 $actionType === PlayerAction::STOP_BREAK =>
new PlayerBlockActionStopBreak(),
247 default =>
throw new PacketDecodeException(
"Unexpected block action type $actionType")
251 if($this->hasFlag(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE)){
252 $this->vehicleInfo = PlayerAuthInputVehicleInfo::read($in);
254 $this->analogMoveVecX = $in->
getLFloat();
255 $this->analogMoveVecZ = $in->
getLFloat();
259 $out->putLFloat($this->pitch);
260 $out->putLFloat($this->yaw);
262 $out->putLFloat($this->moveVecX);
263 $out->putLFloat($this->moveVecZ);
264 $out->putLFloat($this->headYaw);
269 if($this->playMode === PlayMode::VR){
270 assert($this->vrGazeDirection !==
null);
275 if($this->itemInteractionData !==
null){
276 $this->itemInteractionData->write($out);
278 if($this->itemStackRequest !==
null){
279 $this->itemStackRequest->write($out);
281 if($this->blockActions !==
null){
282 $out->
putVarInt(count($this->blockActions));
283 foreach($this->blockActions as $blockAction){
284 $out->
putVarInt($blockAction->getActionType());
285 $blockAction->write($out);
288 if($this->vehicleInfo !==
null){
289 $this->vehicleInfo->write($out);
291 $out->putLFloat($this->analogMoveVecX);
292 $out->putLFloat($this->analogMoveVecZ);
296 return $handler->handlePlayerAuthInput($this);
putVector3(Vector3 $vector)
putUnsignedVarLong(int $v)
putUnsignedVarInt(int $v)