More broke stuff

This commit is contained in:
Pahimar 2015-05-02 14:07:01 -04:00
parent 34cda981c0
commit 87e1f9fb1a
4 changed files with 64 additions and 60 deletions

View file

@ -136,8 +136,8 @@ public class GuiTransmutationTablet extends GuiBase
protected void drawGuiContainerForegroundLayer(int x, int y)
{
super.drawGuiContainerForegroundLayer(x, y);
fontRendererObj.drawString(String.format("%s:", StatCollector.translateToLocal(Messages.ENERGY_VALUE)), 8, 140, Integer.parseInt(Colors.PURE_WHITE, 16));
fontRendererObj.drawString(String.format("%s", energyValueDecimalFormat.format(tileEntityTransmutationTablet.getAvailableEnergyValue().getValue())), 8, 150, Integer.parseInt(Colors.PURE_WHITE, 16));
fontRendererObj.drawString(String.format("%s:", StatCollector.translateToLocal(Messages.ENERGY_VALUE)), 10, 142, Integer.parseInt(Colors.PURE_WHITE, 16));
fontRendererObj.drawString(String.format("%s", energyValueDecimalFormat.format(tileEntityTransmutationTablet.getAvailableEnergyValue().getValue())), 10, 152, Integer.parseInt(Colors.PURE_WHITE, 16));
}
@Override

View file

@ -10,7 +10,9 @@ import com.pahimar.ee3.recipe.RecipeRegistry;
import com.pahimar.ee3.reference.Files;
import com.pahimar.ee3.reference.Reference;
import com.pahimar.ee3.reference.Settings;
import com.pahimar.ee3.util.*;
import com.pahimar.ee3.util.EnergyValueHelper;
import com.pahimar.ee3.util.LogHelper;
import com.pahimar.ee3.util.SerializationHelper;
import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -23,7 +25,7 @@ import java.io.File;
import java.lang.reflect.Type;
import java.util.*;
public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyValueRegistry>, JsonDeserializer<EnergyValueRegistry>
public class EnergyValueRegistry implements JsonSerializer<EnergyValueRegistry>, JsonDeserializer<EnergyValueRegistry>
{
private static final Gson jsonSerializer = (new GsonBuilder()).registerTypeAdapter(EnergyValueRegistry.class, new EnergyValueRegistry()).registerTypeAdapter(EnergyValueStackMapping.class, new EnergyValueStackMapping()).create();
private static final Gson prettyJsonSerializer = (new GsonBuilder()).setPrettyPrinting().registerTypeAdapter(EnergyValueRegistry.class, new EnergyValueRegistry()).registerTypeAdapter(EnergyValueStackMapping.class, new EnergyValueStackMapping()).create();
@ -35,8 +37,6 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
private ImmutableSortedMap<WrappedStack, EnergyValue> stackMappings;
private ImmutableSortedMap<EnergyValue, List<WrappedStack>> valueMappings;
private Set<ItemStack> allItemStacksWithValues = new TreeSet<ItemStack>(ItemHelper.idComparator);
private EnergyValueRegistry()
{
}
@ -585,7 +585,6 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
return stacksInRange;
}
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
if (nbtTagCompound != null && nbtTagCompound.hasKey("stackMappingList"))
@ -615,7 +614,6 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
NBTTagList stackMappingTagList = new NBTTagList();
@ -633,12 +631,6 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
nbtTagCompound.setString("modListMD5", SerializationHelper.getModListMD5());
}
@Override
public String getTagLabel()
{
return "EnergyValueRegistry";
}
public void setEnergyValue(WrappedStack wrappedStack, EnergyValue energyValue)
{
if (wrappedStack != null && energyValue != null && Float.compare(energyValue.getValue(), 0f) > 0)
@ -714,21 +706,9 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
if (shouldRegenNextRestart)
{
File staticEnergyValuesFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES);
File staticEnergyValuesJsonFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON);
File md5EnergyValuesFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat");
File md5EnergyValuesJsonFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json");
// NBT
if (staticEnergyValuesFile.exists())
{
staticEnergyValuesFile.delete();
}
if (md5EnergyValuesFile.exists())
{
md5EnergyValuesFile.delete();
}
// JSON
if (staticEnergyValuesJsonFile.exists())
{
@ -743,58 +723,43 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
}
else
{
// SerializationHelper.writeNBTToFile(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES, this);
SerializationHelper.compressEnergyValueRegistryToFile(new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES));
SerializationHelper.writeNBTToFile(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat", this);
SerializationHelper.writeEnergyValueStackMapToJsonFile(new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON), energyValueRegistry.stackMappings);
SerializationHelper.writeEnergyValueStackMapToJsonFile(new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json"), energyValueRegistry.stackMappings);
SerializationHelper.compressEnergyValueStackMapToFile(new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON), energyValueRegistry.stackMappings);
SerializationHelper.compressEnergyValueStackMapToFile(new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json.gz"), energyValueRegistry.stackMappings);
}
}
public boolean loadEnergyValueRegistryFromFile()
{
// TODO Come back here
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues");
energyValuesDataDirectory.mkdirs();
File staticEnergyValuesFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES);
File md5EnergyValuesFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".dat");
File staticEnergyValuesFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON);
File md5EnergyValuesFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json.gz");
File staticEnergyValuesJsonFile = new File(energyValuesDataDirectory, Files.STATIC_ENERGY_VALUES_JSON);
File md5EnergyValuesJsonFile = new File(energyValuesDataDirectory, SerializationHelper.getModListMD5() + ".json");
Map<WrappedStack, EnergyValue> stackValueMap = null;
NBTTagCompound nbtTagCompound = null;
// TODO Re-enable this once the NPE related to mod changes in the serialized value file bug is resolved
// if (Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Never"))
// {
// if (staticEnergyValuesFile.exists())
// {
// LogHelper.info("Attempting to load energy values from file: " + staticEnergyValuesFile.getAbsolutePath());
// nbtTagCompound = SerializationHelper.readNBTFromFile(staticEnergyValuesFile);
// }
// else if (md5EnergyValuesFile.exists())
// {
// LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath());
// nbtTagCompound = SerializationHelper.readNBTFromFile(md5EnergyValuesFile);
// }
//
// }
// else if (md5EnergyValuesFile.exists())
if (!Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Always"))
{
if (md5EnergyValuesFile.exists())
{
LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath());
nbtTagCompound = SerializationHelper.readNBTFromFile(md5EnergyValuesFile);
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile);
}
if (nbtTagCompound != null)
if (staticEnergyValuesFile.exists())
{
LogHelper.info("Attempting to load energy values from file: " + staticEnergyValuesFile.getAbsolutePath());
stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(staticEnergyValuesFile);
}
if (stackValueMap != null)
{
energyValueRegistry.readFromNBT(nbtTagCompound);
LogHelper.info("Successfully loaded energy values from file");
return true;
for (WrappedStack wrappedStack : stackValueMap.keySet())
{
LogHelper.info(String.format("Stack: %s, Value: %s", wrappedStack, stackValueMap.get(wrappedStack)));
}
return false;
}
else
{

View file

@ -6,6 +6,5 @@ public class Files
public static final String POST_ASSIGNED_ENERGY_VALUES = "post-assigned-energy-values.json";
public static final String TEMPLATE_JSON_FILE = "template.json";
public static final String ABILITIES_JSON_FILE = "abilities.json";
public static final String STATIC_ENERGY_VALUES = "energy-values.dat";
public static final String STATIC_ENERGY_VALUES_JSON = "energy-values.json.gz";
}

