summaryrefslogtreecommitdiffstats
path: root/src/World
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-09-19 16:01:41 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-09-19 16:01:41 +0200
commitc80f54cba794c653732e5cba1f329817d332070d (patch)
tree084bc513a023732e18731344fc9e319f2ea221c0 /src/World
parentd677440f6d8487a4eca613803aff0e091dcd71f3 (diff)
downloadMinedMap-c80f54cba794c653732e5cba1f329817d332070d.tar
MinedMap-c80f54cba794c653732e5cba1f329817d332070d.zip
Chunk: allow generating unlighted maps for chunks without light data
Diffstat (limited to 'src/World')
-rw-r--r--src/World/Chunk.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp
index dae66ff..f722655 100644
--- a/src/World/Chunk.cpp
+++ b/src/World/Chunk.cpp
@@ -99,8 +99,7 @@ void Chunk::parseChunk() {
void Chunk::analyzeChunk() {
std::shared_ptr<const NBT::ByteTag> lightPopulatedTag = level->get<NBT::ByteTag>("LightPopulated");
- if (!(lightPopulatedTag && lightPopulatedTag->getValue()))
- throw std::invalid_argument("light data missing");
+ bool lightPopulated = lightPopulatedTag && lightPopulatedTag->getValue();
sections = assertValue(level->get<NBT::ListTag<NBT::CompoundTag>>("Sections"));
maxY = (assertValue(sections->back()->get<NBT::ByteTag>("Y"))->getValue() + 1) * SIZE;
@@ -126,18 +125,24 @@ void Chunk::analyzeChunk() {
for (auto &section : *sections) {
std::shared_ptr<const NBT::ByteArrayTag> blocks = assertValue(section->get<NBT::ByteArrayTag>("Blocks"));
std::shared_ptr<const NBT::ByteArrayTag> data = assertValue(section->get<NBT::ByteArrayTag>("Data"));
- std::shared_ptr<const NBT::ByteArrayTag> blockLight = assertValue(section->get<NBT::ByteArrayTag>("BlockLight"));
- std::shared_ptr<const NBT::ByteArrayTag> skyLight = assertValue(section->get<NBT::ByteArrayTag>("SkyLight"));
size_t Y = assertValue(section->get<NBT::ByteTag>("Y"))->getValue();
- if (blocks->getLength() != SIZE*SIZE*SIZE || data->getLength() != SIZE*SIZE*SIZE/2
- || blockLight->getLength() != SIZE*SIZE*SIZE/2 || skyLight->getLength() != SIZE*SIZE*SIZE/2)
+ if (blocks->getLength() != SIZE*SIZE*SIZE || data->getLength() != SIZE*SIZE*SIZE/2)
throw std::invalid_argument("corrupt chunk data");
+ if (lightPopulated) {
+ std::shared_ptr<const NBT::ByteArrayTag> blockLight = assertValue(section->get<NBT::ByteArrayTag>("BlockLight"));
+ std::shared_ptr<const NBT::ByteArrayTag> skyLight = assertValue(section->get<NBT::ByteArrayTag>("SkyLight"));
+
+ if (blockLight->getLength() != SIZE*SIZE*SIZE/2 || skyLight->getLength() != SIZE*SIZE*SIZE/2)
+ throw std::invalid_argument("corrupt chunk data");
+
+ std::memcpy(blockBlockLight.get() + Y*SIZE*SIZE*SIZE/2, blockLight->getValue(), SIZE*SIZE*SIZE/2);
+ std::memcpy(blockSkyLight.get() + Y*SIZE*SIZE*SIZE/2, skyLight->getValue(), SIZE*SIZE*SIZE/2);
+ }
+
std::memcpy(blockIDs.get() + Y*SIZE*SIZE*SIZE, blocks->getValue(), SIZE*SIZE*SIZE);
std::memcpy(blockData.get() + Y*SIZE*SIZE*SIZE/2, data->getValue(), SIZE*SIZE*SIZE/2);
- std::memcpy(blockBlockLight.get() + Y*SIZE*SIZE*SIZE/2, blockLight->getValue(), SIZE*SIZE*SIZE/2);
- std::memcpy(blockSkyLight.get() + Y*SIZE*SIZE*SIZE/2, skyLight->getValue(), SIZE*SIZE*SIZE/2);
}
}