Writes a level to a given NBT compound tag.
163 {
164 auto &root = options.output;
165
166
167 auto environment = nbt::tag_compound();
168
169 const auto cloudColor = l->getPropertyOr("CloudColor", 0xFFFFFF);
170 const auto cloudHeight = l->getPropertyOr("CloudHeight", static_cast<int16_t>(66));
171 const auto fogColor = l->getPropertyOr("FogColor", 0xFFFFFF);
172 const auto skyBrightness = l->getPropertyOr("SkyBrightness", static_cast<int8_t>(0xF));
173 const auto skyColor = l->getPropertyOr("SkyColor", 0x99CCFF);
174 const auto surroundingGroundHeight = l->getPropertyOr("SurroundingGroundHeight", static_cast<int16_t>(2));
175 const auto surroundingGroundType = l->getPropertyOr("SurroundingGroundType", static_cast<int8_t>(2));
176 const auto surroundingWaterHeight = l->getPropertyOr("SurroundingWaterHeight", static_cast<int16_t>(32));
177 const auto surroundingWaterType = l->getPropertyOr("SurroundingWaterType", static_cast<int8_t>(8));
178 const auto timeOfDay = l->getPropertyOr("TimeOfDay", static_cast<int16_t>(16));
179 environment["CloudColor"] = cloudColor->getValue();
180 environment["CloudHeight"] = cloudHeight->getValue();
181 environment["FogColor"] = fogColor->getValue();
182 environment["SkyBrightness"] = skyBrightness->getValue();
183 environment["SkyColor"] = skyColor->getValue();
184 environment["SurroundingGroundHeight"] = surroundingGroundHeight->getValue();
185 environment["SurroundingGroundType"] = surroundingGroundType->getValue();
186 environment["SurroundingWaterHeight"] = surroundingWaterHeight->getValue();
187 environment["SurroundingWaterType"] = surroundingWaterType->getValue();
188 environment["TimeOfDay"] = timeOfDay->getValue();
189
190
191 auto map = nbt::tag_compound();
192
193 const auto spawnPos = l->getSpawnPos();
194 const auto spawn = nbt::tag_list({
195 static_cast<int16_t>(spawnPos.x),
196 static_cast<int16_t>(spawnPos.y),
197 static_cast<int16_t>(spawnPos.z)
198 });
199 map.emplace<nbt::tag_list>("Spawn", spawn);
200
201 const auto levelBounds = l->getBlockBounds();
202 const auto height = levelBounds.getHeight();
203 const auto width = levelBounds.getWidth();
204 const auto length = levelBounds.getLength();
205 map["Height"] = nbt::tag_short(height);
206 map["Width"] = nbt::tag_short(width);
207 map["Length"] = nbt::tag_short(length);
208
209 auto blocks = std::vector<int8_t>(height * width * length);
210 auto metadata = std::vector<int8_t>(height * width * length);
211
212 const std::unique_ptr<conversion::block::version::BlockIO> bio =
214
215 for (int y = 0; y < height; y++) {
216 for (int z = 0; z < length; z++) {
217 for (int x = 0; x < width; x++) {
218 const size_t idx =
INDEX_YZX(x, y, z, width, length);
219
220 const auto bb = l->getBlock(x, y, z);
221
223 uint8_t blockId = 0;
224 uint8_t data = 0;
225
226 if (const conversion::block::data::NumericBlockData *bl =
227 bio->convertBlockFromInternal(&bb)->as<conversion::block::data::NumericBlockData>()) {
228 blockId = bl->getId();
229 data = bl->getData();
230 }
231
232 blocks[idx] = blockId;
233 metadata[idx] = data;
234 }
235 }
236 }
237 }
238
239 map["Blocks"] = nbt::tag_byte_array(std::move(blocks));
240 map["Data"] = nbt::tag_byte_array(std::move(metadata));
241
242
243 auto about = nbt::tag_compound();
244
245 const auto author = l->getPropertyOr("Author", "Player");
246 const auto createdOn = l->getPropertyOr("CreatedOn", static_cast<int64_t>(0L));
247 const auto name = l->getPropertyOr("Name", "A Nice World");
248 about["Author"] = author->getValue();
249 about["CreatedOn"] = createdOn->getValue();
250 about["Name"] = name->getValue();
251
252
253 auto entities = nbt::tag_list(nbt::tag_type::Compound);
254
255
256 auto tileEntities = nbt::tag_list(nbt::tag_type::Compound);
257
258 root.emplace<nbt::tag_compound>("Environment", environment);
259 root.emplace<nbt::tag_compound>("Map", map);
260 root.emplace<nbt::tag_compound>("About", about);
261 root.emplace<nbt::tag_list>("Entities", entities);
262 root.emplace<nbt::tag_list>("TileEntities", tileEntities);
263 }