From ae68c3bab49332e8f587ff99b524bf9993a4ffeb Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 25 May 2019 19:51:28 +0200 Subject: [PATCH] Add quirk for stone_slab rename The old stone_slab block from pre-1.14 has been renamed to smooth_stone_slab, and the name stone_slab was reused for a new block. Resolve the palette entry depending on the chunk's dataVersion. --- src/Resource/LegacyBlockType.inc | 4 ++-- src/World/Chunk.cpp | 6 +++++- src/World/Section.cpp | 16 ++++++++++++---- src/World/Section.hpp | 7 +++++-- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Resource/LegacyBlockType.inc b/src/Resource/LegacyBlockType.inc index 1bf3b2b..b1dcdff 100644 --- a/src/Resource/LegacyBlockType.inc +++ b/src/Resource/LegacyBlockType.inc @@ -143,7 +143,7 @@ /* 41 */ simple("gold_block"), /* 42 */ simple("iron_block"), /* 43 */ { - "stone_slab", + "smooth_stone_slab", "sandstone_slab", "oak_slab", "cobblestone_slab", @@ -153,7 +153,7 @@ "quartz_slab", }, /* 44 */ { - "stone_slab", + "smooth_stone_slab", "sandstone_slab", "oak_slab", "cobblestone_slab", diff --git a/src/World/Chunk.cpp b/src/World/Chunk.cpp index 7aea1f3..dfc46db 100644 --- a/src/World/Chunk.cpp +++ b/src/World/Chunk.cpp @@ -25,6 +25,7 @@ #include "Chunk.hpp" +#include "../NBT/IntTag.hpp" #include "../NBT/ListTag.hpp" #include "../NBT/StringTag.hpp" @@ -51,9 +52,12 @@ Chunk::Chunk(const ChunkData *data) { else if (biomeInts && biomeInts->getLength() != SIZE*SIZE) throw std::invalid_argument("corrupt biome data"); + auto dataVersionTag = data->getRoot().get("DataVersion"); + uint32_t dataVersion = dataVersionTag ? dataVersionTag->getValue() : 0; + for (auto &sTag : *sectionsTag) { auto s = std::dynamic_pointer_cast(sTag); - std::unique_ptr
section = Section::makeSection(s); + std::unique_ptr
section = Section::makeSection(s, dataVersion); size_t Y = section->getY(); sections.resize(Y); sections.push_back(std::move(section)); diff --git a/src/World/Section.cpp b/src/World/Section.cpp index aa13bc8..aac2b11 100644 --- a/src/World/Section.cpp +++ b/src/World/Section.cpp @@ -44,12 +44,12 @@ const Resource::BlockType * Section::getBlockStateAt(size_t, size_t, size_t) con return nullptr; } -std::unique_ptr
Section::makeSection(const std::shared_ptr §ion) { +std::unique_ptr
Section::makeSection(const std::shared_ptr §ion, uint32_t dataVersion) { std::shared_ptr blockStates = section->get("BlockStates"); if (blockStates) { const std::shared_ptr palette = assertValue(section->get("Palette")); - return std::unique_ptr
(new PaletteSection(section, std::move(blockStates), palette)); + return std::unique_ptr
(new PaletteSection(section, std::move(blockStates), palette, dataVersion)); } std::shared_ptr blocks = section->get("Blocks"); @@ -71,10 +71,18 @@ const Resource::BlockType * LegacySection::getBlockStateAt(size_t x, size_t y, s } +const Resource::BlockType * PaletteSection::lookup(const std::string &name, uint32_t dataVersion) { + if (dataVersion < 1900 && name == "minecraft:stone_slab") + return Resource::BlockType::lookup("minecraft:smooth_stone_slab"); + + return Resource::BlockType::lookup(name); +} + PaletteSection::PaletteSection( const std::shared_ptr §ion, std::shared_ptr &&blockStates0, - const std::shared_ptr &paletteData + const std::shared_ptr &paletteData, + uint32_t dataVersion ) : Section(section), blockStates(blockStates0) { if (blockStates->getLength() % 64) throw std::invalid_argument("corrupt section data"); @@ -90,7 +98,7 @@ PaletteSection::PaletteSection( const NBT::CompoundTag &paletteEntry = *assertValue(dynamic_cast(entry.get())); std::string name = assertValue(paletteEntry.get("Name"))->getValue(); - const Resource::BlockType *type = Resource::BlockType::lookup(name); + const Resource::BlockType *type = lookup(name, dataVersion); if (!type) std::fprintf(stderr, "Warning: unknown block type: %s\n", name.c_str()); diff --git a/src/World/Section.hpp b/src/World/Section.hpp index e5f71f4..4ba1c89 100644 --- a/src/World/Section.hpp +++ b/src/World/Section.hpp @@ -81,7 +81,7 @@ public: return getHalf(blockLight->getValue(), x, y, z); } - static std::unique_ptr
makeSection(const std::shared_ptr §ion); + static std::unique_ptr
makeSection(const std::shared_ptr §ion, uint32_t dataVersion); }; class LegacySection : public Section { @@ -116,6 +116,8 @@ private: uint16_t mask; + static const Resource::BlockType * lookup(const std::string &name, uint32_t dataVersion); + static size_t mangleByteIndex(size_t index) { return (index & ~(size_t)7) + 7 - (index & 7); } @@ -124,7 +126,8 @@ public: PaletteSection( const std::shared_ptr §ion, std::shared_ptr &&blockStates0, - const std::shared_ptr &paletteData + const std::shared_ptr &paletteData, + uint32_t dataVersion ); virtual const Resource::BlockType * getBlockStateAt(size_t x, size_t y, size_t z) const;