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