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