PocketMine-MP 5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
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
26use Ramsey\Uuid\UuidInterface;
27use function count;
28
30 public const NETWORK_ID = ProtocolInfo::START_GAME_PACKET;
31
32 public int $actorUniqueId;
33 public int $actorRuntimeId;
34 public int $playerGamemode;
35
36 public Vector3 $playerPosition;
37
38 public float $pitch;
39 public float $yaw;
40
42 public CacheableNbt $playerActorProperties; //same as SyncActorPropertyPacket content
43
44 public LevelSettings $levelSettings;
45
46 public string $levelId = ""; //base64 string, usually the same as world folder name in vanilla
47 public string $worldName;
48 public string $premiumWorldTemplateId = "";
49 public bool $isTrial = false;
50 public PlayerMovementSettings $playerMovementSettings;
51 public int $currentTick = 0; //only used if isTrial is true
52 public int $enchantmentSeed = 0;
53 public string $multiplayerCorrelationId = ""; //TODO: this should be filled with a UUID of some sort
54 public bool $enableNewInventorySystem = false; //TODO
55 public string $serverSoftwareVersion;
56 public UuidInterface $worldTemplateId; //why is this here twice ??? mojang
57 public bool $enableClientSideChunkGeneration;
58 public bool $blockNetworkIdsAreHashes = false; //new in 1.19.80, possibly useful for multi version
59 public NetworkPermissions $networkPermissions;
60
65 public array $blockPalette = [];
66
73
78 public array $itemTable;
79
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 array $blockPalette,
113 array $itemTable,
114 ) : self{
115 $result = new self;
116 $result->actorUniqueId = $actorUniqueId;
117 $result->actorRuntimeId = $actorRuntimeId;
118 $result->playerGamemode = $playerGamemode;
119 $result->playerPosition = $playerPosition;
120 $result->pitch = $pitch;
121 $result->yaw = $yaw;
122 $result->playerActorProperties = $playerActorProperties;
123 $result->levelSettings = $levelSettings;
124 $result->levelId = $levelId;
125 $result->worldName = $worldName;
126 $result->premiumWorldTemplateId = $premiumWorldTemplateId;
127 $result->isTrial = $isTrial;
128 $result->playerMovementSettings = $playerMovementSettings;
129 $result->currentTick = $currentTick;
130 $result->enchantmentSeed = $enchantmentSeed;
131 $result->multiplayerCorrelationId = $multiplayerCorrelationId;
132 $result->enableNewInventorySystem = $enableNewInventorySystem;
133 $result->serverSoftwareVersion = $serverSoftwareVersion;
134 $result->worldTemplateId = $worldTemplateId;
135 $result->enableClientSideChunkGeneration = $enableClientSideChunkGeneration;
136 $result->blockNetworkIdsAreHashes = $blockNetworkIdsAreHashes;
137 $result->networkPermissions = $networkPermissions;
138 $result->blockPalette = $blockPalette;
139 $result->blockPaletteChecksum = $blockPaletteChecksum;
140 $result->itemTable = $itemTable;
141 return $result;
142 }
143
144 protected function decodePayload(PacketSerializer $in) : void{
145 $this->actorUniqueId = $in->getActorUniqueId();
146 $this->actorRuntimeId = $in->getActorRuntimeId();
147 $this->playerGamemode = $in->getVarInt();
148
149 $this->playerPosition = $in->getVector3();
150
151 $this->pitch = $in->getLFloat();
152 $this->yaw = $in->getLFloat();
153
154 $this->levelSettings = LevelSettings::read($in);
155
156 $this->levelId = $in->getString();
157 $this->worldName = $in->getString();
158 $this->premiumWorldTemplateId = $in->getString();
159 $this->isTrial = $in->getBool();
160 $this->playerMovementSettings = PlayerMovementSettings::read($in);
161 $this->currentTick = $in->getLLong();
162
163 $this->enchantmentSeed = $in->getVarInt();
164
165 $this->blockPalette = [];
166 for($i = 0, $len = $in->getUnsignedVarInt(); $i < $len; ++$i){
167 $blockName = $in->getString();
168 $state = $in->getNbtCompoundRoot();
169 $this->blockPalette[] = new BlockPaletteEntry($blockName, new CacheableNbt($state));
170 }
171
172 $this->itemTable = [];
173 for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
174 $stringId = $in->getString();
175 $numericId = $in->getSignedLShort();
176 $isComponentBased = $in->getBool();
177
178 $this->itemTable[] = new ItemTypeEntry($stringId, $numericId, $isComponentBased);
179 }
180
181 $this->multiplayerCorrelationId = $in->getString();
182 $this->enableNewInventorySystem = $in->getBool();
183 $this->serverSoftwareVersion = $in->getString();
184 $this->playerActorProperties = new CacheableNbt($in->getNbtCompoundRoot());
185 $this->blockPaletteChecksum = $in->getLLong();
186 $this->worldTemplateId = $in->getUUID();
187 $this->enableClientSideChunkGeneration = $in->getBool();
188 $this->blockNetworkIdsAreHashes = $in->getBool();
189 $this->networkPermissions = NetworkPermissions::decode($in);
190 }
191
192 protected function encodePayload(PacketSerializer $out) : void{
193 $out->putActorUniqueId($this->actorUniqueId);
194 $out->putActorRuntimeId($this->actorRuntimeId);
195 $out->putVarInt($this->playerGamemode);
196
197 $out->putVector3($this->playerPosition);
198
199 $out->putLFloat($this->pitch);
200 $out->putLFloat($this->yaw);
201
202 $this->levelSettings->write($out);
203
204 $out->putString($this->levelId);
205 $out->putString($this->worldName);
206 $out->putString($this->premiumWorldTemplateId);
207 $out->putBool($this->isTrial);
208 $this->playerMovementSettings->write($out);
209 $out->putLLong($this->currentTick);
210
211 $out->putVarInt($this->enchantmentSeed);
212
213 $out->putUnsignedVarInt(count($this->blockPalette));
214 foreach($this->blockPalette as $entry){
215 $out->putString($entry->getName());
216 $out->put($entry->getStates()->getEncodedNbt());
217 }
218
219 $out->putUnsignedVarInt(count($this->itemTable));
220 foreach($this->itemTable as $entry){
221 $out->putString($entry->getStringId());
222 $out->putLShort($entry->getNumericId());
223 $out->putBool($entry->isComponentBased());
224 }
225
226 $out->putString($this->multiplayerCorrelationId);
227 $out->putBool($this->enableNewInventorySystem);
228 $out->putString($this->serverSoftwareVersion);
229 $out->put($this->playerActorProperties->getEncodedNbt());
230 $out->putLLong($this->blockPaletteChecksum);
231 $out->putUUID($this->worldTemplateId);
232 $out->putBool($this->enableClientSideChunkGeneration);
233 $out->putBool($this->blockNetworkIdsAreHashes);
234 $this->networkPermissions->encode($out);
235 }
236
237 public function handle(PacketHandlerInterface $handler) : bool{
238 return $handler->handleStartGame($this);
239 }
240}
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, array $blockPalette, int $blockPaletteChecksum, array $itemTable,)