PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
AddPlayerPacket.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
24use Ramsey\Uuid\UuidInterface;
25use function count;
26
28 public const NETWORK_ID = ProtocolInfo::ADD_PLAYER_PACKET;
29
30 public UuidInterface $uuid;
31 public string $username;
32 public int $actorRuntimeId;
33 public string $platformChatId = "";
34 public Vector3 $position;
35 public ?Vector3 $motion = null;
36 public float $pitch = 0.0;
37 public float $yaw = 0.0;
38 public float $headYaw = 0.0;
39 public ItemStackWrapper $item;
40 public int $gameMode;
45 public array $metadata = [];
46 public PropertySyncData $syncedProperties;
47
48 public UpdateAbilitiesPacket $abilitiesPacket;
49
51 public array $links = [];
52 public string $deviceId = ""; //TODO: fill player's device ID (???)
53 public int $buildPlatform = DeviceOS::UNKNOWN;
54
61 public static function create(
62 UuidInterface $uuid,
63 string $username,
64 int $actorRuntimeId,
65 string $platformChatId,
66 Vector3 $position,
67 ?Vector3 $motion,
68 float $pitch,
69 float $yaw,
70 float $headYaw,
71 ItemStackWrapper $item,
72 int $gameMode,
73 array $metadata,
74 PropertySyncData $syncedProperties,
75 UpdateAbilitiesPacket $abilitiesPacket,
76 array $links,
77 string $deviceId,
78 int $buildPlatform,
79 ) : self{
80 $result = new self;
81 $result->uuid = $uuid;
82 $result->username = $username;
83 $result->actorRuntimeId = $actorRuntimeId;
84 $result->platformChatId = $platformChatId;
85 $result->position = $position;
86 $result->motion = $motion;
87 $result->pitch = $pitch;
88 $result->yaw = $yaw;
89 $result->headYaw = $headYaw;
90 $result->item = $item;
91 $result->gameMode = $gameMode;
92 $result->metadata = $metadata;
93 $result->syncedProperties = $syncedProperties;
94 $result->abilitiesPacket = $abilitiesPacket;
95 $result->links = $links;
96 $result->deviceId = $deviceId;
97 $result->buildPlatform = $buildPlatform;
98 return $result;
99 }
100
101 protected function decodePayload(PacketSerializer $in) : void{
102 $this->uuid = $in->getUUID();
103 $this->username = $in->getString();
104 $this->actorRuntimeId = $in->getActorRuntimeId();
105 $this->platformChatId = $in->getString();
106 $this->position = $in->getVector3();
107 $this->motion = $in->getVector3();
108 $this->pitch = $in->getLFloat();
109 $this->yaw = $in->getLFloat();
110 $this->headYaw = $in->getLFloat();
111 $this->item = $in->getItemStackWrapper();
112 $this->gameMode = $in->getVarInt();
113 $this->metadata = $in->getEntityMetadata();
114 $this->syncedProperties = PropertySyncData::read($in);
115
116 $this->abilitiesPacket = new UpdateAbilitiesPacket();
117 $this->abilitiesPacket->decodePayload($in);
118
119 $linkCount = $in->getUnsignedVarInt();
120 for($i = 0; $i < $linkCount; ++$i){
121 $this->links[$i] = $in->getEntityLink();
122 }
123
124 $this->deviceId = $in->getString();
125 $this->buildPlatform = $in->getLInt();
126 }
127
128 protected function encodePayload(PacketSerializer $out) : void{
129 $out->putUUID($this->uuid);
130 $out->putString($this->username);
131 $out->putActorRuntimeId($this->actorRuntimeId);
132 $out->putString($this->platformChatId);
133 $out->putVector3($this->position);
134 $out->putVector3Nullable($this->motion);
135 $out->putLFloat($this->pitch);
136 $out->putLFloat($this->yaw);
137 $out->putLFloat($this->headYaw);
138 $out->putItemStackWrapper($this->item);
139 $out->putVarInt($this->gameMode);
140 $out->putEntityMetadata($this->metadata);
141 $this->syncedProperties->write($out);
142
143 $this->abilitiesPacket->encodePayload($out);
144
145 $out->putUnsignedVarInt(count($this->links));
146 foreach($this->links as $link){
147 $out->putEntityLink($link);
148 }
149
150 $out->putString($this->deviceId);
151 $out->putLInt($this->buildPlatform);
152 }
153
154 public function handle(PacketHandlerInterface $handler) : bool{
155 return $handler->handleAddPlayer($this);
156 }
157}
static create(UuidInterface $uuid, string $username, int $actorRuntimeId, string $platformChatId, Vector3 $position, ?Vector3 $motion, float $pitch, float $yaw, float $headYaw, ItemStackWrapper $item, int $gameMode, array $metadata, PropertySyncData $syncedProperties, UpdateAbilitiesPacket $abilitiesPacket, array $links, string $deviceId, int $buildPlatform,)