PocketMine-MP 5.19.1 git-5cc1068cd43264d3363295eb8d6901e02f467897
LevelSettings.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\types;
16
21
22final class LevelSettings{
23
24 public int $seed;
25 public SpawnSettings $spawnSettings;
26 public int $generator = GeneratorType::OVERWORLD;
27 public int $worldGamemode;
28 public bool $hardcore = false;
29 public int $difficulty;
30 public BlockPosition $spawnPosition;
31 public bool $hasAchievementsDisabled = true;
32 public int $editorWorldType = EditorWorldType::NON_EDITOR;
33 public bool $createdInEditorMode = false;
34 public bool $exportedFromEditorMode = false;
35 public int $time = -1;
36 public int $eduEditionOffer = EducationEditionOffer::NONE;
37 public bool $hasEduFeaturesEnabled = false;
38 public string $eduProductUUID = "";
39 public float $rainLevel;
40 public float $lightningLevel;
41 public bool $hasConfirmedPlatformLockedContent = false;
42 public bool $isMultiplayerGame = true;
43 public bool $hasLANBroadcast = true;
44 public int $xboxLiveBroadcastMode = MultiplayerGameVisibility::PUBLIC;
45 public int $platformBroadcastMode = MultiplayerGameVisibility::PUBLIC;
46 public bool $commandsEnabled;
47 public bool $isTexturePacksRequired = true;
52 public array $gameRules = [];
53 public Experiments $experiments;
54 public bool $hasBonusChestEnabled = false;
55 public bool $hasStartWithMapEnabled = false;
56 public int $defaultPlayerPermission = PlayerPermissions::MEMBER; //TODO
57
58 public int $serverChunkTickRadius = 4; //TODO (leave as default for now)
59
60 public bool $hasLockedBehaviorPack = false;
61 public bool $hasLockedResourcePack = false;
62 public bool $isFromLockedWorldTemplate = false;
63 public bool $useMsaGamertagsOnly = false;
64 public bool $isFromWorldTemplate = false;
65 public bool $isWorldTemplateOptionLocked = false;
66 public bool $onlySpawnV1Villagers = false;
67 public bool $disablePersona = false;
68 public bool $disableCustomSkins = false;
69 public bool $muteEmoteAnnouncements = false;
70 public string $vanillaVersion = ProtocolInfo::MINECRAFT_VERSION_NETWORK;
71 public int $limitedWorldWidth = 0;
72 public int $limitedWorldLength = 0;
73 public bool $isNewNether = true;
74 public ?EducationUriResource $eduSharedUriResource = null;
75 public ?bool $experimentalGameplayOverride = null;
76 public int $chatRestrictionLevel = ChatRestrictionLevel::NONE;
77 public bool $disablePlayerInteractions = false;
78
79 public string $serverIdentifier = "";
80 public string $worldIdentifier = "";
81 public string $scenarioIdentifier = "";
82
87 public static function read(PacketSerializer $in) : self{
88 //TODO: in the future we'll use promoted properties + named arguments for decoding, but for now we stick with
89 //this shitty way to limit BC breaks (needs more R&D)
90 $result = new self;
91 $result->internalRead($in);
92 return $result;
93 }
94
99 private function internalRead(PacketSerializer $in) : void{
100 $this->seed = $in->getLLong();
101 $this->spawnSettings = SpawnSettings::read($in);
102 $this->generator = $in->getVarInt();
103 $this->worldGamemode = $in->getVarInt();
104 $this->hardcore = $in->getBool();
105 $this->difficulty = $in->getVarInt();
106 $this->spawnPosition = $in->getBlockPosition();
107 $this->hasAchievementsDisabled = $in->getBool();
108 $this->editorWorldType = $in->getVarInt();
109 $this->createdInEditorMode = $in->getBool();
110 $this->exportedFromEditorMode = $in->getBool();
111 $this->time = $in->getVarInt();
112 $this->eduEditionOffer = $in->getVarInt();
113 $this->hasEduFeaturesEnabled = $in->getBool();
114 $this->eduProductUUID = $in->getString();
115 $this->rainLevel = $in->getLFloat();
116 $this->lightningLevel = $in->getLFloat();
117 $this->hasConfirmedPlatformLockedContent = $in->getBool();
118 $this->isMultiplayerGame = $in->getBool();
119 $this->hasLANBroadcast = $in->getBool();
120 $this->xboxLiveBroadcastMode = $in->getVarInt();
121 $this->platformBroadcastMode = $in->getVarInt();
122 $this->commandsEnabled = $in->getBool();
123 $this->isTexturePacksRequired = $in->getBool();
124 $this->gameRules = $in->getGameRules();
125 $this->experiments = Experiments::read($in);
126 $this->hasBonusChestEnabled = $in->getBool();
127 $this->hasStartWithMapEnabled = $in->getBool();
128 $this->defaultPlayerPermission = $in->getVarInt();
129 $this->serverChunkTickRadius = $in->getLInt();
130 $this->hasLockedBehaviorPack = $in->getBool();
131 $this->hasLockedResourcePack = $in->getBool();
132 $this->isFromLockedWorldTemplate = $in->getBool();
133 $this->useMsaGamertagsOnly = $in->getBool();
134 $this->isFromWorldTemplate = $in->getBool();
135 $this->isWorldTemplateOptionLocked = $in->getBool();
136 $this->onlySpawnV1Villagers = $in->getBool();
137 $this->disablePersona = $in->getBool();
138 $this->disableCustomSkins = $in->getBool();
139 $this->muteEmoteAnnouncements = $in->getBool();
140 $this->vanillaVersion = $in->getString();
141 $this->limitedWorldWidth = $in->getLInt();
142 $this->limitedWorldLength = $in->getLInt();
143 $this->isNewNether = $in->getBool();
144 $this->eduSharedUriResource = EducationUriResource::read($in);
145 $this->experimentalGameplayOverride = $in->readOptional($in->getBool(...));
146 $this->chatRestrictionLevel = $in->getByte();
147 $this->disablePlayerInteractions = $in->getBool();
148 $this->serverIdentifier = $in->getString();
149 $this->worldIdentifier = $in->getString();
150 $this->scenarioIdentifier = $in->getString();
151 }
152
153 public function write(PacketSerializer $out) : void{
154 $out->putLLong($this->seed);
155 $this->spawnSettings->write($out);
156 $out->putVarInt($this->generator);
157 $out->putVarInt($this->worldGamemode);
158 $out->putBool($this->hardcore);
159 $out->putVarInt($this->difficulty);
160 $out->putBlockPosition($this->spawnPosition);
161 $out->putBool($this->hasAchievementsDisabled);
162 $out->putVarInt($this->editorWorldType);
163 $out->putBool($this->createdInEditorMode);
164 $out->putBool($this->exportedFromEditorMode);
165 $out->putVarInt($this->time);
166 $out->putVarInt($this->eduEditionOffer);
167 $out->putBool($this->hasEduFeaturesEnabled);
168 $out->putString($this->eduProductUUID);
169 $out->putLFloat($this->rainLevel);
170 $out->putLFloat($this->lightningLevel);
171 $out->putBool($this->hasConfirmedPlatformLockedContent);
172 $out->putBool($this->isMultiplayerGame);
173 $out->putBool($this->hasLANBroadcast);
174 $out->putVarInt($this->xboxLiveBroadcastMode);
175 $out->putVarInt($this->platformBroadcastMode);
176 $out->putBool($this->commandsEnabled);
177 $out->putBool($this->isTexturePacksRequired);
178 $out->putGameRules($this->gameRules);
179 $this->experiments->write($out);
180 $out->putBool($this->hasBonusChestEnabled);
181 $out->putBool($this->hasStartWithMapEnabled);
182 $out->putVarInt($this->defaultPlayerPermission);
183 $out->putLInt($this->serverChunkTickRadius);
184 $out->putBool($this->hasLockedBehaviorPack);
185 $out->putBool($this->hasLockedResourcePack);
186 $out->putBool($this->isFromLockedWorldTemplate);
187 $out->putBool($this->useMsaGamertagsOnly);
188 $out->putBool($this->isFromWorldTemplate);
189 $out->putBool($this->isWorldTemplateOptionLocked);
190 $out->putBool($this->onlySpawnV1Villagers);
191 $out->putBool($this->disablePersona);
192 $out->putBool($this->disableCustomSkins);
193 $out->putBool($this->muteEmoteAnnouncements);
194 $out->putString($this->vanillaVersion);
195 $out->putLInt($this->limitedWorldWidth);
196 $out->putLInt($this->limitedWorldLength);
197 $out->putBool($this->isNewNether);
198 ($this->eduSharedUriResource ?? new EducationUriResource("", ""))->write($out);
199 $out->writeOptional($this->experimentalGameplayOverride, $out->putBool(...));
200 $out->putByte($this->chatRestrictionLevel);
201 $out->putBool($this->disablePlayerInteractions);
202 $out->putString($this->serverIdentifier);
203 $out->putString($this->worldIdentifier);
204 $out->putString($this->scenarioIdentifier);
205 }
206}