Fixing some bugs with the DynEMC system, and improving the tests

This commit is contained in:
Pahimar 2015-04-16 18:18:49 -04:00
parent c8608a41fa
commit 1312175b6b
11 changed files with 6673 additions and 6753 deletions

View File

@ -71,6 +71,7 @@ public class CachedOreDictionary
{
List<String> oreNameList = new ArrayList<String>();
WrappedStack wrappedStack = new WrappedStack(itemStack);
if (itemStackToOreNameMap.containsKey(wrappedStack))
{
for (String oreName : itemStackToOreNameMap.get(wrappedStack))
@ -78,6 +79,13 @@ public class CachedOreDictionary
oreNameList.add(oreName);
}
}
else
{
for (WrappedStack wrappedStack1 : itemStackToOreNameMap.keySet())
{
}
}
return oreNameList;
}

View File

@ -31,8 +31,7 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
private boolean shouldRegenNextRestart = false;
private static EnergyValueRegistry energyValueRegistry = null;
private static Map<WrappedStack, EnergyValue> preAssignedMappings;
private static Map<WrappedStack, EnergyValue> postAssignedExactMappings;
private static Map<WrappedStack, List<WrappedStack>> postAssignedDependentMappings;
private static Map<WrappedStack, EnergyValue> postAssignedMappings;
private ImmutableSortedMap<WrappedStack, EnergyValue> stackMappings;
private ImmutableSortedMap<EnergyValue, List<WrappedStack>> valueMappings;
@ -95,9 +94,9 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
public void addPostAssignedExactEnergyValue(Object object, EnergyValue energyValue)
{
if (postAssignedExactMappings == null)
if (postAssignedMappings == null)
{
postAssignedExactMappings = new TreeMap<WrappedStack, EnergyValue>();
postAssignedMappings = new TreeMap<WrappedStack, EnergyValue>();
}
if (WrappedStack.canBeWrapped(object) && energyValue != null && Float.compare(energyValue.getEnergyValue(), 0f) > 0)
@ -109,43 +108,11 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
WrappedStack factoredWrappedStack = new WrappedStack(wrappedStack, 1);
EnergyValue factoredEnergyValue = EnergyValueHelper.factorEnergyValue(energyValue, wrappedStack.getStackSize());
postAssignedExactMappings.put(factoredWrappedStack, factoredEnergyValue);
postAssignedMappings.put(factoredWrappedStack, factoredEnergyValue);
}
}
}
public void addPostAssignedDependentEnergyValue(Object object, List objects)
{
if (postAssignedDependentMappings == null)
{
postAssignedDependentMappings = new TreeMap<WrappedStack, List<WrappedStack>>();
}
if (!WrappedStack.canBeWrapped(object))
{
return;
}
WrappedStack wrappedStack = new WrappedStack(object);
List<WrappedStack> wrappedStacks = new ArrayList<WrappedStack>();
for (Object obj : objects)
{
if (!WrappedStack.canBeWrapped(obj))
{
return;
}
else
{
wrappedStacks.add(new WrappedStack(obj));
}
}
if (wrappedStacks.size() > 0)
{
postAssignedDependentMappings.put(wrappedStack, wrappedStacks);
}
}
public boolean hasEnergyValue(Object object)
{
return hasEnergyValue(object, false);
@ -211,13 +178,14 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
ItemStack wrappedItemStack = (ItemStack) wrappedObject;
/**
* The ItemStack does not have a direct"mapping, so check if it is a member of an OreDictionary
* The ItemStack does not have a direct mapping, so check if it is a member of an OreDictionary
* entry. If it is a member of only one OreDictionary entry, check if that OreStack has a direct
* mapping
*/
if (CachedOreDictionary.getInstance().getOreNamesForItemStack(wrappedItemStack).size() == 1)
// if (CachedOreDictionary.getInstance().getOreNamesForItemStack(wrappedItemStack).size() == 1)
if (OreDictionary.getOreIDs(wrappedItemStack).length == 1)
{
OreStack oreStack = new OreStack(wrappedItemStack);
OreStack oreStack = new OreStack(OreDictionary.getOreName(OreDictionary.getOreIDs(wrappedItemStack)[0]));
if (stackEnergyValueMap.containsKey(new WrappedStack(oreStack)))
{
@ -378,51 +346,19 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
}
LogHelper.info(String.format("Finished dynamic value computation (computed %s values for objects in %s ms)", totalComputedValueCount, System.currentTimeMillis() - computationStartTime));
// /*
// * Post-assigned values
// */
// if (postAssignedDependentMappings != null)
// {
// for (WrappedStack wrappedStack : postAssignedDependentMappings.keySet())
// {
// boolean allItemsHaveValues = true;
// float computedValue = 0f;
// for (WrappedStack stack : postAssignedDependentMappings.get(wrappedStack))
// {
// if (getStoredEnergyValue(stack) != null)
// {
// computedValue += getStoredEnergyValue(stack).getStoredEnergyValue() * stack.getStackSize();
// }
// else
// {
// allItemsHaveValues = false;
// }
// }
//
// if (allItemsHaveValues)
// {
// stackValueMap.put(wrappedStack, new EnergyValue(computedValue));
// }
// }
// }
// else
// {
// postAssignedDependentMappings = new HashMap<WrappedStack, List<WrappedStack>>();
// }
if (postAssignedExactMappings != null)
if (postAssignedMappings != null)
{
for (WrappedStack wrappedStack : postAssignedExactMappings.keySet())
for (WrappedStack wrappedStack : postAssignedMappings.keySet())
{
if (postAssignedExactMappings.get(wrappedStack) != null)
if (postAssignedMappings.get(wrappedStack) != null)
{
stackValueMap.put(wrappedStack, postAssignedExactMappings.get(wrappedStack));
stackValueMap.put(wrappedStack, postAssignedMappings.get(wrappedStack));
}
}
}
else
{
postAssignedExactMappings = new TreeMap<WrappedStack, EnergyValue>();
postAssignedMappings = new TreeMap<WrappedStack, EnergyValue>();
}
// Grab custom post-assigned values from file
@ -844,18 +780,9 @@ public class EnergyValueRegistry implements INBTTaggable, JsonSerializer<EnergyV
}
else if (phase == EnergyValueRegistryProxy.Phase.POST_ASSIGNMENT)
{
LogHelper.info("POST-ASSIGNED VALUES (DEPENDENT)");
if (this.postAssignedDependentMappings != null)
if (this.postAssignedMappings != null)
{
for (WrappedStack wrappedStack : this.postAssignedDependentMappings.keySet())
{
LogHelper.info(String.format("- Object: %s, Value: %s", wrappedStack, EnergyValueRegistry.getInstance().getStackValueMap().get(wrappedStack)));
}
}
LogHelper.info("POST-ASSIGNED VALUES (EXACT)");
if (this.postAssignedExactMappings != null)
{
for (WrappedStack wrappedStack : this.postAssignedExactMappings.keySet())
for (WrappedStack wrappedStack : this.postAssignedMappings.keySet())
{
LogHelper.info(String.format("- Object: %s, Value: %s", wrappedStack, EnergyValueRegistry.getInstance().getStackValueMap().get(wrappedStack)));
}

View File

@ -3,7 +3,6 @@ package com.pahimar.ee3.exchange;
import com.pahimar.ee3.reference.Comparators;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.oredict.OreDictionary;
import java.util.*;
@ -65,16 +64,6 @@ public class OreStack implements Comparable<OreStack>
this.stackSize = stackSize;
}
// TODO Refactor away, we shouldn't be building OreStacks from single ItemStacks
public OreStack(ItemStack itemStack)
{
if (itemStack != null && OreDictionary.getOreIDs(itemStack).length > 0)
{
this.oreName = OreDictionary.getOreName(OreDictionary.getOreIDs(itemStack)[0]);
this.stackSize = itemStack.stackSize;
}
}
public static boolean compareOreNames(OreStack oreStack1, OreStack oreStack2)
{
if (oreStack1 != null && oreStack2 != null)

View File

@ -15,6 +15,7 @@ public class EnergyValues
{
// OreDictionary assignment
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("cobblestone")), 1);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("stone")), 1);
String[] dyes = {"Black", "Red", "Green", "Brown", "Blue", "Purple", "Cyan", "LightGray", "Gray", "Pink", "Lime", "Yellow", "LightBlue", "Magenta", "Orange", "White"};
for (int i = 0; i < dyes.length; i++)
@ -41,10 +42,10 @@ public class EnergyValues
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("slabWood")), 4);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("stairWood")), 12);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("stickWood")), 4);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("stone")), 1);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("leaves")), 1);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("sapling")), 32);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("treeLeaves")), 1);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("treeSapling")), 32);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("sandstone")), 4);
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(new OreStack("sand")), 1);
// Fluids
EnergyValueRegistryProxy.addPreAssignedEnergyValue(new WrappedStack(FluidRegistry.WATER), 1);

