Skip to content

Commit

Permalink
Support restoring worlds with old chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvinn8 committed Oct 17, 2023
1 parent 173f519 commit ceb1271
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mch/src/main/java/ca/bkaw/mch/region/mc/McRegionFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down

0 comments on commit ceb1271

Please sign in to comment.