From a2fe33ef1f7a3b405066a14c69cc1a340a763a7f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 12 Dec 2021 12:15:31 +0100 Subject: [PATCH] World: Section: add support for Int tag section Y values For some reason, MC1.18 sometimes uses Int instead of Byte tags for section Y values after "optimize world". Add support for this (but still only accept values that fit in a int8_t). --- src/World/Section.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/World/Section.cpp b/src/World/Section.cpp index ffa2789..ba7b0c9 100644 --- a/src/World/Section.cpp +++ b/src/World/Section.cpp @@ -8,6 +8,7 @@ #include "Section.hpp" #include "../Resource/Biome.hpp" #include "../NBT/ByteTag.hpp" +#include "../NBT/IntTag.hpp" #include "../NBT/StringTag.hpp" #include @@ -17,7 +18,16 @@ namespace MinedMap { namespace World { Section::Section(const std::shared_ptr §ion) { - Y = int8_t(assertValue(section->get("Y"))->getValue()); + const std::shared_ptr YByteTag = section->get("Y"); + if (YByteTag) { + Y = int8_t(YByteTag->getValue()); + } else { + const std::shared_ptr YIntTag = assertValue(section->get("Y")); + int32_t value = YIntTag->getValue(); + if (int8_t(value) != value) + throw std::invalid_argument("unsupported section Y coordinate"); + Y = value; + } blockLight = section->get("BlockLight"); }