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).
This commit is contained in:
Matthias Schiffer 2021-12-12 12:15:31 +01:00
parent d18e004743
commit a2fe33ef1f
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C

View file

@ -8,6 +8,7 @@
#include "Section.hpp"
#include "../Resource/Biome.hpp"
#include "../NBT/ByteTag.hpp"
#include "../NBT/IntTag.hpp"
#include "../NBT/StringTag.hpp"
#include <cstdio>
@ -17,7 +18,16 @@ namespace MinedMap {
namespace World {
Section::Section(const std::shared_ptr<const NBT::CompoundTag> &section) {
Y = int8_t(assertValue(section->get<NBT::ByteTag>("Y"))->getValue());
const std::shared_ptr<const NBT::ByteTag> YByteTag = section->get<NBT::ByteTag>("Y");
if (YByteTag) {
Y = int8_t(YByteTag->getValue());
} else {
const std::shared_ptr<const NBT::IntTag> YIntTag = assertValue(section->get<NBT::IntTag>("Y"));
int32_t value = YIntTag->getValue();
if (int8_t(value) != value)
throw std::invalid_argument("unsupported section Y coordinate");
Y = value;
}
blockLight = section->get<NBT::ByteArrayTag>("BlockLight");
}