Section: allow empty sections

This commit is contained in:
Matthias Schiffer 2019-05-25 16:56:25 +02:00
parent 212a8dcaea
commit 3c92f58110
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 13 additions and 6 deletions

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net> Copyright (c) 2015-2019, Matthias Schiffer <mschiffer@universe-factory.net>
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
@ -40,6 +40,9 @@ Section::Section(const std::shared_ptr<const NBT::CompoundTag> &section) {
blockLight = section->get<NBT::ByteArrayTag>("BlockLight"); blockLight = section->get<NBT::ByteArrayTag>("BlockLight");
} }
const Resource::BlockType * Section::getBlockStateAt(size_t, size_t, size_t) const {
return nullptr;
}
std::unique_ptr<Section> Section::makeSection(const std::shared_ptr<const NBT::CompoundTag> &section) { std::unique_ptr<Section> Section::makeSection(const std::shared_ptr<const NBT::CompoundTag> &section) {
std::shared_ptr<const NBT::LongArrayTag> blockStates = section->get<NBT::LongArrayTag>("BlockStates"); std::shared_ptr<const NBT::LongArrayTag> blockStates = section->get<NBT::LongArrayTag>("BlockStates");
@ -49,10 +52,14 @@ 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>("Blocks");
std::shared_ptr<const NBT::ByteArrayTag> data = assertValue(section->get<NBT::ByteArrayTag>("Data")); if (blocks) {
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 std::unique_ptr<Section>(new Section(section));
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 2015-2018, Matthias Schiffer <mschiffer@universe-factory.net> Copyright (c) 2015-2019, Matthias Schiffer <mschiffer@universe-factory.net>
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
@ -72,7 +72,7 @@ public:
size_t getY() const { return Y; }; size_t getY() const { return Y; };
virtual const Resource::BlockType * getBlockStateAt(size_t x, size_t y, size_t z) const = 0; virtual const Resource::BlockType * getBlockStateAt(size_t x, size_t y, size_t z) const;
uint8_t getBlockLightAt(size_t x, size_t y, size_t z) const { uint8_t getBlockLightAt(size_t x, size_t y, size_t z) const {
if (!blockLight) if (!blockLight)