mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
Section: implement new Minecraft 1.16 block state format
This commit is contained in:
parent
73b8b677da
commit
7a99a19998
2 changed files with 37 additions and 16 deletions
|
@ -82,18 +82,28 @@ PaletteSection::PaletteSection(
|
||||||
const std::shared_ptr<const NBT::CompoundTag> §ion,
|
const std::shared_ptr<const NBT::CompoundTag> §ion,
|
||||||
std::shared_ptr<const NBT::LongArrayTag> &&blockStates0,
|
std::shared_ptr<const NBT::LongArrayTag> &&blockStates0,
|
||||||
const std::shared_ptr<const NBT::ListTag> &paletteData,
|
const std::shared_ptr<const NBT::ListTag> &paletteData,
|
||||||
uint32_t dataVersion
|
uint32_t dataVersion0
|
||||||
) : Section(section), blockStates(blockStates0) {
|
) : Section(section), blockStates(blockStates0), dataVersion(dataVersion0) {
|
||||||
if (blockStates->getLength() % 64)
|
bits = 4;
|
||||||
|
while ((1u << bits) < paletteData->size()) {
|
||||||
|
bits++;
|
||||||
|
|
||||||
|
if (bits > 12)
|
||||||
|
throw std::invalid_argument("unsupported block palette size");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned expectedLength;
|
||||||
|
|
||||||
|
if (dataVersion < 2529) {
|
||||||
|
expectedLength = 64 * bits;
|
||||||
|
} else {
|
||||||
|
unsigned blocksPerWord = (64 / bits);
|
||||||
|
expectedLength = (4096 + blocksPerWord - 1) / blocksPerWord;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockStates->getLength() != expectedLength)
|
||||||
throw std::invalid_argument("corrupt section data");
|
throw std::invalid_argument("corrupt section data");
|
||||||
|
|
||||||
bits = blockStates->getLength() / 64;
|
|
||||||
if (bits > 16)
|
|
||||||
throw std::invalid_argument("unsupported block state bits");
|
|
||||||
|
|
||||||
mask = (1u << bits) - 1;
|
|
||||||
|
|
||||||
|
|
||||||
for (const auto &entry : *paletteData) {
|
for (const auto &entry : *paletteData) {
|
||||||
const NBT::CompoundTag &paletteEntry = *assertValue(dynamic_cast<const NBT::CompoundTag *>(entry.get()));
|
const NBT::CompoundTag &paletteEntry = *assertValue(dynamic_cast<const NBT::CompoundTag *>(entry.get()));
|
||||||
std::string name = assertValue(paletteEntry.get<NBT::StringTag>("Name"))->getValue();
|
std::string name = assertValue(paletteEntry.get<NBT::StringTag>("Name"))->getValue();
|
||||||
|
@ -107,9 +117,20 @@ PaletteSection::PaletteSection(
|
||||||
}
|
}
|
||||||
|
|
||||||
const Resource::BlockType * PaletteSection::getBlockStateAt(size_t x, size_t y, size_t z) const {
|
const Resource::BlockType * PaletteSection::getBlockStateAt(size_t x, size_t y, size_t z) const {
|
||||||
size_t index = bits * getIndex(x, y, z);
|
size_t index = getIndex(x, y, z);
|
||||||
size_t pos = index >> 3;
|
size_t bitIndex;
|
||||||
size_t shift = index & 7;
|
|
||||||
|
if (dataVersion < 2529) {
|
||||||
|
bitIndex = bits * index;
|
||||||
|
} else {
|
||||||
|
unsigned blocksPerWord = (64 / bits);
|
||||||
|
size_t word = index / blocksPerWord;
|
||||||
|
bitIndex = 64 * word + bits * (index % blocksPerWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t pos = bitIndex >> 3;
|
||||||
|
size_t shift = bitIndex & 7;
|
||||||
|
uint16_t mask = (1u << bits) - 1;
|
||||||
|
|
||||||
uint32_t v = blockStates->getPointer()[mangleByteIndex(pos)];
|
uint32_t v = blockStates->getPointer()[mangleByteIndex(pos)];
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,8 @@ class PaletteSection : public Section {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<const NBT::LongArrayTag> blockStates;
|
std::shared_ptr<const NBT::LongArrayTag> blockStates;
|
||||||
std::vector<const Resource::BlockType *> palette;
|
std::vector<const Resource::BlockType *> palette;
|
||||||
size_t bits;
|
uint32_t dataVersion;
|
||||||
uint16_t mask;
|
unsigned bits;
|
||||||
|
|
||||||
|
|
||||||
static const Resource::BlockType * lookup(const std::string &name, uint32_t dataVersion);
|
static const Resource::BlockType * lookup(const std::string &name, uint32_t dataVersion);
|
||||||
|
@ -127,7 +127,7 @@ public:
|
||||||
const std::shared_ptr<const NBT::CompoundTag> §ion,
|
const std::shared_ptr<const NBT::CompoundTag> §ion,
|
||||||
std::shared_ptr<const NBT::LongArrayTag> &&blockStates0,
|
std::shared_ptr<const NBT::LongArrayTag> &&blockStates0,
|
||||||
const std::shared_ptr<const NBT::ListTag> &paletteData,
|
const std::shared_ptr<const NBT::ListTag> &paletteData,
|
||||||
uint32_t dataVersion
|
uint32_t dataVersion0
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual const Resource::BlockType * getBlockStateAt(size_t x, size_t y, size_t z) const;
|
virtual const Resource::BlockType * getBlockStateAt(size_t x, size_t y, size_t z) const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue