PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\Byte;
18use pmmp\encoding\ByteBufferReader;
19use pmmp\encoding\ByteBufferWriter;
20use pmmp\encoding\DataDecodeException;
21use pmmp\encoding\LE;
22use pmmp\encoding\VarInt;
26
27final class LevelSettings{
28
29 public int $seed;
30 public SpawnSettings $spawnSettings;
31 public int $generator = GeneratorType::OVERWORLD;
32 public int $worldGamemode;
33 public bool $hardcore = false;
34 public int $difficulty;
35 public BlockPosition $spawnPosition;
36 public bool $hasAchievementsDisabled = true;
37 public int $editorWorldType = EditorWorldType::NON_EDITOR;
38 public bool $createdInEditorMode = false;
39 public bool $exportedFromEditorMode = false;
40 public int $time = -1;
41 public int $eduEditionOffer = EducationEditionOffer::NONE;
42 public bool $hasEduFeaturesEnabled = false;
43 public string $eduProductUUID = "";
44 public float $rainLevel;
45 public float $lightningLevel;
46 public bool $hasConfirmedPlatformLockedContent = false;
47 public bool $isMultiplayerGame = true;
48 public bool $hasLANBroadcast = true;
49 public int $xboxLiveBroadcastMode = MultiplayerGameVisibility::PUBLIC;
50 public int $platformBroadcastMode = MultiplayerGameVisibility::PUBLIC;
51 public bool $commandsEnabled;
52 public bool $isTexturePacksRequired = true;
57 public array $gameRules = [];
58 public Experiments $experiments;
59 public bool $hasBonusChestEnabled = false;
60 public bool $hasStartWithMapEnabled = false;
61 public int $defaultPlayerPermission = PlayerPermissions::MEMBER; //TODO
62
63 public int $serverChunkTickRadius = 4; //TODO (leave as default for now)
64
65 public bool $hasLockedBehaviorPack = false;
66 public bool $hasLockedResourcePack = false;
67 public bool $isFromLockedWorldTemplate = false;
68 public bool $useMsaGamertagsOnly = false;
69 public bool $isFromWorldTemplate = false;
70 public bool $isWorldTemplateOptionLocked = false;
71 public bool $onlySpawnV1Villagers = false;
72 public bool $disablePersona = false;
73 public bool $disableCustomSkins = false;
74 public bool $muteEmoteAnnouncements = false;
75 public string $vanillaVersion = ProtocolInfo::MINECRAFT_VERSION_NETWORK;
76 public int $limitedWorldWidth = 0;
77 public int $limitedWorldLength = 0;
78 public bool $isNewNether = true;
79 public ?EducationUriResource $eduSharedUriResource = null;
80 public ?bool $experimentalGameplayOverride = null;
81 public int $chatRestrictionLevel = ChatRestrictionLevel::NONE;
82 public bool $disablePlayerInteractions = false;
83
84 public string $serverIdentifier = "";
85 public string $worldIdentifier = "";
86 public string $scenarioIdentifier = "";
87 public string $ownerIdentifier = "";
88
93 public static function read(ByteBufferReader $in) : self{
94 //TODO: in the future we'll use promoted properties + named arguments for decoding, but for now we stick with
95 //this shitty way to limit BC breaks (needs more R&D)
96 $result = new self;
97 $result->internalRead($in);
98 return $result;
99 }
100
105 private function internalRead(ByteBufferReader $in) : void{
106 $this->seed = LE::readUnsignedLong($in);
107 $this->spawnSettings = SpawnSettings::read($in);
108 $this->generator = VarInt::readSignedInt($in);
109 $this->worldGamemode = VarInt::readSignedInt($in);
110 $this->hardcore = CommonTypes::getBool($in);
111 $this->difficulty = VarInt::readSignedInt($in);
112 $this->spawnPosition = CommonTypes::getBlockPosition($in);
113 $this->hasAchievementsDisabled = CommonTypes::getBool($in);
114 $this->editorWorldType = VarInt::readSignedInt($in);
115 $this->createdInEditorMode = CommonTypes::getBool($in);
116 $this->exportedFromEditorMode = CommonTypes::getBool($in);
117 $this->time = VarInt::readSignedInt($in);
118 $this->eduEditionOffer = VarInt::readSignedInt($in);
119 $this->hasEduFeaturesEnabled = CommonTypes::getBool($in);
120 $this->eduProductUUID = CommonTypes::getString($in);
121 $this->rainLevel = LE::readFloat($in);
122 $this->lightningLevel = LE::readFloat($in);
123 $this->hasConfirmedPlatformLockedContent = CommonTypes::getBool($in);
124 $this->isMultiplayerGame = CommonTypes::getBool($in);
125 $this->hasLANBroadcast = CommonTypes::getBool($in);
126 $this->xboxLiveBroadcastMode = VarInt::readSignedInt($in);
127 $this->platformBroadcastMode = VarInt::readSignedInt($in);
128 $this->commandsEnabled = CommonTypes::getBool($in);
129 $this->isTexturePacksRequired = CommonTypes::getBool($in);
130 $this->gameRules = CommonTypes::getGameRules($in, true);
131 $this->experiments = Experiments::read($in);
132 $this->hasBonusChestEnabled = CommonTypes::getBool($in);
133 $this->hasStartWithMapEnabled = CommonTypes::getBool($in);
134 $this->defaultPlayerPermission = VarInt::readSignedInt($in);
135 $this->serverChunkTickRadius = LE::readSignedInt($in); //doesn't make sense for this to be signed, but that's what the spec says
136 $this->hasLockedBehaviorPack = CommonTypes::getBool($in);
137 $this->hasLockedResourcePack = CommonTypes::getBool($in);
138 $this->isFromLockedWorldTemplate = CommonTypes::getBool($in);
139 $this->useMsaGamertagsOnly = CommonTypes::getBool($in);
140 $this->isFromWorldTemplate = CommonTypes::getBool($in);
141 $this->isWorldTemplateOptionLocked = CommonTypes::getBool($in);
142 $this->onlySpawnV1Villagers = CommonTypes::getBool($in);
143 $this->disablePersona = CommonTypes::getBool($in);
144 $this->disableCustomSkins = CommonTypes::getBool($in);
145 $this->muteEmoteAnnouncements = CommonTypes::getBool($in);
146 $this->vanillaVersion = CommonTypes::getString($in);
147 $this->limitedWorldWidth = LE::readSignedInt($in); //doesn't make sense for this to be signed, but that's what the spec says
148 $this->limitedWorldLength = LE::readSignedInt($in); //same as above
149 $this->isNewNether = CommonTypes::getBool($in);
150 $this->eduSharedUriResource = EducationUriResource::read($in);
151 $this->experimentalGameplayOverride = CommonTypes::readOptional($in, CommonTypes::getBool(...));
152 $this->chatRestrictionLevel = Byte::readUnsigned($in);
153 $this->disablePlayerInteractions = CommonTypes::getBool($in);
154 $this->serverIdentifier = CommonTypes::getString($in);
155 $this->worldIdentifier = CommonTypes::getString($in);
156 $this->scenarioIdentifier = CommonTypes::getString($in);
157 $this->ownerIdentifier = CommonTypes::getString($in);
158 }
159
160 public function write(ByteBufferWriter $out) : void{
161 LE::writeUnsignedLong($out, $this->seed);
162 $this->spawnSettings->write($out);
163 VarInt::writeSignedInt($out, $this->generator);
164 VarInt::writeSignedInt($out, $this->worldGamemode);
165 CommonTypes::putBool($out, $this->hardcore);
166 VarInt::writeSignedInt($out, $this->difficulty);
167 CommonTypes::putBlockPosition($out, $this->spawnPosition);
168 CommonTypes::putBool($out, $this->hasAchievementsDisabled);
169 VarInt::writeSignedInt($out, $this->editorWorldType);
170 CommonTypes::putBool($out, $this->createdInEditorMode);
171 CommonTypes::putBool($out, $this->exportedFromEditorMode);
172 VarInt::writeSignedInt($out, $this->time);
173 VarInt::writeSignedInt($out, $this->eduEditionOffer);
174 CommonTypes::putBool($out, $this->hasEduFeaturesEnabled);
175 CommonTypes::putString($out, $this->eduProductUUID);
176 LE::writeFloat($out, $this->rainLevel);
177 LE::writeFloat($out, $this->lightningLevel);
178 CommonTypes::putBool($out, $this->hasConfirmedPlatformLockedContent);
179 CommonTypes::putBool($out, $this->isMultiplayerGame);
180 CommonTypes::putBool($out, $this->hasLANBroadcast);
181 VarInt::writeSignedInt($out, $this->xboxLiveBroadcastMode);
182 VarInt::writeSignedInt($out, $this->platformBroadcastMode);
183 CommonTypes::putBool($out, $this->commandsEnabled);
184 CommonTypes::putBool($out, $this->isTexturePacksRequired);
185 CommonTypes::putGameRules($out, $this->gameRules, true);
186 $this->experiments->write($out);
187 CommonTypes::putBool($out, $this->hasBonusChestEnabled);
188 CommonTypes::putBool($out, $this->hasStartWithMapEnabled);
189 VarInt::writeSignedInt($out, $this->defaultPlayerPermission);
190 LE::writeSignedInt($out, $this->serverChunkTickRadius); //doesn't make sense for this to be signed, but that's what the spec says
191 CommonTypes::putBool($out, $this->hasLockedBehaviorPack);
192 CommonTypes::putBool($out, $this->hasLockedResourcePack);
193 CommonTypes::putBool($out, $this->isFromLockedWorldTemplate);
194 CommonTypes::putBool($out, $this->useMsaGamertagsOnly);
195 CommonTypes::putBool($out, $this->isFromWorldTemplate);
196 CommonTypes::putBool($out, $this->isWorldTemplateOptionLocked);
197 CommonTypes::putBool($out, $this->onlySpawnV1Villagers);
198 CommonTypes::putBool($out, $this->disablePersona);
199 CommonTypes::putBool($out, $this->disableCustomSkins);
200 CommonTypes::putBool($out, $this->muteEmoteAnnouncements);
201 CommonTypes::putString($out, $this->vanillaVersion);
202 LE::writeSignedInt($out, $this->limitedWorldWidth); //doesn't make sense for this to be signed, but that's what the spec says
203 LE::writeSignedInt($out, $this->limitedWorldLength); //same as above
204 CommonTypes::putBool($out, $this->isNewNether);
205 ($this->eduSharedUriResource ?? new EducationUriResource("", ""))->write($out);
206 CommonTypes::writeOptional($out, $this->experimentalGameplayOverride, CommonTypes::putBool(...));
207 Byte::writeUnsigned($out, $this->chatRestrictionLevel);
208 CommonTypes::putBool($out, $this->disablePlayerInteractions);
209 CommonTypes::putString($out, $this->serverIdentifier);
210 CommonTypes::putString($out, $this->worldIdentifier);
211 CommonTypes::putString($out, $this->scenarioIdentifier);
212 CommonTypes::putString($out, $this->ownerIdentifier);
213 }
214}