World: ChunkData: make getRoot() return shared pointer reference

This commit is contained in:
Matthias Schiffer 2021-12-03 23:54:15 +01:00
parent 16a1258f08
commit 21966252ea
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
3 changed files with 5 additions and 5 deletions

View file

@ -19,7 +19,7 @@ namespace World {
Chunk::Chunk(const ChunkData *data) {
std::shared_ptr<const NBT::CompoundTag> level =
assertValue(data->getRoot().get<NBT::CompoundTag>("Level"));
assertValue(data->getRoot()->get<NBT::CompoundTag>("Level"));
std::shared_ptr<const NBT::ListTag> sectionsTag = level->get<NBT::ListTag>("Sections");
if (!sectionsTag || sectionsTag->empty())
@ -37,7 +37,7 @@ Chunk::Chunk(const ChunkData *data) {
else
throw std::invalid_argument("corrupt biome data");
auto dataVersionTag = data->getRoot().get<NBT::IntTag>("DataVersion");
auto dataVersionTag = data->getRoot()->get<NBT::IntTag>("DataVersion");
uint32_t dataVersion = dataVersionTag ? dataVersionTag->getValue() : 0;
for (auto &sTag : *sectionsTag) {

View file

@ -32,8 +32,8 @@ private:
public:
ChunkData(Buffer buffer);
const NBT::CompoundTag & getRoot() const {
return *root;
const std::shared_ptr<const NBT::CompoundTag> & getRoot() const {
return root;
}
};

View file

@ -25,7 +25,7 @@ int main(int argc, char *argv[]) {
World::Region::visitChunks(argv[1], [&] (chunk_idx_t X, chunk_idx_t Z, const World::ChunkData *chunk) {
std::cout << "Chunk(" << X << ", " << Z << "): "
<< chunk->getRoot() << std::endl;
<< *chunk->getRoot() << std::endl;
});
return 0;