PocketMine-MP 5.44.4 git-bc94a0da0c87abe7eb99d229a9ec672b3c405d11
Loading...
Searching...
No Matches
StartGamePacket.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\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
31use Ramsey\Uuid\UuidInterface;
32use function count;
33
35 public const NETWORK_ID = ProtocolInfo::START_GAME_PACKET;
36
37 public int $actorUniqueId;
38 public int $actorRuntimeId;
39 public int $playerGamemode;
40
41 public Vector3 $playerPosition;
42
43 public float $pitch;
44 public float $yaw;
45
47 public CacheableNbt $playerActorProperties; //same as SyncActorPropertyPacket content
48
49 public LevelSettings $levelSettings;
50
51 public string $levelId = ""; //base64 string, usually the same as world folder name in vanilla
52 public string $worldName;
53 public string $premiumWorldTemplateId = "";
54 public bool $isTrial = false;
55 public PlayerMovementSettings $playerMovementSettings;
56 public int $currentTick = 0; //only used if isTrial is true
57 public int $enchantmentSeed = 0;
58 public string $multiplayerCorrelationId = ""; //TODO: this should be filled with a UUID of some sort
59 public bool $enableNewInventorySystem = false; //TODO
60 public string $serverSoftwareVersion;
61 public UuidInterface $worldTemplateId; //why is this here twice ??? mojang
62 public bool $enableClientSideChunkGeneration;
63 public bool $blockNetworkIdsAreHashes = false; //new in 1.19.80, possibly useful for multi version
64 public NetworkPermissions $networkPermissions;
65 public bool $isLoggingChat = false;
66 public ?ServerJoinInformation $serverJoinInformation;
67 public ServerTelemetryData $serverTelemetryData;
68
73 public array $blockPalette = [];
74
81
88 public static function create(
89 int $actorUniqueId,
90 int $actorRuntimeId,
91 int $playerGamemode,
92 Vector3 $playerPosition,
93 float $pitch,
94 float $yaw,
96 LevelSettings $levelSettings,
97 string $levelId,
98 string $worldName,
99 string $premiumWorldTemplateId,
100 bool $isTrial,
101 PlayerMovementSettings $playerMovementSettings,
102 int $currentTick,
103 int $enchantmentSeed,
104 string $multiplayerCorrelationId,
105 bool $enableNewInventorySystem,
106 string $serverSoftwareVersion,
107 UuidInterface $worldTemplateId,
108 bool $enableClientSideChunkGeneration,
109 bool $blockNetworkIdsAreHashes,
110 NetworkPermissions $networkPermissions,
111 bool $isLoggingChat,
112 ?ServerJoinInformation $serverJoinInformation,
113 ServerTelemetryData $serverTelemetryData,
114 array $blockPalette,
116 ) : self{
117 $result = new self;
118 $result->actorUniqueId = $actorUniqueId;
119 $result->actorRuntimeId = $actorRuntimeId;
120 $result->playerGamemode = $playerGamemode;
121 $result->playerPosition = $playerPosition;
122 $result->pitch = $pitch;
123 $result->yaw = $yaw;
124 $result->playerActorProperties = $playerActorProperties;
125 $result->levelSettings = $levelSettings;
126 $result->levelId = $levelId;
127 $result->worldName = $worldName;
128 $result->premiumWorldTemplateId = $premiumWorldTemplateId;
129 $result->isTrial = $isTrial;
130 $result->playerMovementSettings = $playerMovementSettings;
131 $result->currentTick = $currentTick;
132 $result->enchantmentSeed = $enchantmentSeed;
133 $result->multiplayerCorrelationId = $multiplayerCorrelationId;
134 $result->enableNewInventorySystem = $enableNewInventorySystem;
135 $result->serverSoftwareVersion = $serverSoftwareVersion;
136 $result->worldTemplateId = $worldTemplateId;
137 $result->enableClientSideChunkGeneration = $enableClientSideChunkGeneration;
138 $result->blockNetworkIdsAreHashes = $blockNetworkIdsAreHashes;
139 $result->networkPermissions = $networkPermissions;
140 $result->isLoggingChat = $isLoggingChat;
141 $result->serverJoinInformation = $serverJoinInformation;
142 $result->serverTelemetryData = $serverTelemetryData;
143 $result->blockPalette = $blockPalette;
144 $result->blockPaletteChecksum = $blockPaletteChecksum;
145 return $result;
146 }
147
148 protected function decodePayload(ByteBufferReader $in) : void{
149 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
150 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
151 $this->playerGamemode = VarInt::readSignedInt($in);
152
153 $this->playerPosition = CommonTypes::getVector3($in);
154
155 $this->pitch = LE::readFloat($in);
156 $this->yaw = LE::readFloat($in);
157
158 $this->levelSettings = LevelSettings::read($in);
159
160 $this->levelId = CommonTypes::getString($in);
161 $this->worldName = CommonTypes::getString($in);
162 $this->premiumWorldTemplateId = CommonTypes::getString($in);
163 $this->isTrial = CommonTypes::getBool($in);
164 $this->playerMovementSettings = PlayerMovementSettings::read($in);
165 $this->currentTick = LE::readUnsignedLong($in);
166
167 $this->enchantmentSeed = VarInt::readSignedInt($in);
168
169 $this->blockPalette = [];
170 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
171 $blockName = CommonTypes::getString($in);
172 $state = CommonTypes::getNbtCompoundRoot($in);
173 $this->blockPalette[] = new BlockPaletteEntry($blockName, new CacheableNbt($state));
174 }
175
176 $this->multiplayerCorrelationId = CommonTypes::getString($in);
177 $this->enableNewInventorySystem = CommonTypes::getBool($in);
178 $this->serverSoftwareVersion = CommonTypes::getString($in);
179 $this->playerActorProperties = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
180 $this->blockPaletteChecksum = LE::readUnsignedLong($in);
181 $this->worldTemplateId = CommonTypes::getUUID($in);
182 $this->enableClientSideChunkGeneration = CommonTypes::getBool($in);
183 $this->blockNetworkIdsAreHashes = CommonTypes::getBool($in);
184 $this->networkPermissions = NetworkPermissions::decode($in);
185 $this->isLoggingChat = CommonTypes::getBool($in);
186 $this->serverJoinInformation = CommonTypes::readOptional($in, ServerJoinInformation::read(...));
187 $this->serverTelemetryData = ServerTelemetryData::read($in);
188 }
189
190 protected function encodePayload(ByteBufferWriter $out) : void{
191 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
192 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
193 VarInt::writeSignedInt($out, $this->playerGamemode);
194
195 CommonTypes::putVector3($out, $this->playerPosition);
196
197 LE::writeFloat($out, $this->pitch);
198 LE::writeFloat($out, $this->yaw);
199
200 $this->levelSettings->write($out);
201
202 CommonTypes::putString($out, $this->levelId);
203 CommonTypes::putString($out, $this->worldName);
204 CommonTypes::putString($out, $this->premiumWorldTemplateId);
205 CommonTypes::putBool($out, $this->isTrial);
206 $this->playerMovementSettings->write($out);
207 LE::writeUnsignedLong($out, $this->currentTick);
208
209 VarInt::writeSignedInt($out, $this->enchantmentSeed);
210
211 VarInt::writeUnsignedInt($out, count($this->blockPalette));
212 foreach($this->blockPalette as $entry){
213 CommonTypes::putString($out, $entry->getName());
214 $out->writeByteArray($entry->getStates()->getEncodedNbt());
215 }
216
217 CommonTypes::putString($out, $this->multiplayerCorrelationId);
218 CommonTypes::putBool($out, $this->enableNewInventorySystem);
219 CommonTypes::putString($out, $this->serverSoftwareVersion);
220 $out->writeByteArray($this->playerActorProperties->getEncodedNbt());
221 LE::writeUnsignedLong($out, $this->blockPaletteChecksum);
222 CommonTypes::putUUID($out, $this->worldTemplateId);
223 CommonTypes::putBool($out, $this->enableClientSideChunkGeneration);
224 CommonTypes::putBool($out, $this->blockNetworkIdsAreHashes);
225 $this->networkPermissions->encode($out);
226 CommonTypes::putBool($out, $this->isLoggingChat);
227 CommonTypes::writeOptional($out, $this->serverJoinInformation, fn(ByteBufferWriter $out, ServerJoinInformation $info) => $info->write($out));
228 $this->serverTelemetryData->write($out);
229 }
230
231 public function handle(PacketHandlerInterface $handler) : bool{
232 return $handler->handleStartGame($this);
233 }
234}
static create(int $actorUniqueId, int $actorRuntimeId, int $playerGamemode, Vector3 $playerPosition, float $pitch, float $yaw, CacheableNbt $playerActorProperties, LevelSettings $levelSettings, string $levelId, string $worldName, string $premiumWorldTemplateId, bool $isTrial, PlayerMovementSettings $playerMovementSettings, int $currentTick, int $enchantmentSeed, string $multiplayerCorrelationId, bool $enableNewInventorySystem, string $serverSoftwareVersion, UuidInterface $worldTemplateId, bool $enableClientSideChunkGeneration, bool $blockNetworkIdsAreHashes, NetworkPermissions $networkPermissions, bool $isLoggingChat, ?ServerJoinInformation $serverJoinInformation, ServerTelemetryData $serverTelemetryData, array $blockPalette, int $blockPaletteChecksum,)