From ceb1271f1e7ecc0c82e8268b0ed1ff740160f50d Mon Sep 17 00:00:00 2001 From: Alvinn8 <42838560+Alvinn8@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:23:15 +0200 Subject: [PATCH] Support restoring worlds with old chunks --- .../ca/bkaw/mch/region/mc/McRegionFileWriter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mch/src/main/java/ca/bkaw/mch/region/mc/McRegionFileWriter.java b/mch/src/main/java/ca/bkaw/mch/region/mc/McRegionFileWriter.java index bbf4698..87f0652 100644 --- a/mch/src/main/java/ca/bkaw/mch/region/mc/McRegionFileWriter.java +++ b/mch/src/main/java/ca/bkaw/mch/region/mc/McRegionFileWriter.java @@ -57,6 +57,17 @@ private long getNextSector(long location) { public void writeChunk(NbtCompound chunkNbt, int lastModified) throws IOException { NbtInt xPos = (NbtInt) chunkNbt.get("xPos"); NbtInt zPos = (NbtInt) chunkNbt.get("zPos"); + if (xPos == null || zPos == null) { + // Some older versions of the game store all data in a nested "Level" tag. While + // mch mainly targets newer versions of the game, there are still cases where a + // world needs to be restored that has some chunks that have not been touched in + // a long time and therefore have chunks in this old format, despite the world + // being loaded and saved in the latest version. + if (chunkNbt.get("Level") instanceof NbtCompound level) { + xPos = (NbtInt) level.get("xPos"); + zPos = (NbtInt) level.get("zPos"); + } + } if (xPos == null || zPos == null) { throw new IllegalArgumentException("The provided chunk nbt does not specify its coordinates."); }