diff --git a/build.properties b/build.properties index e99545a7..b7afeb85 100644 --- a/build.properties +++ b/build.properties @@ -2,5 +2,5 @@ #Sat Dec 28 00:14:08 EST 2013 minecraft_version = 1.7.10 forge_version = 10.13.2.1291 -mod_version = 0.2 -release_type = alpha +mod_version = 0.3 +release_type = beta diff --git a/src/main/java/com/pahimar/ee3/api/AlchemyArray.java b/src/main/java/com/pahimar/ee3/api/AlchemyArray.java index 3be0a67c..5a6c6d65 100644 --- a/src/main/java/com/pahimar/ee3/api/AlchemyArray.java +++ b/src/main/java/com/pahimar/ee3/api/AlchemyArray.java @@ -14,7 +14,7 @@ import net.minecraft.world.World; public class AlchemyArray implements Comparable { private ResourceLocation texture; - private String unLocalizedName; + private String unlocalizedName; private String className; private int lightLevel; private int chalkPerBlockCost; @@ -24,10 +24,10 @@ public class AlchemyArray implements Comparable } - public AlchemyArray(ResourceLocation texture, String unLocalizedName) + public AlchemyArray(ResourceLocation texture, String unlocalizedName) { this.texture = texture; - this.unLocalizedName = unLocalizedName; + this.unlocalizedName = unlocalizedName; this.chalkPerBlockCost = 1; this.lightLevel = 0; } @@ -42,19 +42,19 @@ public class AlchemyArray implements Comparable this.texture = texture; } - public String getUnLocalizedName() + public String getUnlocalizedName() { - return unLocalizedName; + return unlocalizedName; } - public void setUnLocalizedName(String unLocalizedName) + public void setUnlocalizedName(String unlocalizedName) { - this.unLocalizedName = unLocalizedName; + this.unlocalizedName = unlocalizedName; } public String getDisplayName() { - return StatCollector.translateToLocal(unLocalizedName); + return StatCollector.translateToLocal(unlocalizedName); } public int getChalkCostPerBlock() @@ -90,13 +90,13 @@ public class AlchemyArray implements Comparable this.texture = new ResourceLocation(""); } - if (nbtTagCompound.hasKey("unLocalizedName")) + if (nbtTagCompound.hasKey("unlocalizedName")) { - this.unLocalizedName = nbtTagCompound.getString("unLocalizedName"); + this.unlocalizedName = nbtTagCompound.getString("unlocalizedName"); } else { - this.unLocalizedName = ""; + this.unlocalizedName = ""; } if (nbtTagCompound.hasKey("className")) @@ -120,7 +120,7 @@ public class AlchemyArray implements Comparable else { this.texture = new ResourceLocation(""); - this.unLocalizedName = ""; + this.unlocalizedName = ""; this.className = ""; this.lightLevel = 0; } @@ -130,7 +130,7 @@ public class AlchemyArray implements Comparable { nbtTagCompound.setString("textureDomain", texture.getResourceDomain()); nbtTagCompound.setString("texturePath", texture.getResourcePath()); - nbtTagCompound.setString("unLocalizedName", unLocalizedName); + nbtTagCompound.setString("unlocalizedName", unlocalizedName); nbtTagCompound.setString("className", this.getClass().getCanonicalName()); nbtTagCompound.setInteger("lightLevel", lightLevel); } diff --git a/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java b/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java index b259e055..caba67f1 100644 --- a/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java +++ b/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java @@ -16,8 +16,6 @@ import com.pahimar.ee3.util.SerializationHelper; import cpw.mods.fml.common.FMLCommonHandler; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; @@ -585,24 +583,10 @@ public class EnergyValueRegistry implements JsonSerializer, return stacksInRange; } - public void readFromNBT(NBTTagCompound nbtTagCompound) + public void loadFromMap(Map stackValueMap) { - if (nbtTagCompound != null && nbtTagCompound.hasKey("stackMappingList")) + if (stackValueMap != null) { - TreeMap stackValueMap = new TreeMap(); - - /** - * Read stack value mappings from NBTTagCompound - */ - NBTTagList stackMappingTagList = nbtTagCompound.getTagList("stackMappingList", 10); - for (int i = 0; i < stackMappingTagList.tagCount(); i++) - { - NBTTagCompound tagCompound = stackMappingTagList.getCompoundTagAt(i); - WrappedStack wrappedStack = WrappedStack.fromNBTTagCompound(tagCompound.getCompoundTag("wrappedStack")); - EnergyValue energyValue = EnergyValue.loadEnergyValueFromNBT(tagCompound.getCompoundTag("energyValue")); - stackValueMap.put(wrappedStack, energyValue); - } - ImmutableSortedMap.Builder stackMappingsBuilder = ImmutableSortedMap.naturalOrder(); stackMappingsBuilder.putAll(stackValueMap); stackMappings = stackMappingsBuilder.build(); @@ -614,23 +598,6 @@ public class EnergyValueRegistry implements JsonSerializer, } } - public void writeToNBT(NBTTagCompound nbtTagCompound) - { - NBTTagList stackMappingTagList = new NBTTagList(); - for (WrappedStack wrappedStack : stackMappings.keySet()) - { - if (wrappedStack != null && stackMappings.get(wrappedStack) != null) - { - NBTTagCompound stackMappingCompound = new NBTTagCompound(); - stackMappingCompound.setTag("wrappedStack", WrappedStack.toNBTTagCompound(wrappedStack)); - stackMappingCompound.setTag("energyValue", EnergyValue.writeEnergyValueToNBT(stackMappings.get(wrappedStack))); - stackMappingTagList.appendTag(stackMappingCompound); - } - } - nbtTagCompound.setTag("stackMappingList", stackMappingTagList); - nbtTagCompound.setString("modListMD5", SerializationHelper.getModListMD5()); - } - public void setEnergyValue(WrappedStack wrappedStack, EnergyValue energyValue) { if (wrappedStack != null && energyValue != null && Float.compare(energyValue.getValue(), 0f) > 0) @@ -740,26 +707,33 @@ public class EnergyValueRegistry implements JsonSerializer, if (!Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Always")) { - if (md5EnergyValuesFile.exists()) + if (Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("When Mods Change")) { - LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath()); - stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile); + if (md5EnergyValuesFile.exists()) + { + LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath()); + stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile); + } } - - if (staticEnergyValuesFile.exists()) + else if (Settings.DynamicEnergyValueGeneration.regenerateEnergyValuesWhen.equalsIgnoreCase("Never")) { - LogHelper.info("Attempting to load energy values from file: " + staticEnergyValuesFile.getAbsolutePath()); - stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(staticEnergyValuesFile); + if (staticEnergyValuesFile.exists()) + { + LogHelper.info("Attempting to load energy values from file: " + staticEnergyValuesFile.getAbsolutePath()); + stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(staticEnergyValuesFile); + } + else if (md5EnergyValuesFile.exists()) + { + LogHelper.info("Attempting to load energy values from file: " + md5EnergyValuesFile.getAbsolutePath()); + stackValueMap = SerializationHelper.decompressEnergyValueStackMapFromFile(md5EnergyValuesFile); + } } if (stackValueMap != null) { + loadFromMap(stackValueMap); LogHelper.info("Successfully loaded energy values from file"); - for (WrappedStack wrappedStack : stackValueMap.keySet()) - { - LogHelper.info(String.format("Stack: %s, Value: %s", wrappedStack, stackValueMap.get(wrappedStack))); - } - return false; + return true; } else { diff --git a/src/main/java/com/pahimar/ee3/network/message/MessageSyncEnergyValues.java b/src/main/java/com/pahimar/ee3/network/message/MessageSyncEnergyValues.java index 18cf1b20..a88b90dd 100644 --- a/src/main/java/com/pahimar/ee3/network/message/MessageSyncEnergyValues.java +++ b/src/main/java/com/pahimar/ee3/network/message/MessageSyncEnergyValues.java @@ -1,20 +1,25 @@ package com.pahimar.ee3.network.message; +import com.google.gson.stream.JsonReader; +import com.pahimar.ee3.api.EnergyValue; import com.pahimar.ee3.exchange.EnergyValueRegistry; +import com.pahimar.ee3.exchange.EnergyValueStackMapping; +import com.pahimar.ee3.exchange.WrappedStack; +import com.pahimar.ee3.util.CompressionHelper; import com.pahimar.ee3.util.LogHelper; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.StringReader; +import java.util.Map; +import java.util.TreeMap; public class MessageSyncEnergyValues implements IMessage, IMessageHandler { - public NBTTagCompound energyValueRegistryNBT; + public String jsonEnergyValueRegistry; public MessageSyncEnergyValues() { @@ -22,8 +27,7 @@ public class MessageSyncEnergyValues implements IMessage, IMessageHandler 0) { - compressedNBT = buf.readBytes(readableBytes).array(); + compressedBytes = buf.readBytes(readableBytes).array(); } - if (compressedNBT != null) + if (compressedBytes != null) { - try - { - this.energyValueRegistryNBT = CompressedStreamTools.readCompressed(new ByteArrayInputStream(compressedNBT)); - } - catch (IOException e) - { - e.printStackTrace(); - } + this.jsonEnergyValueRegistry = CompressionHelper.decompressStringFromByteArray(compressedBytes); } } @@ -63,24 +60,17 @@ public class MessageSyncEnergyValues implements IMessage, IMessageHandler energyValueStackMap = new TreeMap(); + + try + { + JsonReader jsonReader = new JsonReader(new StringReader(message.jsonEnergyValueRegistry)); + 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 (IOException e) + { + e.printStackTrace(); + } + + for (WrappedStack wrappedStack : energyValueStackMap.keySet()) + { + LogHelper.info(String.format("Object: %s, Value: %s", wrappedStack, energyValueStackMap.get(wrappedStack))); + } + EnergyValueRegistry.getInstance().loadFromMap(energyValueStackMap); LogHelper.info("Client successfully received EnergyValues from server"); } else