View File

@ -1,6 +1,6 @@
package com.pahimar.ee3.item.crafting;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.exchange.WrappedStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
@ -21,23 +21,8 @@ public class RecipeAludel
this.dustStack = dustStack.copy();
}
public RecipeAludel(ItemStack recipeOutput, OreStack inputStack, ItemStack dustStack)
{
this.recipeOutput = recipeOutput.copy();
this.inputStack = new WrappedStack(inputStack);
this.dustStack = dustStack.copy();
}
public boolean matches(ItemStack inputStack, ItemStack dustStack)
{
if (OreDictionary.getOreIDs(inputStack).length > 0)
{
if (matches(new WrappedStack(new OreStack(inputStack)), dustStack))
{
return matches(new WrappedStack(new OreStack(inputStack)), dustStack);
}
}
return matches(new WrappedStack(inputStack), dustStack);
}
@ -59,13 +44,6 @@ public class RecipeAludel
return compareItemStacks(itemStack1, itemStack2);
}
else if (wrappedStack1.getWrappedObject() instanceof OreStack && wrappedStack2.getWrappedObject() instanceof OreStack)
{
if (((OreStack) wrappedStack1.getWrappedObject()).oreName.equalsIgnoreCase(((OreStack) wrappedStack2.getWrappedObject()).oreName))
{
return wrappedStack2.getStackSize() >= wrappedStack1.getStackSize();
}
}
}
return false;

