mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-03-05 17:44:52 +01:00
NBT: unify API of different array types
This commit is contained in:
parent
c313db2994
commit
466f393d26
4 changed files with 17 additions and 9 deletions
|
@ -37,7 +37,7 @@ namespace NBT {
|
||||||
class ByteArrayTag : public Tag {
|
class ByteArrayTag : public Tag {
|
||||||
private:
|
private:
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
const uint8_t *value;
|
const uint8_t *ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const MakeType<ByteArrayTag> Type;
|
static const MakeType<ByteArrayTag> Type;
|
||||||
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
ByteArrayTag(Buffer *buffer) {
|
ByteArrayTag(Buffer *buffer) {
|
||||||
len = buffer->get32();
|
len = buffer->get32();
|
||||||
value = buffer->get(len);
|
ptr = buffer->get(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual const TagType & getType() const {
|
virtual const TagType & getType() const {
|
||||||
|
@ -58,7 +58,7 @@ public:
|
||||||
std::string inner = indent + " ";
|
std::string inner = indent + " ";
|
||||||
|
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
uint8_t v = value[i];
|
uint8_t v = ptr[i];
|
||||||
|
|
||||||
os << inner
|
os << inner
|
||||||
<< (unsigned)v << " / "
|
<< (unsigned)v << " / "
|
||||||
|
@ -74,8 +74,12 @@ public:
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t * getValue() const {
|
const uint8_t * getPointer() const {
|
||||||
return value;
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getValue(size_t i) const {
|
||||||
|
return ptr[i];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,10 @@ public:
|
||||||
const uint8_t * getPointer() const {
|
const uint8_t * getPointer() const {
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t getValue(size_t i) const {
|
||||||
|
return Buffer::parse64(&ptr[8*i]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ private:
|
||||||
|
|
||||||
uint8_t getBiomeAt(size_t x, size_t z) const {
|
uint8_t getBiomeAt(size_t x, size_t z) const {
|
||||||
if (biomeBytes)
|
if (biomeBytes)
|
||||||
return biomeBytes->getValue()[z*SIZE + x];
|
return biomeBytes->getValue(z*SIZE + x);
|
||||||
else
|
else
|
||||||
return biomeInts->getValue(z*SIZE + x);
|
return biomeInts->getValue(z*SIZE + x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public:
|
||||||
if (!blockLight)
|
if (!blockLight)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return getHalf(blockLight->getValue(), x, y, z);
|
return getHalf(blockLight->getPointer(), x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::unique_ptr<Section> makeSection(const std::shared_ptr<const NBT::CompoundTag> §ion, uint32_t dataVersion);
|
static std::unique_ptr<Section> makeSection(const std::shared_ptr<const NBT::CompoundTag> §ion, uint32_t dataVersion);
|
||||||
|
@ -91,11 +91,11 @@ private:
|
||||||
|
|
||||||
|
|
||||||
uint8_t getBlockAt(size_t x, size_t y, size_t z) const {
|
uint8_t getBlockAt(size_t x, size_t y, size_t z) const {
|
||||||
return blocks->getValue()[getIndex(x, y, z)];
|
return blocks->getValue(getIndex(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getDataAt(size_t x, size_t y, size_t z) const {
|
uint8_t getDataAt(size_t x, size_t y, size_t z) const {
|
||||||
return getHalf(data->getValue(), x, y, z);
|
return getHalf(data->getPointer(), x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Add table
Reference in a new issue