2014-07-07 21:31:10 +02:00
|
|
|
package com.pahimar.ee3.exchange;
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableSortedMap;
|
2014-06-22 20:02:15 +02:00
|
|
|
import com.pahimar.ee3.init.EnergyValues;
|
2014-07-07 21:31:10 +02:00
|
|
|
import com.pahimar.ee3.recipe.RecipeRegistry;
|
2014-06-20 21:57:27 +02:00
|
|
|
import com.pahimar.ee3.util.EnergyValueHelper;
|
2014-06-14 21:40:45 +02:00
|
|
|
import com.pahimar.ee3.util.LogHelper;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
public class EnergyValueRegistry
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
private static EnergyValueRegistry energyValueRegistry = null;
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
private ImmutableSortedMap<WrappedStack, EnergyValue> stackMappings;
|
|
|
|
private ImmutableSortedMap<EnergyValue, List<WrappedStack>> valueMappings;
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
private EnergyValueRegistry()
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
public static EnergyValueRegistry getInstance()
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry == null)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
energyValueRegistry = new EnergyValueRegistry();
|
|
|
|
energyValueRegistry.init();
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
return energyValueRegistry;
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void init()
|
|
|
|
{
|
|
|
|
HashMap<WrappedStack, EnergyValue> stackValueMap = new HashMap<WrappedStack, EnergyValue>();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default values
|
|
|
|
*/
|
2014-06-22 20:02:15 +02:00
|
|
|
Map<WrappedStack, EnergyValue> defaultValuesMap = EnergyValues.getValueMap();
|
2014-06-14 21:40:45 +02:00
|
|
|
for (WrappedStack keyStack : defaultValuesMap.keySet())
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
EnergyValue factoredExchangeEnergyValue = null;
|
2014-06-14 21:40:45 +02:00
|
|
|
WrappedStack factoredKeyStack = null;
|
|
|
|
|
|
|
|
if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
|
|
|
{
|
2014-07-10 22:05:14 +02:00
|
|
|
if (defaultValuesMap.get(keyStack) != null && Float.compare(defaultValuesMap.get(keyStack).getEnergyValue(), 0f) > 0)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
factoredExchangeEnergyValue = EnergyValueHelper.factorEnergyValue(defaultValuesMap.get(keyStack), keyStack.getStackSize());
|
2014-06-14 21:40:45 +02:00
|
|
|
factoredKeyStack = new WrappedStack(keyStack, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (factoredExchangeEnergyValue != null)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
if (stackValueMap.containsKey(factoredKeyStack))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (factoredExchangeEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// /*
|
|
|
|
// * IMC Pre-assigned values
|
|
|
|
// */
|
|
|
|
// Map<WrappedStack, EnergyValue> preAssignedValuesMap = EnergyValuesIMC.getPreAssignedValues();
|
|
|
|
// for (WrappedStack keyStack : preAssignedValuesMap.keySet())
|
|
|
|
// {
|
|
|
|
// EnergyValue factoredEnergyValue = null;
|
|
|
|
// WrappedStack factoredKeyStack = null;
|
|
|
|
//
|
|
|
|
// if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
|
|
|
// {
|
|
|
|
// if (preAssignedValuesMap.get(keyStack) != null && Float.compare(preAssignedValuesMap.get(keyStack).getValue(), 0f) > 0)
|
|
|
|
// {
|
2014-06-20 21:57:27 +02:00
|
|
|
// factoredEnergyValue = EnergyValueHelper.factorEnergyValue(preAssignedValuesMap.get(keyStack), keyStack.getStackSize());
|
2014-06-14 21:40:45 +02:00
|
|
|
// factoredKeyStack = new WrappedStack(keyStack, 1);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (factoredEnergyValue != null)
|
|
|
|
// {
|
|
|
|
// if (stackValueMap.containsKey(factoredKeyStack))
|
|
|
|
// {
|
|
|
|
// if (factoredEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
|
|
|
// {
|
|
|
|
// stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Auto-assignment
|
|
|
|
*/
|
|
|
|
// Initialize the maps for the first pass to happen
|
|
|
|
ImmutableSortedMap.Builder<WrappedStack, EnergyValue> stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
|
|
|
stackMappingsBuilder.putAll(stackValueMap);
|
|
|
|
stackMappings = stackMappingsBuilder.build();
|
|
|
|
Map<WrappedStack, EnergyValue> computedStackValues = computeStackMappings();
|
|
|
|
|
|
|
|
// Initialize the pass counter
|
|
|
|
int passNumber = 0;
|
|
|
|
|
|
|
|
while ((computedStackValues.size() > 0) && (passNumber < 16))
|
|
|
|
{
|
|
|
|
// Increment the pass counter
|
|
|
|
passNumber++;
|
|
|
|
|
|
|
|
// Set the values for getEnergyValue calls in the auto-assignment computation
|
|
|
|
stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
|
|
|
stackMappingsBuilder.putAll(stackValueMap);
|
|
|
|
stackMappings = stackMappingsBuilder.build();
|
|
|
|
|
|
|
|
// Compute stack mappings from existing stack mappings
|
|
|
|
computedStackValues = computeStackMappings();
|
|
|
|
for (WrappedStack keyStack : computedStackValues.keySet())
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
EnergyValue factoredExchangeEnergyValue = null;
|
2014-06-14 21:40:45 +02:00
|
|
|
WrappedStack factoredKeyStack = null;
|
|
|
|
|
|
|
|
if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
|
|
|
{
|
2014-07-10 22:05:14 +02:00
|
|
|
if (computedStackValues.get(keyStack) != null && Float.compare(computedStackValues.get(keyStack).getEnergyValue(), 0f) > 0)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
factoredExchangeEnergyValue = EnergyValueHelper.factorEnergyValue(computedStackValues.get(keyStack), keyStack.getStackSize());
|
2014-06-14 21:40:45 +02:00
|
|
|
factoredKeyStack = new WrappedStack(keyStack, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (factoredExchangeEnergyValue != null)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
if (stackValueMap.containsKey(factoredKeyStack))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (factoredExchangeEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// /*
|
|
|
|
// * IMC Post-assigned values
|
|
|
|
// */
|
|
|
|
// Map<WrappedStack, EnergyValue> postAssignedValuesMap = EnergyValuesIMC.getPostAssignedValues();
|
|
|
|
// for (WrappedStack keyStack : postAssignedValuesMap.keySet())
|
|
|
|
// {
|
|
|
|
// EnergyValue factoredEnergyValue = null;
|
|
|
|
// WrappedStack factoredKeyStack = null;
|
|
|
|
//
|
|
|
|
// if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
|
|
|
// {
|
|
|
|
// if (postAssignedValuesMap.get(keyStack) != null && Float.compare(postAssignedValuesMap.get(keyStack).getValue(), 0f) > 0)
|
|
|
|
// {
|
|
|
|
// factoredEnergyValue = EnergyHelper.factorEnergyValue(postAssignedValuesMap.get(keyStack), keyStack.getStackSize());
|
|
|
|
// factoredKeyStack = new WrappedStack(keyStack, 1);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// // Post auto assignment values are meant to override all over values, so we just take the value given
|
|
|
|
// if (factoredEnergyValue != null)
|
|
|
|
// {
|
|
|
|
// stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Finalize the stack to value map
|
|
|
|
*/
|
|
|
|
stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
|
|
|
stackMappingsBuilder.putAll(stackValueMap);
|
|
|
|
stackMappings = stackMappingsBuilder.build();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Value map resolution
|
|
|
|
*/
|
|
|
|
SortedMap<EnergyValue, List<WrappedStack>> tempValueMappings = new TreeMap<EnergyValue, List<WrappedStack>>();
|
|
|
|
|
|
|
|
for (WrappedStack stack : stackMappings.keySet())
|
|
|
|
{
|
|
|
|
if (stack != null)
|
|
|
|
{
|
|
|
|
EnergyValue value = stackMappings.get(stack);
|
|
|
|
|
|
|
|
if (value != null)
|
|
|
|
{
|
|
|
|
if (tempValueMappings.containsKey(value))
|
|
|
|
{
|
|
|
|
if (!(tempValueMappings.get(value).contains(stack)))
|
|
|
|
{
|
|
|
|
tempValueMappings.get(value).add(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tempValueMappings.put(value, new ArrayList<WrappedStack>(Arrays.asList(stack)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
valueMappings = ImmutableSortedMap.copyOf(tempValueMappings);
|
|
|
|
}
|
|
|
|
|
|
|
|
private Map<WrappedStack, EnergyValue> computeStackMappings()
|
|
|
|
{
|
|
|
|
Map<WrappedStack, EnergyValue> computedStackMap = new HashMap<WrappedStack, EnergyValue>();
|
|
|
|
|
|
|
|
for (WrappedStack recipeOutput : RecipeRegistry.getInstance().getRecipeMappings().keySet())
|
|
|
|
{
|
|
|
|
if (!hasEnergyValue(recipeOutput.getWrappedStack(), false) && !computedStackMap.containsKey(recipeOutput))
|
|
|
|
{
|
|
|
|
EnergyValue lowestValue = null;
|
|
|
|
|
|
|
|
for (List<WrappedStack> recipeInputs : RecipeRegistry.getInstance().getRecipeMappings().get(recipeOutput))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
EnergyValue computedValue = EnergyValueHelper.computeEnergyValueFromList(recipeInputs);
|
|
|
|
computedValue = EnergyValueHelper.factorEnergyValue(computedValue, recipeOutput.getStackSize());
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
if (computedValue != null)
|
|
|
|
{
|
|
|
|
if (computedValue.compareTo(lowestValue) < 0)
|
|
|
|
{
|
|
|
|
lowestValue = computedValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 22:05:14 +02:00
|
|
|
if ((lowestValue != null) && (lowestValue.getEnergyValue() > 0f))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
computedStackMap.put(new WrappedStack(recipeOutput.getWrappedStack()), lowestValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return computedStackMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasEnergyValue(Object object, boolean strict)
|
|
|
|
{
|
|
|
|
if (WrappedStack.canBeWrapped(object))
|
|
|
|
{
|
|
|
|
WrappedStack stack = new WrappedStack(object);
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!strict)
|
|
|
|
{
|
|
|
|
if (stack.getWrappedStack() instanceof ItemStack)
|
|
|
|
{
|
|
|
|
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
|
|
|
|
|
|
|
|
// If its an OreDictionary item, scan its siblings for values
|
2014-06-20 21:57:27 +02:00
|
|
|
if (OreDictionary.getOreIDs(wrappedItemStack).length > 0)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
OreStack oreStack = new OreStack(wrappedItemStack);
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Else, scan for if there is a wildcard value for it
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
for (WrappedStack valuedStack : energyValueRegistry.stackMappings.keySet())
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
if (valuedStack.getWrappedStack() instanceof ItemStack)
|
|
|
|
{
|
|
|
|
ItemStack valuedItemStack = (ItemStack) valuedStack.getWrappedStack();
|
|
|
|
|
|
|
|
if (Item.getIdFromItem(valuedItemStack.getItem()) == Item.getIdFromItem(wrappedItemStack.getItem()))
|
|
|
|
{
|
|
|
|
if (valuedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (wrappedItemStack.getItem().isDamageable() && wrappedItemStack.isItemDamaged())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (stack.getWrappedStack() instanceof OreStack)
|
|
|
|
{
|
|
|
|
OreStack oreStack = (OreStack) stack.getWrappedStack();
|
|
|
|
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasEnergyValue(Object object)
|
|
|
|
{
|
|
|
|
return hasEnergyValue(object, false);
|
|
|
|
}
|
|
|
|
|
2014-07-07 17:22:21 +02:00
|
|
|
public EnergyValue getEnergyValue(Object object)
|
|
|
|
{
|
|
|
|
return getEnergyValue(object, false);
|
|
|
|
}
|
|
|
|
|
2014-06-14 21:40:45 +02:00
|
|
|
public EnergyValue getEnergyValue(Object object, boolean strict)
|
|
|
|
{
|
|
|
|
if (WrappedStack.canBeWrapped(object))
|
|
|
|
{
|
|
|
|
WrappedStack stack = new WrappedStack(object);
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
return energyValueRegistry.stackMappings.get(new WrappedStack(stack.getWrappedStack()));
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!strict)
|
|
|
|
{
|
|
|
|
if (stack.getWrappedStack() instanceof ItemStack)
|
|
|
|
{
|
|
|
|
EnergyValue lowestValue = null;
|
|
|
|
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (OreDictionary.getOreIDs(wrappedItemStack).length > 0)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
OreStack oreStack = new OreStack(wrappedItemStack);
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
return energyValueRegistry.stackMappings.get(new WrappedStack(oreStack));
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
if (lowestValue == null)
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
lowestValue = energyValueRegistry.stackMappings.get(new WrappedStack(itemStack));
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
EnergyValue itemValue = energyValueRegistry.stackMappings.get(new WrappedStack(itemStack));
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
if (itemValue.compareTo(lowestValue) < 0)
|
|
|
|
{
|
|
|
|
lowestValue = itemValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return lowestValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
for (WrappedStack valuedStack : energyValueRegistry.stackMappings.keySet())
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
|
|
|
if (valuedStack.getWrappedStack() instanceof ItemStack)
|
|
|
|
{
|
|
|
|
ItemStack valuedItemStack = (ItemStack) valuedStack.getWrappedStack();
|
|
|
|
|
|
|
|
if (Item.getIdFromItem(valuedItemStack.getItem()) == Item.getIdFromItem(wrappedItemStack.getItem()))
|
|
|
|
{
|
|
|
|
if (valuedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
EnergyValue stackValue = energyValueRegistry.stackMappings.get(valuedStack);
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
if (stackValue.compareTo(lowestValue) < 0)
|
|
|
|
{
|
|
|
|
lowestValue = stackValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (wrappedItemStack.getItem().isDamageable() && wrappedItemStack.isItemDamaged())
|
|
|
|
{
|
2014-07-10 22:05:14 +02:00
|
|
|
EnergyValue stackValue = new EnergyValue(energyValueRegistry.stackMappings.get(valuedStack).getEnergyValue() * (1 - (wrappedItemStack.getItemDamage() * 1.0F / wrappedItemStack.getMaxDamage())));
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
return energyValueRegistry.stackMappings.get(new WrappedStack(oreItemStack));
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public List<WrappedStack> getStacksInRange(int start, int finish)
|
|
|
|
{
|
|
|
|
return getStacksInRange(new EnergyValue(start), new EnergyValue(finish));
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<WrappedStack> getStacksInRange(EnergyValue start, EnergyValue finish)
|
|
|
|
{
|
|
|
|
List<WrappedStack> stacksInRange = new ArrayList<WrappedStack>();
|
|
|
|
|
2014-06-20 21:57:27 +02:00
|
|
|
SortedMap<EnergyValue, List<WrappedStack>> tailMap = energyValueRegistry.valueMappings.tailMap(start);
|
|
|
|
SortedMap<EnergyValue, List<WrappedStack>> headMap = energyValueRegistry.valueMappings.headMap(finish);
|
2014-06-14 21:40:45 +02:00
|
|
|
|
|
|
|
SortedMap<EnergyValue, List<WrappedStack>> smallerMap;
|
|
|
|
SortedMap<EnergyValue, List<WrappedStack>> biggerMap;
|
|
|
|
|
|
|
|
if (!tailMap.isEmpty() && !headMap.isEmpty())
|
|
|
|
{
|
|
|
|
|
|
|
|
if (tailMap.size() <= headMap.size())
|
|
|
|
{
|
|
|
|
smallerMap = tailMap;
|
|
|
|
biggerMap = headMap;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
smallerMap = headMap;
|
|
|
|
biggerMap = tailMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (EnergyValue value : smallerMap.keySet())
|
|
|
|
{
|
|
|
|
if (biggerMap.containsKey(value))
|
|
|
|
{
|
2014-06-20 21:57:27 +02:00
|
|
|
stacksInRange.addAll(energyValueRegistry.valueMappings.get(value));
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stacksInRange;
|
|
|
|
}
|
|
|
|
|
2014-07-07 17:22:21 +02:00
|
|
|
public List<WrappedStack> getStacksInRange(float start, float finish)
|
2014-06-14 21:40:45 +02:00
|
|
|
{
|
2014-07-07 17:22:21 +02:00
|
|
|
return getStacksInRange(new EnergyValue(start), new EnergyValue(finish));
|
2014-06-14 21:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ImmutableSortedMap<EnergyValue, List<WrappedStack>> getEnergyValueToStackMap()
|
|
|
|
{
|
|
|
|
return valueMappings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void dumpStackMappings()
|
|
|
|
{
|
|
|
|
for (WrappedStack wrappedStack : getStackToEnergyValueMap().keySet())
|
|
|
|
{
|
|
|
|
LogHelper.info(String.format("%s = %s", wrappedStack, getStackToEnergyValueMap().get(wrappedStack)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 17:22:21 +02:00
|
|
|
public ImmutableSortedMap<WrappedStack, EnergyValue> getStackToEnergyValueMap()
|
|
|
|
{
|
|
|
|
return stackMappings;
|
|
|
|
}
|
|
|
|
|
2014-06-14 21:40:45 +02:00
|
|
|
public void dumpValueMappings()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|