View File

@ -2,7 +2,6 @@ package com.pahimar.ee3.recipe;
import com.google.common.collect.ImmutableList;
import com.pahimar.ee3.api.RecipeRegistryProxy;
import com.pahimar.ee3.exchange.OreStack;
import com.pahimar.ee3.item.crafting.RecipeAludel;
import net.minecraft.item.ItemStack;
@ -43,11 +42,6 @@ public class AludelRecipeManager
}
}
public void addRecipe(ItemStack recipeOutput, OreStack recipeInputStack, ItemStack recipeInputDust)
{
addRecipe(new RecipeAludel(recipeOutput, recipeInputStack, recipeInputDust));
}
public ItemStack getResult(ItemStack recipeInputStack, ItemStack recipeInputDust)
{
for (RecipeAludel recipeAludel : aludelRecipes)

View File

@ -244,22 +244,22 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(new ItemStack(Blocks.leaves2, 1, 0), 1);
add(new ItemStack(Blocks.leaves2, 1, 1), 1);
add(new ItemStack(Blocks.carpet, 1, 0), 32);
add(new ItemStack(Blocks.carpet, 1, 1), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 2), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 3), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 4), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 5), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 6), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 7), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 8), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 9), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 10), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 11), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 12), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 13), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 14), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 15), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 15), 37.333332);
add(new ItemStack(Blocks.carpet, 1, 1), 37.333);
add(new ItemStack(Blocks.carpet, 1, 2), 37.333);
add(new ItemStack(Blocks.carpet, 1, 3), 37.333);
add(new ItemStack(Blocks.carpet, 1, 4), 37.333);
add(new ItemStack(Blocks.carpet, 1, 5), 37.333);
add(new ItemStack(Blocks.carpet, 1, 6), 37.333);
add(new ItemStack(Blocks.carpet, 1, 7), 37.333);
add(new ItemStack(Blocks.carpet, 1, 8), 37.333);
add(new ItemStack(Blocks.carpet, 1, 9), 37.333);
add(new ItemStack(Blocks.carpet, 1, 10), 37.333);
add(new ItemStack(Blocks.carpet, 1, 11), 37.333);
add(new ItemStack(Blocks.carpet, 1, 12), 37.333);
add(new ItemStack(Blocks.carpet, 1, 13), 37.333);
add(new ItemStack(Blocks.carpet, 1, 14), 37.333);
add(new ItemStack(Blocks.carpet, 1, 15), 37.333);
add(new ItemStack(Blocks.carpet, 1, 15), 37.333);
add(new ItemStack(Blocks.double_plant, 1, 0), 16);
add(new ItemStack(Blocks.double_plant, 1, 1), 16);
add(new ItemStack(Blocks.double_plant, 1, 2), 16);
@ -363,7 +363,7 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(new ItemStack(Items.spawn_egg, 1, 97), null);
add(new ItemStack(Items.spawn_egg, 1, 99), null);
add(Items.experience_bottle, null);
add(Items.fire_charge, 330.66666);
add(Items.fire_charge, 330.667);
add(Items.writable_book, 216);
add(Items.map, 1312);
add(Items.firework_charge, null);
@ -411,7 +411,7 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(Items.potato, 24);
add(Items.baked_potato, 24);
add(Items.poisonous_potato, 24);
add(Items.golden_carrot, 1844.4445);
add(Items.golden_carrot, 1844.448);
add(Items.pumpkin_pie, 208);
}
@ -506,13 +506,13 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(new ItemStack(Items.potionitem, 1, 16420), 730);
add(new ItemStack(Items.potionitem, 1, 16452), 762);
add(new ItemStack(Items.potionitem, 1, 8261), null);
add(new ItemStack(Items.potionitem, 1, 8229), 2246.4443);
add(new ItemStack(Items.potionitem, 1, 8229), 2246.448);
add(new ItemStack(Items.potionitem, 1, 16453), null);
add(new ItemStack(Items.potionitem, 1, 16421), 2438.4443);
add(new ItemStack(Items.potionitem, 1, 16421), 2438.448);
add(new ItemStack(Items.potionitem, 1, 8230), null);
add(new ItemStack(Items.potionitem, 1, 8262), 1902.4445);
add(new ItemStack(Items.potionitem, 1, 8262), 1902.448);
add(new ItemStack(Items.potionitem, 1, 16422), null);
add(new ItemStack(Items.potionitem, 1, 16454), 2094.4443);
add(new ItemStack(Items.potionitem, 1, 16454), 2094.448);
add(new ItemStack(Items.potionitem, 1, 8232), null);
add(new ItemStack(Items.potionitem, 1, 8264), 226);
add(new ItemStack(Items.potionitem, 1, 16424), null);
@ -536,15 +536,15 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(new ItemStack(Items.potionitem, 1, 16429), null);
add(new ItemStack(Items.potionitem, 1, 16461), null);
add(new ItemStack(Items.potionitem, 1, 8238), null);
add(new ItemStack(Items.potionitem, 1, 8270), 2094.4443);
add(new ItemStack(Items.potionitem, 1, 8270), 2094.448);
add(new ItemStack(Items.potionitem, 1, 16430), null);
add(new ItemStack(Items.potionitem, 1, 16462), 2286.4443);
add(new ItemStack(Items.potionitem, 1, 16462), 2286.448);
add(Items.glass_bottle, 1);
add(Items.fermented_spider_eye, 192);
add(Items.blaze_powder, 768);
add(Items.magma_cream, 792);
add(Items.brewing_stand, 1539);
add(Items.speckled_melon, 1836.4445);
add(Items.speckled_melon, 1836.448);
}
private void addMaterialsTabTestCases()
@ -588,7 +588,7 @@ public class VanillaEnergyValueTest extends EnergyValueMappingsTestSuite
add(Items.pumpkin_seeds, 36);
add(Items.melon_seeds, 16);
add(Items.blaze_rod, 1536);
add(Items.gold_nugget, 227.55556);
add(Items.gold_nugget, 227.556);
add(Items.nether_wart, 24);
add(Items.emerald, 8192);
add(Items.nether_star, 24576);

