PocketMine-MP 5.15.1 git-08c6e63aac45a450fe3b437616ee8aa2500e04e2
MovePlayerPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
19
21 public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET;
22
23 public const MODE_NORMAL = 0;
24 public const MODE_RESET = 1;
25 public const MODE_TELEPORT = 2;
26 public const MODE_PITCH = 3; //facepalm Mojang
27
28 public int $actorRuntimeId;
29 public Vector3 $position;
30 public float $pitch;
31 public float $yaw;
32 public float $headYaw;
33 public int $mode = self::MODE_NORMAL;
34 public bool $onGround = false; //TODO
35 public int $ridingActorRuntimeId = 0;
36 public int $teleportCause = 0;
37 public int $teleportItem = 0;
38 public int $tick = 0;
39
43 public static function create(
44 int $actorRuntimeId,
45 Vector3 $position,
46 float $pitch,
47 float $yaw,
48 float $headYaw,
49 int $mode,
50 bool $onGround,
51 int $ridingActorRuntimeId,
52 int $teleportCause,
53 int $teleportItem,
54 int $tick,
55 ) : self{
56 $result = new self;
57 $result->actorRuntimeId = $actorRuntimeId;
58 $result->position = $position;
59 $result->pitch = $pitch;
60 $result->yaw = $yaw;
61 $result->headYaw = $headYaw;
62 $result->mode = $mode;
63 $result->onGround = $onGround;
64 $result->ridingActorRuntimeId = $ridingActorRuntimeId;
65 $result->teleportCause = $teleportCause;
66 $result->teleportItem = $teleportItem;
67 $result->tick = $tick;
68 return $result;
69 }
70
71 public static function simple(
72 int $actorRuntimeId,
73 Vector3 $position,
74 float $pitch,
75 float $yaw,
76 float $headYaw,
77 int $mode,
78 bool $onGround,
79 int $ridingActorRuntimeId,
80 int $tick,
81 ) : self{
82 return self::create($actorRuntimeId, $position, $pitch, $yaw, $headYaw, $mode, $onGround, $ridingActorRuntimeId, 0, 0, $tick);
83 }
84
85 protected function decodePayload(PacketSerializer $in) : void{
86 $this->actorRuntimeId = $in->getActorRuntimeId();
87 $this->position = $in->getVector3();
88 $this->pitch = $in->getLFloat();
89 $this->yaw = $in->getLFloat();
90 $this->headYaw = $in->getLFloat();
91 $this->mode = $in->getByte();
92 $this->onGround = $in->getBool();
93 $this->ridingActorRuntimeId = $in->getActorRuntimeId();
94 if($this->mode === MovePlayerPacket::MODE_TELEPORT){
95 $this->teleportCause = $in->getLInt();
96 $this->teleportItem = $in->getLInt();
97 }
98 $this->tick = $in->getUnsignedVarLong();
99 }
100
101 protected function encodePayload(PacketSerializer $out) : void{
102 $out->putActorRuntimeId($this->actorRuntimeId);
103 $out->putVector3($this->position);
104 $out->putLFloat($this->pitch);
105 $out->putLFloat($this->yaw);
106 $out->putLFloat($this->headYaw); //TODO
107 $out->putByte($this->mode);
108 $out->putBool($this->onGround);
109 $out->putActorRuntimeId($this->ridingActorRuntimeId);
110 if($this->mode === MovePlayerPacket::MODE_TELEPORT){
111 $out->putLInt($this->teleportCause);
112 $out->putLInt($this->teleportItem);
113 }
114 $out->putUnsignedVarLong($this->tick);
115 }
116
117 public function handle(PacketHandlerInterface $handler) : bool{
118 return $handler->handleMovePlayer($this);
119 }
120}
static create(int $actorRuntimeId, Vector3 $position, float $pitch, float $yaw, float $headYaw, int $mode, bool $onGround, int $ridingActorRuntimeId, int $teleportCause, int $teleportItem, int $tick,)