Don't fall on empty Sections

This commit is contained in:
Roman Shishkin 2019-05-16 19:17:09 +03:00
parent 6719ccdbe1
commit 281603dc5a
3 changed files with 15 additions and 6 deletions

View file

@ -1,5 +1,6 @@
/* /*
Copyright (c) 2015, 2018, Matthias Schiffer <mschiffer@universe-factory.net> Copyright (c) 2015, 2018, Matthias Schiffer <mschiffer@universe-factory.net>
Copyright (c) 2019, Roman Shishkin <spark@uwtech.org>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View file

@ -1,5 +1,6 @@
/* /*
Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net> Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net>
Copyright (c) 2019, Roman Shishkin <spark@uwtech.org>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -54,11 +55,13 @@ Chunk::Chunk(const ChunkData *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);
if (section != nullptr) {
size_t Y = section->getY(); size_t Y = section->getY();
sections.resize(Y); sections.resize(Y);
sections.push_back(std::move(section)); sections.push_back(std::move(section));
} }
} }
}
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 {
if (block->height > 0) if (block->height > 0)

View file

@ -1,5 +1,6 @@
/* /*
Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net> Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net>
Copyright (c) 2019, Roman Shishkin <spark@uwtech.org>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
@ -49,12 +50,16 @@ std::unique_ptr<Section> Section::makeSection(const std::shared_ptr<const NBT::C
return std::unique_ptr<Section>(new PaletteSection(section, std::move(blockStates), palette)); return std::unique_ptr<Section>(new PaletteSection(section, std::move(blockStates), palette));
} }
std::shared_ptr<const NBT::ByteArrayTag> blocks = assertValue(section->get<NBT::ByteArrayTag>("Blocks")); std::shared_ptr<const NBT::ByteArrayTag> blocks = section->get<NBT::ByteArrayTag>("BlockStates");
if (blocks) {
std::shared_ptr<const NBT::ByteArrayTag> data = assertValue(section->get<NBT::ByteArrayTag>("Data")); std::shared_ptr<const NBT::ByteArrayTag> data = assertValue(section->get<NBT::ByteArrayTag>("Data"));
return std::unique_ptr<Section>(new LegacySection(section, std::move(blocks), std::move(data))); return std::unique_ptr<Section>(new LegacySection(section, std::move(blocks), std::move(data)));
} }
return nullptr;
}
const Resource::BlockType * LegacySection::getBlockStateAt(size_t x, size_t y, size_t z) const { const Resource::BlockType * LegacySection::getBlockStateAt(size_t x, size_t y, size_t z) const {
uint8_t type = getBlockAt(x, y, z); uint8_t type = getBlockAt(x, y, z);