Try to save WorldData too when Chunks get unloaded as the stupid data loss bug is still a thing and it doesn't even make any sense

This commit is contained in:
Ellpeck 2016-06-05 00:08:32 +02:00
parent 1aa979195f
commit 6fd36259fc
2 changed files with 12 additions and 4 deletions

View file

@ -126,7 +126,7 @@ public class WorldData{
}
}
public static void save(World world){
public static void save(World world, boolean doMessage){
if(!world.isRemote){
WorldData data = worldData.get(world.provider.getDimension());
if(data != null && data.handler != null){
@ -145,7 +145,9 @@ public class WorldData{
CompressedStreamTools.writeCompressed(compound, stream);
stream.close();
ModUtil.LOGGER.info("Saved WorldData for world "+data.dimension+"!");
if(doMessage){
ModUtil.LOGGER.info("Saved WorldData for world "+data.dimension+"!");
}
}
}
catch(Exception e){
@ -160,7 +162,7 @@ public class WorldData{
public static void unload(World world){
if(!world.isRemote){
save(world);
save(world, true);
worldData.remove(world.provider.getDimension());
ModUtil.LOGGER.info("Unloading WorldData for world "+world.provider.getDimension()+"!");

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.data.WorldData;
import de.ellpeck.actuallyadditions.mod.util.FakePlayerUtil;
import net.minecraftforge.event.world.ChunkDataEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -30,7 +31,12 @@ public class WorldLoadingEvents{
@SubscribeEvent
public void onSave(WorldEvent.Save event){
WorldData.save(event.getWorld());
WorldData.save(event.getWorld(), true);
}
@SubscribeEvent
public void onChunkUnload(ChunkDataEvent.Save event){
WorldData.save(event.getWorld(), false);
}
}