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