PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\LE;
21use pmmp\encoding\VarInt;
24
26 public const NETWORK_ID = ProtocolInfo::MOVE_PLAYER_PACKET;
27
28 public const MODE_NORMAL = 0;
29 public const MODE_RESET = 1;
30 public const MODE_TELEPORT = 2;
31 public const MODE_PITCH = 3; //facepalm Mojang
32
33 public int $actorRuntimeId;
34 public Vector3 $position;
35 public float $pitch;
36 public float $yaw;
37 public float $headYaw;
38 public int $mode = self::MODE_NORMAL;
39 public bool $onGround = false; //TODO
40 public int $ridingActorRuntimeId = 0;
41 public int $teleportCause = 0;
42 public int $teleportItem = 0;
43 public int $tick = 0;
44
48 public static function create(
49 int $actorRuntimeId,
50 Vector3 $position,
51 float $pitch,
52 float $yaw,
53 float $headYaw,
54 int $mode,
55 bool $onGround,
56 int $ridingActorRuntimeId,
57 int $teleportCause,
58 int $teleportItem,
59 int $tick,
60 ) : self{
61 $result = new self;
62 $result->actorRuntimeId = $actorRuntimeId;
63 $result->position = $position;
64 $result->pitch = $pitch;
65 $result->yaw = $yaw;
66 $result->headYaw = $headYaw;
67 $result->mode = $mode;
68 $result->onGround = $onGround;
69 $result->ridingActorRuntimeId = $ridingActorRuntimeId;
70 $result->teleportCause = $teleportCause;
71 $result->teleportItem = $teleportItem;
72 $result->tick = $tick;
73 return $result;
74 }
75
76 public static function simple(
77 int $actorRuntimeId,
78 Vector3 $position,
79 float $pitch,
80 float $yaw,
81 float $headYaw,
82 int $mode,
83 bool $onGround,
84 int $ridingActorRuntimeId,
85 int $tick,
86 ) : self{
87 return self::create($actorRuntimeId, $position, $pitch, $yaw, $headYaw, $mode, $onGround, $ridingActorRuntimeId, 0, 0, $tick);
88 }
89
90 protected function decodePayload(ByteBufferReader $in) : void{
91 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
92 $this->position = CommonTypes::getVector3($in);
93 $this->pitch = LE::readFloat($in);
94 $this->yaw = LE::readFloat($in);
95 $this->headYaw = LE::readFloat($in);
96 $this->mode = Byte::readUnsigned($in);
97 $this->onGround = CommonTypes::getBool($in);
98 $this->ridingActorRuntimeId = CommonTypes::getActorRuntimeId($in);
99 if($this->mode === MovePlayerPacket::MODE_TELEPORT){
100 $this->teleportCause = LE::readSignedInt($in);
101 $this->teleportItem = LE::readSignedInt($in);
102 }
103 $this->tick = VarInt::readUnsignedLong($in);
104 }
105
106 protected function encodePayload(ByteBufferWriter $out) : void{
107 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
108 CommonTypes::putVector3($out, $this->position);
109 LE::writeFloat($out, $this->pitch);
110 LE::writeFloat($out, $this->yaw);
111 LE::writeFloat($out, $this->headYaw); //TODO
112 Byte::writeUnsigned($out, $this->mode);
113 CommonTypes::putBool($out, $this->onGround);
114 CommonTypes::putActorRuntimeId($out, $this->ridingActorRuntimeId);
115 if($this->mode === MovePlayerPacket::MODE_TELEPORT){
116 LE::writeSignedInt($out, $this->teleportCause);
117 LE::writeSignedInt($out, $this->teleportItem);
118 }
119 VarInt::writeUnsignedLong($out, $this->tick);
120 }
121
122 public function handle(PacketHandlerInterface $handler) : bool{
123 return $handler->handleMovePlayer($this);
124 }
125}
static create(int $actorRuntimeId, Vector3 $position, float $pitch, float $yaw, float $headYaw, int $mode, bool $onGround, int $ridingActorRuntimeId, int $teleportCause, int $teleportItem, int $tick,)