View file

@ -1,5 +1,6 @@
package com.pahimar.ee3.util;
import com.google.common.io.Files;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.pahimar.ee3.api.EnergyValue;
@ -287,4 +288,43 @@ public class SerializationHelper
e.printStackTrace();
}
}
public static Map<WrappedStack, EnergyValue> decompressEnergyValueStackMapFromFile(String fileName)
{
File energyValuesDataDirectory = new File(FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getSaveHandler().getWorldDirectory(), "data" + File.separator + Reference.LOWERCASE_MOD_ID + File.separator + "energyvalues");
return decompressEnergyValueStackMapFromFile(new File(energyValuesDataDirectory, fileName));
}
public static Map<WrappedStack, EnergyValue> decompressEnergyValueStackMapFromFile(File file)
{
Map<WrappedStack, EnergyValue> energyValueStackMap = new TreeMap<WrappedStack, EnergyValue>();
try
{
String jsonEnergyValueStackMap = CompressionHelper.decompressStringFromByteArray(Files.toByteArray(file));
JsonReader jsonReader = new JsonReader(new StringReader(jsonEnergyValueStackMap));
jsonReader.beginArray();
while (jsonReader.hasNext())
{
EnergyValueStackMapping energyValueStackMapping = EnergyValueStackMapping.jsonSerializer.fromJson(jsonReader, EnergyValueStackMapping.class);
if (energyValueStackMapping != null)
{
energyValueStackMap.put(energyValueStackMapping.wrappedStack, energyValueStackMapping.energyValue);
}
}
jsonReader.endArray();
jsonReader.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return energyValueStackMap;
}
}