From d5d03c61f6ada3f77f9b2554bccb1aa724337a59 Mon Sep 17 00:00:00 2001 From: Pahimar Date: Sat, 14 May 2016 14:31:45 -0400 Subject: [PATCH] About ready to port the DynEMC algo to the new EnergyValueRegistry class --- .../com/pahimar/ee3/EquivalentExchange3.java | 3 +-- .../ee3/exchange/NewEnergyValueRegistry.java | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/pahimar/ee3/EquivalentExchange3.java b/src/main/java/com/pahimar/ee3/EquivalentExchange3.java index 158736b5..5f83cd45 100644 --- a/src/main/java/com/pahimar/ee3/EquivalentExchange3.java +++ b/src/main/java/com/pahimar/ee3/EquivalentExchange3.java @@ -119,8 +119,6 @@ public class EquivalentExchange3 { CachedOreDictionary.getInstance(); Abilities.initNotLearnables(); - - NewEnergyValueRegistry.INSTANCE.save(); NewEnergyValueRegistry.INSTANCE.load(); } @@ -130,6 +128,7 @@ public class EquivalentExchange3 WorldEventHandler.hasInitilialized = false; EnergyValueRegistry.getInstance().save(); + NewEnergyValueRegistry.INSTANCE.save(); TransmutationKnowledgeRegistry.getInstance().clear(); AbilityRegistry.getInstance().save(); } diff --git a/src/main/java/com/pahimar/ee3/exchange/NewEnergyValueRegistry.java b/src/main/java/com/pahimar/ee3/exchange/NewEnergyValueRegistry.java index cab9bcbe..d302b0c3 100644 --- a/src/main/java/com/pahimar/ee3/exchange/NewEnergyValueRegistry.java +++ b/src/main/java/com/pahimar/ee3/exchange/NewEnergyValueRegistry.java @@ -26,7 +26,6 @@ public class NewEnergyValueRegistry { private ImmutableSortedMap energyValueMap; - // TODO Should we have API values and files loaded from file as separate maps (runtime vs file) private final Map preCalculationValueMap; private final Map postCalculationValueMap; private transient SortedSet uncomputedStacks; @@ -107,7 +106,7 @@ public class NewEnergyValueRegistry { preCalculationValueMap.put(wrappedStack, factoredEnergyValue); if (doRegenValues) { - // TODO Regen values + compute(); } } else { @@ -122,31 +121,35 @@ public class NewEnergyValueRegistry { } } + /** + * This is where the magic happens + */ public void compute() { - // TODO Should we load in values from file? - // Initialize the "working copy" energy value map TreeMap stackValueMap = new TreeMap<>(); uncomputedStacks = new TreeSet<>(); // Add in all pre-calculation energy value mappings - // TODO Should we be extra vigilant about possible nulls here? - stackValueMap.putAll(preCalculationValueMap); + preCalculationValueMap.keySet().stream() + .filter(wrappedStack -> wrappedStack != null && wrappedStack.getWrappedObject() != null && preCalculationValueMap.get(wrappedStack) != null) + .forEach(wrappedStack -> stackValueMap.put(wrappedStack, preCalculationValueMap.get(wrappedStack))); // Calculate values from the known methods to create items, and the pre-calculation value mappings // TODO Re-implement DynEMC here // Add in all post-calculation energy value mappings - // TODO Should we be extra vigilant about possible nulls here? - stackValueMap.putAll(postCalculationValueMap); + postCalculationValueMap.keySet().stream() + .filter(wrappedStack -> wrappedStack != null && wrappedStack.getWrappedObject() != null && postCalculationValueMap.get(wrappedStack) != null) + .forEach(wrappedStack -> stackValueMap.put(wrappedStack, postCalculationValueMap.get(wrappedStack))); // Bake the final calculated energy value map ImmutableSortedMap.Builder stackMappingsBuilder = ImmutableSortedMap.naturalOrder(); stackMappingsBuilder.putAll(stackValueMap); energyValueMap = stackMappingsBuilder.build(); - // TODO Should we save the results to file now? + // Save the results to disk + save(); } /** @@ -175,7 +178,7 @@ public class NewEnergyValueRegistry { try { postCalculationValueMap.putAll(SerializationHelper.readFromJsonFile(postCalculationValuesFile)); } catch (FileNotFoundException e) { - // TODO Log that no pre-calculation values were loaded from file because file wasn't found + // TODO Log that no post-calculation values were loaded from file because file wasn't found } try { @@ -183,8 +186,8 @@ public class NewEnergyValueRegistry { energyValueMapBuilder.putAll(SerializationHelper.readFromJsonFile(energyValuesFile)); energyValueMap = energyValueMapBuilder.build(); } catch (FileNotFoundException e) { - LogHelper.warn("No calculated energy value file found, regenerating"); - // TODO Gen new values from the loaded pre/post value maps + LogHelper.warn("No calculated energy value file found, regenerating"); // TODO Better log message + compute(); } } }