diff --git a/src/main/java/com/pahimar/ee3/api/AbilityRegistryProxy.java b/src/main/java/com/pahimar/ee3/api/AbilityRegistryProxy.java index 704daf2a..8cd76166 100644 --- a/src/main/java/com/pahimar/ee3/api/AbilityRegistryProxy.java +++ b/src/main/java/com/pahimar/ee3/api/AbilityRegistryProxy.java @@ -72,6 +72,21 @@ public final class AbilityRegistryProxy } } + public static void dumpAbilityRegistryToLog() + { + dumpAbilityRegistryToLog(Abilities.ALL); + } + + public static void dumpAbilityRegistryToLog(Abilities ability) + { + init(); + + if (ee3Mod != null) + { + EE3Wrapper.ee3mod.getAbilityRegistry().dumpAbilityRegistryToLog(ability); + } + } + private static class EE3Wrapper { private static EquivalentExchange3 ee3mod; @@ -84,4 +99,11 @@ public final class AbilityRegistryProxy EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod; } } + + public enum Abilities + { + NOT_LEARNABLE, + NOT_RECOVERABLE, + ALL + } } diff --git a/src/main/java/com/pahimar/ee3/api/EnergyValueRegistryProxy.java b/src/main/java/com/pahimar/ee3/api/EnergyValueRegistryProxy.java index b08e0e42..f46fcd47 100644 --- a/src/main/java/com/pahimar/ee3/api/EnergyValueRegistryProxy.java +++ b/src/main/java/com/pahimar/ee3/api/EnergyValueRegistryProxy.java @@ -107,6 +107,21 @@ public final class EnergyValueRegistryProxy return null; } + public static void dumpEnergyValueRegistryToLog() + { + dumpEnergyValueRegistryToLog(Phase.ALL); + } + + public static void dumpEnergyValueRegistryToLog(Phase phase) + { + init(); + + if (ee3Mod != null) + { + EE3Wrapper.ee3mod.getEnergyValueRegistry().dumpEnergyValueRegistryToLog(phase); + } + } + private static class EE3Wrapper { private static EquivalentExchange3 ee3mod; @@ -119,4 +134,11 @@ public final class EnergyValueRegistryProxy EE3Wrapper.ee3mod = (EquivalentExchange3) ee3Mod; } } + + public enum Phase + { + PRE_ASSIGNMENT, + POST_ASSIGNMENT, + ALL + } } diff --git a/src/main/java/com/pahimar/ee3/api/RecipeRegistryProxy.java b/src/main/java/com/pahimar/ee3/api/RecipeRegistryProxy.java index aa2fca8d..ae2e1fc3 100644 --- a/src/main/java/com/pahimar/ee3/api/RecipeRegistryProxy.java +++ b/src/main/java/com/pahimar/ee3/api/RecipeRegistryProxy.java @@ -12,12 +12,21 @@ public final class RecipeRegistryProxy init(); // NOOP if EquivalentExchange3 is not present - if (ee3Mod == null) + if (ee3Mod != null) { - return; + EE3Wrapper.ee3mod.getRecipeRegistry().addRecipe(recipeOutput, recipeInputList); } + } - EE3Wrapper.ee3mod.getRecipeRegistry().addRecipe(recipeOutput, recipeInputList); + public static void dumpRecipeRegistryToLog() + { + init(); + + // NOOP if EquivalentExchange3 is not present + if (ee3Mod != null) + { + EE3Wrapper.ee3mod.getRecipeRegistry().dumpRecipeRegistryToLog(); + } } @Mod.Instance("EE3") diff --git a/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java b/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java index b3befb95..c60ae1df 100644 --- a/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java +++ b/src/main/java/com/pahimar/ee3/exchange/EnergyValueRegistry.java @@ -3,6 +3,7 @@ package com.pahimar.ee3.exchange; import com.google.common.collect.ImmutableSortedMap; import com.google.gson.*; import com.pahimar.ee3.api.EnergyValue; +import com.pahimar.ee3.api.EnergyValueRegistryProxy; import com.pahimar.ee3.api.IEnergyValueProvider; import com.pahimar.ee3.knowledge.AbilityRegistry; import com.pahimar.ee3.recipe.RecipeRegistry; @@ -60,7 +61,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer(); + preAssignedMappings = new TreeMap(); } if (WrappedStack.canBeWrapped(object) && energyValue != null && Float.compare(energyValue.getEnergyValue(), 0f) > 0) @@ -96,7 +97,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer(); + postAssignedExactMappings = new TreeMap(); } if (WrappedStack.canBeWrapped(object) && energyValue != null && Float.compare(energyValue.getEnergyValue(), 0f) > 0) @@ -117,7 +118,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer>(); + postAssignedDependentMappings = new TreeMap>(); } if (!WrappedStack.canBeWrapped(object)) @@ -303,7 +304,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer stackValueMap = new HashMap(); + TreeMap stackValueMap = new TreeMap(); /* * Pre-assigned values @@ -321,7 +322,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer stackMappingsBuilder = ImmutableSortedMap.naturalOrder(); stackMappingsBuilder.putAll(stackValueMap); stackMappings = stackMappingsBuilder.build(); - Map computedStackValues = new HashMap(); + Map computedStackValues = new TreeMap(); // Initialize the pass counter int passNumber = 0; @@ -431,7 +432,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer(); + postAssignedExactMappings = new TreeMap(); } // Grab custom post-assigned values from file @@ -486,7 +487,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer computeStackMappings() { - Map computedStackMap = new HashMap(); + Map computedStackMap = new TreeMap(); for (WrappedStack recipeOutput : RecipeRegistry.getInstance().getRecipeMappings().keySet()) { @@ -584,7 +585,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer stackValueMap = new HashMap(); + TreeMap stackValueMap = new TreeMap(); /** * Read stack value mappings from NBTTagCompound @@ -637,7 +638,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer 0) { - HashMap stackValueMap = new HashMap(); + TreeMap stackValueMap = new TreeMap(); /** * Read stack value mappings from NBTTagCompound @@ -793,7 +794,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer stackValueMap = new HashMap(); + Map stackValueMap = new TreeMap(); Iterator iterator = jsonArray.iterator(); while (iterator.hasNext()) @@ -829,4 +830,48 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer, JsonDeserializer { + public static final Gson jsonSerializer = (new GsonBuilder()).registerTypeAdapter(JsonItemStack.class, new JsonItemStack()).create(); + public String itemName; public int itemDamage; public NBTTagCompound itemNBTTagCompound; @@ -26,4 +34,75 @@ public class JsonItemStack this.itemNBTTagCompound = itemStack.getTagCompound(); } } + + @Override + public JsonItemStack deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException + { + if (json.isJsonObject()) + { + JsonObject jsonObject = (JsonObject) json; + JsonItemStack jsonItemStack = new JsonItemStack(); + + if (jsonObject.has("itemName")) + { + jsonItemStack.itemName = jsonObject.get("itemName").getAsString(); + } + else + { + throw new JsonParseException(""); // TODO Exception message + } + + if (jsonObject.has("itemDamage")) + { + jsonItemStack.itemDamage = jsonObject.get("itemDamage").getAsInt(); + } + else + { + throw new JsonParseException(""); // TODO Exception message + } + + if (jsonObject.has("itemNBTTagCompound")) + { + try + { + NBTBase nbtBase = JsonToNBT.func_150315_a(jsonObject.get("itemNBTTagCompound").getAsString()); + + if (nbtBase instanceof NBTTagCompound) + { + jsonItemStack.itemNBTTagCompound = (NBTTagCompound) nbtBase; + } + } + catch (NBTException e) + { + throw new JsonParseException(e.getMessage(), e.getCause()); + } + } + + return jsonItemStack; + } + + return null; + } + + @Override + public JsonElement serialize(JsonItemStack src, Type typeOfSrc, JsonSerializationContext context) + { + JsonObject jsonObject = new JsonObject(); + + jsonObject.addProperty("itemName", src.itemName); + jsonObject.addProperty("itemDamage", src.itemDamage); + + if (src.itemNBTTagCompound != null) + { + jsonObject.addProperty("itemNBTTagCompound", src.itemNBTTagCompound.toString()); + } + + return jsonObject; + } + + @Override + public String toString() + { + return String.format("itemName: %s, itemDamage: %s, itemNBTTagCompound: %s", itemName, itemDamage, itemNBTTagCompound); + } } diff --git a/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java b/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java index e3235c21..6dc8c94a 100644 --- a/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java +++ b/src/main/java/com/pahimar/ee3/exchange/WrappedStack.java @@ -49,7 +49,12 @@ public class WrappedStack implements Comparable, JsonDeserializer< { if (((ItemStack) object).getItem() != null) { - ItemStack itemStack = ((ItemStack) object).copy(); + ItemStack itemStackObject = (ItemStack) object; + ItemStack itemStack = new ItemStack(itemStackObject.getItem(), itemStackObject.stackSize, itemStackObject.getItemDamage()); + if (itemStackObject.stackTagCompound != null) + { + itemStack.stackTagCompound = (NBTTagCompound) itemStackObject.stackTagCompound.copy(); + } objectType = "itemstack"; stackSize = itemStack.stackSize; itemStack.stackSize = 1; @@ -392,7 +397,7 @@ public class WrappedStack implements Comparable, JsonDeserializer< { if (objectType.equalsIgnoreCase("ItemStack")) { - JsonItemStack jsonItemStack = jsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack_data"), JsonItemStack.class); + JsonItemStack jsonItemStack = JsonItemStack.jsonSerializer.fromJson(jsonWrappedStack.get("wrappedStack_data"), JsonItemStack.class); ItemStack itemStack = null; Item item = (Item) Item.itemRegistry.getObject(jsonItemStack.itemName); if (stackSize > 0 && item != null) @@ -477,7 +482,7 @@ public class WrappedStack implements Comparable, JsonDeserializer< { jsonItemStack.itemNBTTagCompound = ((ItemStack) wrappedStack.wrappedStack).stackTagCompound; } - jsonWrappedStack.add("wrappedStack_data", gson.toJsonTree(jsonItemStack, JsonItemStack.class)); + jsonWrappedStack.add("wrappedStack_data", JsonItemStack.jsonSerializer.toJsonTree(jsonItemStack, JsonItemStack.class)); } else if (wrappedStack.wrappedStack instanceof OreStack) { @@ -555,7 +560,7 @@ public class WrappedStack implements Comparable, JsonDeserializer< { if (wrappedStack instanceof ItemStack) { - return String.format("%sxitemStack[%s@%s, %s]", stackSize, ((ItemStack) wrappedStack).getUnlocalizedName(), ((ItemStack) wrappedStack).getItemDamage(), Item.getIdFromItem(((ItemStack) wrappedStack).getItem())); + return ItemHelper.toString((ItemStack) wrappedStack); } else if (wrappedStack instanceof OreStack) { diff --git a/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalTome.java b/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalTome.java index 7ffad521..959fbe5c 100644 --- a/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalTome.java +++ b/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalTome.java @@ -21,7 +21,6 @@ import java.util.UUID; public class ContainerAlchemicalTome extends ContainerEE implements IElementButtonHandler, IElementTextFieldHandler { private final InventoryAlchemicalTome inventoryAlchemicalTome; - private final ItemStack alchemicalTomeItemStack; private int pageOffset, maxPageOffset; private String searchTerm; private boolean requiresUpdate = false; @@ -31,7 +30,6 @@ public class ContainerAlchemicalTome extends ContainerEE implements IElementButt public ContainerAlchemicalTome(EntityPlayer entityPlayer, ItemStack itemStack) { - this.alchemicalTomeItemStack = itemStack; TreeSet knownTransmutations = new TreeSet(ItemHelper.displayNameComparator); if (itemStack.getItem() instanceof ItemAlchemicalTome && ItemHelper.hasOwnerUUID(itemStack)) diff --git a/src/main/java/com/pahimar/ee3/knowledge/AbilityRegistry.java b/src/main/java/com/pahimar/ee3/knowledge/AbilityRegistry.java index 372a7065..a1f3dec7 100644 --- a/src/main/java/com/pahimar/ee3/knowledge/AbilityRegistry.java +++ b/src/main/java/com/pahimar/ee3/knowledge/AbilityRegistry.java @@ -3,11 +3,13 @@ package com.pahimar.ee3.knowledge; import com.google.gson.*; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; +import com.pahimar.ee3.api.AbilityRegistryProxy; import com.pahimar.ee3.exchange.EnergyValueRegistry; import com.pahimar.ee3.exchange.OreStack; import com.pahimar.ee3.exchange.WrappedStack; import com.pahimar.ee3.reference.Files; import com.pahimar.ee3.util.ItemHelper; +import com.pahimar.ee3.util.LogHelper; import com.pahimar.ee3.util.SerializationHelper; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -332,4 +334,55 @@ public class AbilityRegistry implements JsonSerializer, JsonDes e.printStackTrace(); } } + + public void dumpAbilityRegistryToLog() + { + dumpAbilityRegistryToLog(AbilityRegistryProxy.Abilities.ALL); + } + + public void dumpAbilityRegistryToLog(AbilityRegistryProxy.Abilities abilityType) + { + LogHelper.info(String.format("BEGIN DUMPING %s ABILITY OBJECTS", abilityType)); + if (abilityType == AbilityRegistryProxy.Abilities.NOT_LEARNABLE) + { + if (this.notLearnableSet != null) + { + for (WrappedStack wrappedStack : this.notLearnableSet) + { + LogHelper.info(String.format("- Object: %s", wrappedStack)); + } + } + } + else if (abilityType == AbilityRegistryProxy.Abilities.NOT_RECOVERABLE) + { + if (this.notRecoverableSet != null) + { + for (WrappedStack wrappedStack : this.notRecoverableSet) + { + LogHelper.info(String.format("- Object: %s", wrappedStack)); + } + } + } + else if (abilityType == AbilityRegistryProxy.Abilities.ALL) + { + if (this.notLearnableSet != null) + { + LogHelper.info("NOT LEARNABLE OBJECTS"); + for (WrappedStack wrappedStack : this.notLearnableSet) + { + LogHelper.info(String.format("- Object: %s", wrappedStack)); + } + } + + if (this.notRecoverableSet != null) + { + LogHelper.info("NOT RECOVERABLE OBJECTS"); + for (WrappedStack wrappedStack : this.notRecoverableSet) + { + LogHelper.info(String.format("- Object: %s", wrappedStack)); + } + } + } + LogHelper.info(String.format("END DUMPING %s ABILITY OBJECTS", abilityType)); + } } diff --git a/src/main/java/com/pahimar/ee3/knowledge/TransmutationKnowledge.java b/src/main/java/com/pahimar/ee3/knowledge/TransmutationKnowledge.java index 48f63b4f..7fa06d70 100644 --- a/src/main/java/com/pahimar/ee3/knowledge/TransmutationKnowledge.java +++ b/src/main/java/com/pahimar/ee3/knowledge/TransmutationKnowledge.java @@ -266,22 +266,28 @@ public class TransmutationKnowledge implements INBTTaggable, JsonSerializer listStacks : recipeMap.get(wrappedStack)) + stringBuilder.append(String.format("-Output: %s, Inputs: ", wrappedStack.toString())); + for (List listStacks : getRecipeMappings().get(wrappedStack)) { for (WrappedStack listStack : listStacks) { diff --git a/src/main/java/com/pahimar/ee3/util/SerializationHelper.java b/src/main/java/com/pahimar/ee3/util/SerializationHelper.java index a2d99503..94d8061f 100644 --- a/src/main/java/com/pahimar/ee3/util/SerializationHelper.java +++ b/src/main/java/com/pahimar/ee3/util/SerializationHelper.java @@ -207,7 +207,10 @@ public class SerializationHelper while (jsonReader.hasNext()) { EnergyValueStackMapping energyValueStackMapping = EnergyValueStackMapping.jsonSerializer.fromJson(jsonReader, EnergyValueStackMapping.class); - energyValueStackMap.put(energyValueStackMapping.wrappedStack, energyValueStackMapping.energyValue); + if (energyValueStackMapping != null) + { + energyValueStackMap.put(energyValueStackMapping.wrappedStack, energyValueStackMapping.energyValue); + } } jsonReader.endArray(); jsonReader.close();