Compare commits

...

3 Commits

Author SHA1 Message Date
5b5f1f54af remove unneeded code 2025-08-28 16:46:27 +02:00
f1141e0db4 fix: not moving chunks correctly in mcx_delchunk_range 2025-08-28 10:59:30 +02:00
15942b47f5 fix: assertion was inverted 2025-08-28 10:57:00 +02:00
2 changed files with 3 additions and 37 deletions

View File

@@ -14,7 +14,7 @@ static void mvchunks(u8 *restrict buf, u8 *src, u8 *dst, int src_s, int src_e) {
assert(src > dst);
u32 *table = (u32 *)buf;
size_t len = src - dst; // acquire the amount of bytes that we shall move
assert(len % 0x1000);
assert(!(len % 0x1000));
// count how many bytes we need to move, whilst updating location data
size_t blen = 0;
@@ -69,7 +69,8 @@ size_t mcx_delchunk_range(u8 *restrict buf, int start, int end) {
}
// move the remaining chunks down
mvchunks(buf, src, dst, start, end);
if (end < 0x3FF)
mvchunks(buf, src, dst, end, 0x3FF);
return src - dst;
}
@@ -103,19 +104,3 @@ size_t mcx_calcsize(const u8 *restrict buf) {
size += *(buf + (i * 4) + 3);
return (size * 0x1000) + 0x2000;
}
/* an `*.mcX` contains a `0x2000` byte long table, the first `0x1000` containing
* `0x400` entries of chunk data.
* This chunk data is big-endian, where bytes `0xFFFFFF00` represent the `0x1000` sector offset.
* From the start, and bytes `0x000000FF` represent the length in `0x1000` sectors. */
void mcx_index(const u8 *restrict buf, struct mcx_chunk *restrict chunks) {
const u32 *ptr = (u32 *)buf;
for (uint i = 0; i < 0x400; i++) {
u32 dat = be32toh(ptr[i]);
chunks[i] = (struct mcx_chunk){
.idx = (dat >> 8) * 0x1000,
.len = (dat & 0xFF) * 0x1000,
.time = be32toh(ptr[i + 0x400]),
};
}
}

View File

@@ -35,22 +35,3 @@ size_t mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunk
/* Computes the byte size of the `*.mcX` file in `buf` and returns it. */
size_t mcx_calcsize(const u8 *restrict buf) NONNULL((1)) PURE;
/* indexes the chunks in an `*.mcX` file, writing `0x400` of entries to `chunks` */
void mcx_index(const u8 *restrict buf, struct mcx_chunk *restrict chunks) NONNULL((1, 2));
/* the MCR (Minecraft region) and MCA (Minecraft anvil) files are similar
* MCA is the newer variant, where it includes:
* - a world height of 256, rather than 128.
* - block IDs have been extended to 4096 from 256
* - block ordering is now YZX, rather than XZY.
* - biomes are included in the data per XZ column.
* MCR start with an 8KiB header, split in two 4KiB tables
* - the first containing the offsets of chunks in the region file itself.
* - the second providing timestamps on when they were last updated.
* -
*
*
*
*
*/