Skip to content

Commit

Permalink
Fix forcedchunk.dat saving (should be uncompressed)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchej123 committed Dec 24, 2024
1 parent 7489be4 commit 75e0449
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/mitchej123/hodgepodge/core/HodgepodgeCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ public class HodgepodgeCore implements IFMLLoadingPlugin, IEarlyMixinLoader {
}

public static void saveWorldData(File file, NBTTagCompound tag) {
WorldDataSaver.INSTANCE.saveData(file, tag);
WorldDataSaver.INSTANCE.saveData(file, tag, true, false);
}

public static void saveWorldData(File file, NBTTagCompound tag, boolean backup) {
WorldDataSaver.INSTANCE.saveData(file, tag, backup);
public static void saveWorldDataUncompressed(File file, NBTTagCompound tag) {
WorldDataSaver.INSTANCE.saveData(file, tag, false, false);
}

public static void saveWorldDataBackup(File file, NBTTagCompound tag) {
WorldDataSaver.INSTANCE.saveData(file, tag, true, true);
}

public static void savfeWorldDataUncompressedBackup(File file, NBTTagCompound tag) {
WorldDataSaver.INSTANCE.saveData(file, tag, false, true);
}

private String[] transformerClasses;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class MixinForgeChunkManager_threadedIO {
value = "INVOKE",
target = "Lnet/minecraft/nbt/CompressedStreamTools;write(Lnet/minecraft/nbt/NBTTagCompound;Ljava/io/File;)V"))
private static void redirectWrite(NBTTagCompound forcedChunkNBTData, File chunkLoaderFile) throws IOException {
HodgepodgeCore.saveWorldData(chunkLoaderFile, forcedChunkNBTData);
HodgepodgeCore.saveWorldDataUncompressed(chunkLoaderFile, forcedChunkNBTData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class MixinSaveHandler_threadedIO {
private void injectSaveWorldDataWithPlayer(WorldInfo worldInfo, NBTTagCompound playerTag, CallbackInfo ci,
@Local(ordinal = 2) NBTTagCompound nbttagcompound2) {
File file = new File(((SaveHandler) (Object) this).getWorldDirectory(), "level.dat");
HodgepodgeCore.saveWorldData(file, nbttagcompound2, true);
HodgepodgeCore.saveWorldDataBackup(file, nbttagcompound2);
ci.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void saveMaze(World world) {

final File file = new File(world.getSaveHandler().getWorldDirectory(), filename);

HodgepodgeCore.saveWorldData(file, parentTag, true);
HodgepodgeCore.saveWorldDataBackup(file, parentTag);

}
}
24 changes: 13 additions & 11 deletions src/main/java/com/mitchej123/hodgepodge/util/WorldDataSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public class WorldDataSaver implements IThreadedFileIO {
static class WrappedNBTTagCompound {

public final NBTTagCompound tag;
public final boolean compressed;
public final boolean backup;

public WrappedNBTTagCompound(NBTTagCompound tag, boolean backup) {
public WrappedNBTTagCompound(NBTTagCompound tag, boolean compressed, boolean backup) {
this.tag = tag;
this.compressed = compressed;
this.backup = backup;
}
}
Expand All @@ -42,6 +44,7 @@ public boolean writeNextIO() {
final File file;
final WrappedNBTTagCompound wrapped;
final NBTTagCompound data;
final boolean compressed;
final boolean backup;
synchronized (pendingData) {
Iterator<Map.Entry<File, WrappedNBTTagCompound>> it = pendingData.entrySet().iterator();
Expand All @@ -53,6 +56,7 @@ public boolean writeNextIO() {
wrapped = entry.getValue();
data = wrapped.tag;
backup = wrapped.backup;
compressed = wrapped.compressed;
it.remove();

}
Expand All @@ -65,10 +69,12 @@ public boolean writeNextIO() {
}

try {
LOGGER.debug("Writing data to file {}", file);
FileOutputStream fileoutputstream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(data, fileoutputstream);
fileoutputstream.close();
LOGGER.info("Writing data to file {}{}", file, compressed ? " (compressed)" : "");
if (compressed) {
try (FileOutputStream fileoutputstream = new FileOutputStream(file)) {
CompressedStreamTools.writeCompressed(data, fileoutputstream);
}
} else CompressedStreamTools.write(data, file);

} catch (IOException e) {
LOGGER.error("Failed to write data to file {}", file, e);
Expand All @@ -77,12 +83,8 @@ public boolean writeNextIO() {
return true;
}

public void saveData(File file, NBTTagCompound parentTag) {
saveData(file, parentTag, false);
}

public void saveData(File file, NBTTagCompound parentTag, boolean backup) {
WrappedNBTTagCompound wrapped = new WrappedNBTTagCompound(parentTag, backup);
public void saveData(File file, NBTTagCompound parentTag, boolean compressed, boolean backup) {
WrappedNBTTagCompound wrapped = new WrappedNBTTagCompound(parentTag, compressed, backup);
if (pendingData.containsKey(file)) {
pendingData.replace(file, wrapped);
} else {
Expand Down

0 comments on commit 75e0449

Please sign in to comment.