PocketMine-MP 5.39.3 git-66148f13a91e4af6778ba9f200ca25ad8a04a584
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 NetworkPermissions $networkPermissions;
63
68 public array $blockPalette = [];
69
76
83 public static function create(
84 int $actorUniqueId,
85 int $actorRuntimeId,
86 int $playerGamemode,
87 Vector3 $playerPosition,
88 float $pitch,
89 float $yaw,
91 LevelSettings $levelSettings,
92 string $levelId,
93 string $worldName,
94 string $premiumWorldTemplateId,
95 bool $isTrial,
96 PlayerMovementSettings $playerMovementSettings,
97 int $currentTick,
98 int $enchantmentSeed,
99 string $multiplayerCorrelationId,
100 bool $enableNewInventorySystem,
101 string $serverSoftwareVersion,
102 UuidInterface $worldTemplateId,
103 bool $enableClientSideChunkGeneration,
104 bool $blockNetworkIdsAreHashes,
105 NetworkPermissions $networkPermissions,
106 array $blockPalette,
108 ) : self{
109 $result = new self;
110 $result->actorUniqueId = $actorUniqueId;
111 $result->actorRuntimeId = $actorRuntimeId;
112 $result->playerGamemode = $playerGamemode;
113 $result->playerPosition = $playerPosition;
114 $result->pitch = $pitch;
115 $result->yaw = $yaw;
116 $result->playerActorProperties = $playerActorProperties;
117 $result->levelSettings = $levelSettings;
118 $result->levelId = $levelId;
119 $result->worldName = $worldName;
120 $result->premiumWorldTemplateId = $premiumWorldTemplateId;
121 $result->isTrial = $isTrial;
122 $result->playerMovementSettings = $playerMovementSettings;
123 $result->currentTick = $currentTick;
124 $result->enchantmentSeed = $enchantmentSeed;
125 $result->multiplayerCorrelationId = $multiplayerCorrelationId;
126 $result->enableNewInventorySystem = $enableNewInventorySystem;
127 $result->serverSoftwareVersion = $serverSoftwareVersion;
128 $result->worldTemplateId = $worldTemplateId;
129 $result->enableClientSideChunkGeneration = $enableClientSideChunkGeneration;
130 $result->blockNetworkIdsAreHashes = $blockNetworkIdsAreHashes;
131 $result->networkPermissions = $networkPermissions;
132 $result->blockPalette = $blockPalette;
133 $result->blockPaletteChecksum = $blockPaletteChecksum;
134 return $result;
135 }
136
137 protected function decodePayload(ByteBufferReader $in) : void{
138 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
139 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
140 $this->playerGamemode = VarInt::readSignedInt($in);
141
142 $this->playerPosition = CommonTypes::getVector3($in);
143
144 $this->pitch = LE::readFloat($in);
145 $this->yaw = LE::readFloat($in);
146
147 $this->levelSettings = LevelSettings::read($in);
148
149 $this->levelId = CommonTypes::getString($in);
150 $this->worldName = CommonTypes::getString($in);
151 $this->premiumWorldTemplateId = CommonTypes::getString($in);
152 $this->isTrial = CommonTypes::getBool($in);
153 $this->playerMovementSettings = PlayerMovementSettings::read($in);
154 $this->currentTick = LE::readUnsignedLong($in);
155
156 $this->enchantmentSeed = VarInt::readSignedInt($in);
157
158 $this->blockPalette = [];
159 for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
160 $blockName = CommonTypes::getString($in);
161 $state = CommonTypes::getNbtCompoundRoot($in);
162 $this->blockPalette[] = new BlockPaletteEntry($blockName, new CacheableNbt($state));
163 }
164
165 $this->multiplayerCorrelationId = CommonTypes::getString($in);
166 $this->enableNewInventorySystem = CommonTypes::getBool($in);
167 $this->serverSoftwareVersion = CommonTypes::getString($in);
168 $this->playerActorProperties = new CacheableNbt(CommonTypes::getNbtCompoundRoot($in));
169 $this->blockPaletteChecksum = LE::readUnsignedLong($in);
170 $this->worldTemplateId = CommonTypes::getUUID($in);
171 $this->enableClientSideChunkGeneration = CommonTypes::getBool($in);
172 $this->blockNetworkIdsAreHashes = CommonTypes::getBool($in);
173 $this->networkPermissions = NetworkPermissions::decode($in);
174 }
175
176 protected function encodePayload(ByteBufferWriter $out) : void{
177 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
178 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
179 VarInt::writeSignedInt($out, $this->playerGamemode);
180
181 CommonTypes::putVector3($out, $this->playerPosition);
182
183 LE::writeFloat($out, $this->pitch);
184 LE::writeFloat($out, $this->yaw);
185
186 $this->levelSettings->write($out);
187
188 CommonTypes::putString($out, $this->levelId);
189 CommonTypes::putString($out, $this->worldName);
190 CommonTypes::putString($out, $this->premiumWorldTemplateId);
191 CommonTypes::putBool($out, $this->isTrial);
192 $this->playerMovementSettings->write($out);
193 LE::writeUnsignedLong($out, $this->currentTick);
194
195 VarInt::writeSignedInt($out, $this->enchantmentSeed);
196
197 VarInt::writeUnsignedInt($out, count($this->blockPalette));
198 foreach($this->blockPalette as $entry){
199 CommonTypes::putString($out, $entry->getName());
200 $out->writeByteArray($entry->getStates()->getEncodedNbt());
201 }
202
203 CommonTypes::putString($out, $this->multiplayerCorrelationId);
204 CommonTypes::putBool($out, $this->enableNewInventorySystem);
205 CommonTypes::putString($out, $this->serverSoftwareVersion);
206 $out->writeByteArray($this->playerActorProperties->getEncodedNbt());
207 LE::writeUnsignedLong($out, $this->blockPaletteChecksum);
208 CommonTypes::putUUID($out, $this->worldTemplateId);
209 CommonTypes::putBool($out, $this->enableClientSideChunkGeneration);
210 CommonTypes::putBool($out, $this->blockNetworkIdsAreHashes);
211 $this->networkPermissions->encode($out);
212 }
213
214 public function handle(PacketHandlerInterface $handler) : bool{
215 return $handler->handleStartGame($this);
216 }
217}
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,)