View File

@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.oredict.OreDictionary;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
@ -110,11 +111,11 @@ public class EnergyValueHelper
{
if ((Float.compare(factor, 0f) != 0) && (energyValue != null))
{
return new EnergyValue(energyValue.getEnergyValue() * 1f / factor);
return new EnergyValue(new BigDecimal(energyValue.getEnergyValue() * 1f / factor).setScale(3, BigDecimal.ROUND_HALF_EVEN).floatValue());
}
else
{
return energyValue;
return null;
}
}
}

View File

@ -5,6 +5,7 @@ import com.pahimar.ee3.reference.Names;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.Comparator;
import java.util.UUID;
@ -31,7 +32,7 @@ public class ItemHelper
if (itemStack1.getItem() == itemStack2.getItem())
{
// Then sort on meta
if (itemStack1.getItemDamage() == itemStack2.getItemDamage())
if ((itemStack1.getItemDamage() == itemStack2.getItemDamage()) || itemStack1.getItemDamage() == OreDictionary.WILDCARD_VALUE || itemStack2.getItemDamage() == OreDictionary.WILDCARD_VALUE)
{
// Then sort on NBT
if (itemStack1.hasTagCompound() && itemStack2.hasTagCompound())

View File

@ -243,7 +243,10 @@ public class SerializationHelper
jsonWriter.beginArray();
for (WrappedStack wrappedStack : energyValueMap.keySet())
{
EnergyValueStackMapping.jsonSerializer.toJson(new EnergyValueStackMapping(wrappedStack, energyValueMap.get(wrappedStack)), EnergyValueStackMapping.class, jsonWriter);
if (wrappedStack.getWrappedObject() != null)
{
EnergyValueStackMapping.jsonSerializer.toJson(new EnergyValueStackMapping(wrappedStack, energyValueMap.get(wrappedStack)), EnergyValueStackMapping.class, jsonWriter);
}
}
jsonWriter.endArray();

File diff suppressed because it is too large Load Diff