add Chunk.convertV2

This commit is contained in:
MihailRis 2024-09-05 11:34:01 +03:00
parent c18eddb63c
commit 4a619fc18e
2 changed files with 10 additions and 1 deletions

View File

@ -158,7 +158,6 @@ bool Chunk::decodeV2(const ubyte* data) {
void Chunk::convert(ubyte* data, const ContentReport* report) {
for (uint i = 0; i < CHUNK_VOL; i++) {
// see encode method to understand what the hell is going on here
blockid_t id =
((static_cast<blockid_t>(data[i]) << 8) |
static_cast<blockid_t>(data[CHUNK_VOL + i]));
@ -167,3 +166,12 @@ void Chunk::convert(ubyte* data, const ContentReport* report) {
data[CHUNK_VOL + i] = replacement & 0xFF;
}
}
void Chunk::convertV2(ubyte* data, const ContentReport* report) {
auto buffer = reinterpret_cast<uint16_t*>(data);
for (uint i = 0; i < CHUNK_VOL; i++) {
blockid_t id = dataio::le2h(buffer[i]);
blockid_t replacement = report->blocks.getId(id);
buffer[i] = dataio::h2le(replacement);
}
}

View File

@ -81,4 +81,5 @@ public:
bool decodeV2(const ubyte* data);
static void convert(ubyte* data, const ContentReport* report);
static void convertV2(ubyte* data, const ContentReport* report);
};