Only run the DynamicEnergyValueInitThread on the server side (prevents clients running it when connecting to a server because since the server sends the values there is no need to gen values on the client). Also fix some sided stuff in the serialization of values when clients connect to servers.

This commit is contained in:
Pahimar 2014-09-04 15:15:16 -04:00
parent 49dbe16757
commit 73d67dd30d
2 changed files with 33 additions and 23 deletions

View file

@ -1,7 +1,9 @@
package com.pahimar.ee3.handler;
import com.pahimar.ee3.exchange.DynamicEnergyValueInitThread;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import net.minecraftforge.event.world.WorldEvent;
public class WorldEventHandler
@ -11,7 +13,7 @@ public class WorldEventHandler
@SubscribeEvent
public void onWorldLoadEvent(WorldEvent.Load event)
{
if (!hasInitilialized)
if (!hasInitilialized && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
{
DynamicEnergyValueInitThread.initEnergyValueRegistry();
hasInitilialized = true;

View file

@ -40,6 +40,11 @@ public class SerializationHelper
public static boolean energyValueRegistryFileExist()
{
if (FMLCommonHandler.instance().getMinecraftServerInstance() == null)
{
return false;
}
File dataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + "ee3");
if (!dataDirectory.exists())
{
@ -57,33 +62,36 @@ public class SerializationHelper
public static void writeEnergyValueRegistryToFile()
{
File dataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + "ee3");
if (!dataDirectory.exists())
if (FMLCommonHandler.instance().getMinecraftServerInstance() != null)
{
dataDirectory.mkdir();
}
NBTTagCompound energyValueRegistryNBT = new NBTTagCompound();
EnergyValueRegistry.getInstance().writeToNBT(energyValueRegistryNBT);
try
{
File file1 = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3.tmp");
File file2 = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
CompressedStreamTools.writeCompressed(energyValueRegistryNBT, new FileOutputStream(file1));
if (file2.exists())
File dataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + "ee3");
if (!dataDirectory.exists())
{
file2.delete();
dataDirectory.mkdir();
}
file1.renameTo(file2);
NBTTagCompound energyValueRegistryNBT = new NBTTagCompound();
EnergyValueRegistry.getInstance().writeToNBT(energyValueRegistryNBT);
LogHelper.info("Successfully saved EnergyValues to file: " + file2.getAbsolutePath());
}
catch (Exception exception)
{
LogHelper.warn("Failed to save EnergyValueRegistry to file " + dataDirectory.getPath() + SerializationHelper.getModListMD5() + ".ee3");
try
{
File file1 = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3.tmp");
File file2 = new File(dataDirectory, SerializationHelper.getModListMD5() + ".ee3");
CompressedStreamTools.writeCompressed(energyValueRegistryNBT, new FileOutputStream(file1));
if (file2.exists())
{
file2.delete();
}
file1.renameTo(file2);
LogHelper.info("Successfully saved EnergyValues to file: " + file2.getAbsolutePath());
}
catch (Exception exception)
{
LogHelper.warn("Failed to save EnergyValueRegistry to file " + dataDirectory.getPath() + SerializationHelper.getModListMD5() + ".ee3");
}
}
}