From 3c92f581101b0352c97db6662b26012747614ae1 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 25 May 2019 16:56:25 +0200 Subject: [PATCH] Section: allow empty sections --- src/World/Section.cpp | 15 +++++++++++---- src/World/Section.hpp | 4 ++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/World/Section.cpp b/src/World/Section.cpp index fbf1c33..aa13bc8 100644 --- a/src/World/Section.cpp +++ b/src/World/Section.cpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2015-2018, Matthias Schiffer + Copyright (c) 2015-2019, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without @@ -40,6 +40,9 @@ Section::Section(const std::shared_ptr §ion) { blockLight = section->get("BlockLight"); } +const Resource::BlockType * Section::getBlockStateAt(size_t, size_t, size_t) const { + return nullptr; +} std::unique_ptr
Section::makeSection(const std::shared_ptr §ion) { std::shared_ptr blockStates = section->get("BlockStates"); @@ -49,10 +52,14 @@ std::unique_ptr
Section::makeSection(const std::shared_ptr(new PaletteSection(section, std::move(blockStates), palette)); } - std::shared_ptr blocks = assertValue(section->get("Blocks")); - std::shared_ptr data = assertValue(section->get("Data")); + std::shared_ptr blocks = section->get("Blocks"); + if (blocks) { + std::shared_ptr data = assertValue(section->get("Data")); - return std::unique_ptr
(new LegacySection(section, std::move(blocks), std::move(data))); + return std::unique_ptr
(new LegacySection(section, std::move(blocks), std::move(data))); + } + + return std::unique_ptr
(new Section(section)); } diff --git a/src/World/Section.hpp b/src/World/Section.hpp index 3444bce..e5f71f4 100644 --- a/src/World/Section.hpp +++ b/src/World/Section.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) 2015-2018, Matthias Schiffer + Copyright (c) 2015-2019, Matthias Schiffer All rights reserved. Redistribution and use in source and binary forms, with or without @@ -72,7 +72,7 @@ public: 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 { if (!blockLight)