Merge pull request #640 from Dynious/calculationOptimizations

Optimized getEmcValue and hasEmcValue
This commit is contained in:
pahimar 2014-02-24 11:42:41 -05:00
commit 86f2179967

View file

@ -265,7 +265,7 @@ public class EmcRegistry
if (emcRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack()))) if (emcRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
{ {
return emcRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())); return true;
} }
else else
{ {
@ -283,7 +283,7 @@ public class EmcRegistry
if (emcRegistry.stackMappings.containsKey(new WrappedStack(oreStack))) if (emcRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
{ {
return emcRegistry.stackMappings.containsKey(new WrappedStack(oreStack)); return true;
} }
else else
{ {
@ -291,7 +291,7 @@ public class EmcRegistry
{ {
if (emcRegistry.stackMappings.containsKey(new WrappedStack(itemStack))) if (emcRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
{ {
return emcRegistry.stackMappings.containsKey(new WrappedStack(itemStack)); return true;
} }
} }
} }
@ -339,7 +339,7 @@ public class EmcRegistry
public EmcValue getEmcValue(Object object, boolean strict) public EmcValue getEmcValue(Object object, boolean strict)
{ {
if (hasEmcValue(object, strict)) if (WrappedStack.canBeWrapped(object))
{ {
WrappedStack stack = new WrappedStack(object); WrappedStack stack = new WrappedStack(object);
@ -349,36 +349,62 @@ public class EmcRegistry
} }
else else
{ {
if (stack.getWrappedStack() instanceof ItemStack) if (!strict)
{ {
EmcValue lowestValue = null; if (stack.getWrappedStack() instanceof ItemStack)
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
if (OreDictionary.getOreID(wrappedItemStack) != -1)
{ {
OreStack oreStack = new OreStack(wrappedItemStack); EmcValue lowestValue = null;
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
if (emcRegistry.stackMappings.containsKey(new WrappedStack(oreStack))) if (OreDictionary.getOreID(wrappedItemStack) != -1)
{ {
return emcRegistry.stackMappings.get(new WrappedStack(oreStack)); OreStack oreStack = new OreStack(wrappedItemStack);
if (emcRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
{
return emcRegistry.stackMappings.get(new WrappedStack(oreStack));
}
else
{
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
{
if (emcRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
{
if (lowestValue == null)
{
lowestValue = emcRegistry.stackMappings.get(new WrappedStack(itemStack));
}
else
{
EmcValue itemValue = emcRegistry.stackMappings.get(new WrappedStack(itemStack));
if (itemValue.compareTo(lowestValue) < 0)
{
lowestValue = itemValue;
}
}
}
}
return lowestValue;
}
} }
else else
{ {
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack))) for (WrappedStack valuedStack : emcRegistry.stackMappings.keySet())
{ {
if (emcRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
{
if (lowestValue == null)
{
lowestValue = emcRegistry.stackMappings.get(new WrappedStack(itemStack));
}
else
{
EmcValue itemValue = emcRegistry.stackMappings.get(new WrappedStack(itemStack));
if (itemValue.compareTo(lowestValue) < 0) if (valuedStack.getWrappedStack() instanceof ItemStack)
{
ItemStack valuedItemStack = (ItemStack) valuedStack.getWrappedStack();
if ((valuedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) && valuedItemStack.itemID == wrappedItemStack.itemID)
{
EmcValue stackValue = emcRegistry.stackMappings.get(valuedStack);
if (stackValue.compareTo(lowestValue) < 0)
{ {
lowestValue = itemValue; lowestValue = stackValue;
} }
} }
} }
@ -387,38 +413,16 @@ public class EmcRegistry
return lowestValue; return lowestValue;
} }
} }
else else if (stack.getWrappedStack() instanceof OreStack)
{ {
for (WrappedStack valuedStack : emcRegistry.stackMappings.keySet()) OreStack oreStack = (OreStack)stack.getWrappedStack();
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
{ {
EmcValue stackValue = emcRegistry.stackMappings.get(valuedStack); if (emcRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
if (valuedStack.getWrappedStack() instanceof ItemStack)
{ {
ItemStack valuedItemStack = (ItemStack) valuedStack.getWrappedStack(); return emcRegistry.stackMappings.get(new WrappedStack(oreItemStack));
if ((valuedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE) && valuedItemStack.itemID == wrappedItemStack.itemID)
{
if (stackValue.compareTo(lowestValue) < 0)
{
lowestValue = stackValue;
}
}
} }
} }
return lowestValue;
}
}
else if (stack.getWrappedStack() instanceof OreStack)
{
OreStack oreStack = (OreStack)stack.getWrappedStack();
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
{
if (emcRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
{
return emcRegistry.stackMappings.get(new WrappedStack(oreItemStack));
}
} }
} }
} }