Ignore chunks without sections

This commit is contained in:
Roman Shishkin 2019-05-16 20:16:27 +03:00
parent 02010d1a0d
commit e6348ac5a2

View file

@ -43,15 +43,6 @@ Chunk::Chunk(const ChunkData *data) {
if (!sectionsTag) if (!sectionsTag)
return; return;
biomeBytes = level->get<NBT::ByteArrayTag>("Biomes");
biomeInts = level->get<NBT::IntArrayTag>("Biomes");
assertValue(biomeBytes || biomeInts);
if (biomeBytes && biomeBytes->getLength() != SIZE*SIZE)
throw std::invalid_argument("corrupt biome data");
else if (biomeInts && biomeInts->getLength() != SIZE*SIZE)
throw std::invalid_argument("corrupt biome data");
for (auto &sTag : *sectionsTag) { for (auto &sTag : *sectionsTag) {
auto s = std::dynamic_pointer_cast<const NBT::CompoundTag>(sTag); auto s = std::dynamic_pointer_cast<const NBT::CompoundTag>(sTag);
std::unique_ptr<Section> section = Section::makeSection(s); std::unique_ptr<Section> section = Section::makeSection(s);
@ -61,6 +52,17 @@ Chunk::Chunk(const ChunkData *data) {
sections.push_back(std::move(section)); sections.push_back(std::move(section));
} }
} }
if (!sections.empty()) {
biomeBytes = level->get<NBT::ByteArrayTag>("Biomes");
biomeInts = level->get<NBT::IntArrayTag>("Biomes");
assertValue(biomeBytes || biomeInts);
if (biomeBytes && biomeBytes->getLength() != SIZE*SIZE)
throw std::invalid_argument("corrupt biome data");
else if (biomeInts && biomeInts->getLength() != SIZE*SIZE)
throw std::invalid_argument("corrupt biome data");
}
} }
bool Chunk::getBlock(Block *block, const Section *section, size_t x, size_t y, size_t z, uint8_t prev_light) const { bool Chunk::getBlock(Block *block, const Section *section, size_t x, size_t y, size_t z, uint8_t prev_light) const {