Skip to content

Commit

Permalink
Fallback to uncompressed when reading player data (paulevsGitch/Bette…
Browse files Browse the repository at this point in the history
  • Loading branch information
quiqueck committed Nov 6, 2021
1 parent 07d8c56 commit 60574d5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/main/java/ru/bclib/api/datafixer/DataFixerAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.zip.ZipException;

/**
* API to manage Patches that need to get applied to a world
Expand Down Expand Up @@ -393,11 +394,12 @@ private static void fixLevel(MigrationProfile profile, State state, File levelBa
e.printStackTrace();
}
}

private static void fixPlayer(MigrationProfile data, State state, File file) {
try {
LOGGER.info("Inspecting " + file);
CompoundTag player = NbtIo.readCompressed(file);

CompoundTag player = readNbt(file);
boolean[] changed = { false };
fixPlayerNbt(player, changed, data);

Expand All @@ -413,7 +415,7 @@ private static void fixPlayer(MigrationProfile data, State state, File file) {
e.printStackTrace();
}
}

private static void fixPlayerNbt(CompoundTag player, boolean[] changed, MigrationProfile data) {
//Checking Inventory
ListTag inventory = player.getList("Inventory", Tag.TAG_COMPOUND);
Expand Down Expand Up @@ -599,4 +601,12 @@ public static void registerPatch(Supplier<Patch> patch) {
Patch.getALL().add(patch.get());
}

private static CompoundTag readNbt(File file) throws IOException {
try {
return NbtIo.readCompressed(file);
} catch (ZipException e){
return NbtIo.read(file);
}
}

}

0 comments on commit 60574d5

Please sign in to comment.