Refactored references of Emc to EnergyValue and renamed the thread that initializes the value registry
This commit is contained in:
parent
1f726f33d9
commit
af8621f480
|
@ -1,7 +1,7 @@
|
||||||
package com.pahimar.ee3.client.handler;
|
package com.pahimar.ee3.client.handler;
|
||||||
|
|
||||||
import com.pahimar.ee3.exchange.EnergyRegistry;
|
|
||||||
import com.pahimar.ee3.exchange.EnergyValue;
|
import com.pahimar.ee3.exchange.EnergyValue;
|
||||||
|
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||||
import com.pahimar.ee3.exchange.WrappedStack;
|
import com.pahimar.ee3.exchange.WrappedStack;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
@ -21,7 +21,7 @@ import java.text.DecimalFormat;
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class ItemTooltipEventHandler
|
public class ItemTooltipEventHandler
|
||||||
{
|
{
|
||||||
private static DecimalFormat emcDecimalFormat = new DecimalFormat("###,###,###,###,###.###");
|
private static DecimalFormat energyValueDecimalFormat = new DecimalFormat("###,###,###,###,###.###");
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void handleItemTooltipEvent(ItemTooltipEvent event)
|
public void handleItemTooltipEvent(ItemTooltipEvent event)
|
||||||
|
@ -30,22 +30,22 @@ public class ItemTooltipEventHandler
|
||||||
{
|
{
|
||||||
WrappedStack stack = new WrappedStack(event.itemStack);
|
WrappedStack stack = new WrappedStack(event.itemStack);
|
||||||
|
|
||||||
if (EnergyRegistry.getInstance().hasEnergyValue(stack))
|
if (EnergyValueRegistry.getInstance().hasEnergyValue(stack))
|
||||||
{
|
{
|
||||||
EnergyValue emcValue = EnergyRegistry.getInstance().getEnergyValue(stack);
|
EnergyValue energyValue = EnergyValueRegistry.getInstance().getEnergyValue(stack);
|
||||||
if (stack.getStackSize() > 1)
|
if (stack.getStackSize() > 1)
|
||||||
{
|
{
|
||||||
event.toolTip.add("EMC (Item): " + String.format("%s", emcDecimalFormat.format(emcValue.getValue())));
|
event.toolTip.add("Exchange Energy (Item): " + String.format("%s", energyValueDecimalFormat.format(energyValue.getValue())));
|
||||||
event.toolTip.add("EMC (Stack): " + String.format("%s", emcDecimalFormat.format(stack.getStackSize() * emcValue.getValue())));
|
event.toolTip.add("Exchange Energy (Stack): " + String.format("%s", energyValueDecimalFormat.format(stack.getStackSize() * energyValue.getValue())));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.toolTip.add("EMC: " + String.format("%s", emcDecimalFormat.format(stack.getStackSize() * emcValue.getValue())));
|
event.toolTip.add("Exchange Energy: " + String.format("%s", energyValueDecimalFormat.format(stack.getStackSize() * energyValue.getValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.toolTip.add("No EMC value");
|
event.toolTip.add("No Exchange Energy value");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class EnergyComponent implements Comparable<EnergyComponent>
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("<EMC Type: %s, Weight: %s>", type, weight);
|
return String.format("<Energy Type: %s, Weight: %s>", type, weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -10,29 +10,29 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class EnergyValuesDefault
|
public class EnergyDefaultValues
|
||||||
{
|
{
|
||||||
private static EnergyValuesDefault emcDefaultValues = null;
|
private static EnergyDefaultValues energyDefaultValues = null;
|
||||||
private Map<WrappedStack, EnergyValue> valueMap;
|
private Map<WrappedStack, EnergyValue> valueMap;
|
||||||
|
|
||||||
private EnergyValuesDefault()
|
private EnergyDefaultValues()
|
||||||
{
|
{
|
||||||
valueMap = new HashMap<WrappedStack, EnergyValue>();
|
valueMap = new HashMap<WrappedStack, EnergyValue>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void lazyInit()
|
private static void lazyInit()
|
||||||
{
|
{
|
||||||
if (emcDefaultValues == null)
|
if (energyDefaultValues == null)
|
||||||
{
|
{
|
||||||
emcDefaultValues = new EnergyValuesDefault();
|
energyDefaultValues = new EnergyDefaultValues();
|
||||||
emcDefaultValues.init();
|
energyDefaultValues.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<WrappedStack, EnergyValue> getDefaultValueMap()
|
public static Map<WrappedStack, EnergyValue> getDefaultValueMap()
|
||||||
{
|
{
|
||||||
lazyInit();
|
lazyInit();
|
||||||
return emcDefaultValues.valueMap;
|
return energyDefaultValues.valueMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
|
@ -10,13 +10,6 @@ import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
|
||||||
* Equivalent-Exchange-3
|
|
||||||
* <p/>
|
|
||||||
* EMCEntry
|
|
||||||
*
|
|
||||||
* @author pahimar
|
|
||||||
*/
|
|
||||||
public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<EnergyValue>, JsonSerializer<EnergyValue>
|
public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<EnergyValue>, JsonSerializer<EnergyValue>
|
||||||
{
|
{
|
||||||
// Gson serializer for serializing to/deserializing from json
|
// Gson serializer for serializing to/deserializing from json
|
||||||
|
@ -118,18 +111,18 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
|
||||||
/**
|
/**
|
||||||
* Deserializes an EnergyValue object from the given serialized json String
|
* Deserializes an EnergyValue object from the given serialized json String
|
||||||
*
|
*
|
||||||
* @param jsonEmcValue
|
* @param jsonEnergyValue
|
||||||
* Json encoded String representing a EnergyValue object
|
* Json encoded String representing a EnergyValue object
|
||||||
*
|
*
|
||||||
* @return The EnergyValue that was encoded as json, or null if a valid EnergyValue could not be decoded from given
|
* @return The EnergyValue that was encoded as json, or null if a valid EnergyValue could not be decoded from given
|
||||||
* String
|
* String
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static EnergyValue createFromJson(String jsonEmcValue)
|
public static EnergyValue createFromJson(String jsonEnergyValue)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return gsonSerializer.fromJson(jsonEmcValue, EnergyValue.class);
|
return gsonSerializer.fromJson(jsonEnergyValue, EnergyValue.class);
|
||||||
}
|
}
|
||||||
catch (JsonSyntaxException exception)
|
catch (JsonSyntaxException exception)
|
||||||
{
|
{
|
||||||
|
@ -250,11 +243,11 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(EnergyValue energyValue)
|
public int compareTo(EnergyValue exchangeEnergyValue)
|
||||||
{
|
{
|
||||||
if (energyValue != null)
|
if (exchangeEnergyValue != null)
|
||||||
{
|
{
|
||||||
return compareComponents(this.components, energyValue.components);
|
return compareComponents(this.components, exchangeEnergyValue.components);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -273,32 +266,32 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JsonElement serialize(EnergyValue energyValue, Type type, JsonSerializationContext context)
|
public JsonElement serialize(EnergyValue exchangeEnergyValue, Type type, JsonSerializationContext context)
|
||||||
{
|
{
|
||||||
JsonObject jsonEmcValue = new JsonObject();
|
JsonObject jsonEnergyValue = new JsonObject();
|
||||||
|
|
||||||
for (EnergyType energyType : EnergyType.TYPES)
|
for (EnergyType energyType : EnergyType.TYPES)
|
||||||
{
|
{
|
||||||
jsonEmcValue.addProperty(energyType.toString(), energyValue.components[energyType.ordinal()]);
|
jsonEnergyValue.addProperty(energyType.toString(), exchangeEnergyValue.components[energyType.ordinal()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonEmcValue;
|
return jsonEnergyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnergyValue deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException
|
public EnergyValue deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException
|
||||||
{
|
{
|
||||||
|
|
||||||
float[] emcValueComponents = new float[EnergyType.TYPES.length];
|
float[] energyValueComponents = new float[EnergyType.TYPES.length];
|
||||||
JsonObject jsonEmcValue = (JsonObject) jsonElement;
|
JsonObject jsonEnergyValue = (JsonObject) jsonElement;
|
||||||
|
|
||||||
for (EnergyType energyType : EnergyType.TYPES)
|
for (EnergyType energyType : EnergyType.TYPES)
|
||||||
{
|
{
|
||||||
if ((jsonEmcValue.get(energyType.toString()) != null) && (jsonEmcValue.get(energyType.toString()).isJsonPrimitive()))
|
if ((jsonEnergyValue.get(energyType.toString()) != null) && (jsonEnergyValue.get(energyType.toString()).isJsonPrimitive()))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
emcValueComponents[energyType.ordinal()] = jsonEmcValue.get(energyType.toString()).getAsFloat();
|
energyValueComponents[energyType.ordinal()] = jsonEnergyValue.get(energyType.toString()).getAsFloat();
|
||||||
}
|
}
|
||||||
catch (UnsupportedOperationException exception)
|
catch (UnsupportedOperationException exception)
|
||||||
{
|
{
|
||||||
|
@ -307,11 +300,11 @@ public class EnergyValue implements Comparable<EnergyValue>, JsonDeserializer<En
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnergyValue energyValue = new EnergyValue(emcValueComponents);
|
EnergyValue exchangeEnergyValue = new EnergyValue(energyValueComponents);
|
||||||
|
|
||||||
if (energyValue.getValue() > 0f)
|
if (exchangeEnergyValue.getValue() > 0f)
|
||||||
{
|
{
|
||||||
return energyValue;
|
return exchangeEnergyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.pahimar.ee3.exchange;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
import com.pahimar.ee3.recipe.RecipeRegistry;
|
import com.pahimar.ee3.recipe.RecipeRegistry;
|
||||||
|
import com.pahimar.ee3.util.EnergyValueHelper;
|
||||||
import com.pahimar.ee3.util.LogHelper;
|
import com.pahimar.ee3.util.LogHelper;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -9,26 +10,26 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class EnergyRegistry
|
public class EnergyValueRegistry
|
||||||
{
|
{
|
||||||
private static EnergyRegistry energyRegistry = null;
|
private static EnergyValueRegistry energyValueRegistry = null;
|
||||||
|
|
||||||
private ImmutableSortedMap<WrappedStack, EnergyValue> stackMappings;
|
private ImmutableSortedMap<WrappedStack, EnergyValue> stackMappings;
|
||||||
private ImmutableSortedMap<EnergyValue, List<WrappedStack>> valueMappings;
|
private ImmutableSortedMap<EnergyValue, List<WrappedStack>> valueMappings;
|
||||||
|
|
||||||
private EnergyRegistry()
|
private EnergyValueRegistry()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnergyRegistry getInstance()
|
public static EnergyValueRegistry getInstance()
|
||||||
{
|
{
|
||||||
if (energyRegistry == null)
|
if (energyValueRegistry == null)
|
||||||
{
|
{
|
||||||
energyRegistry = new EnergyRegistry();
|
energyValueRegistry = new EnergyValueRegistry();
|
||||||
energyRegistry.init();
|
energyValueRegistry.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
return energyRegistry;
|
return energyValueRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
|
@ -38,33 +39,33 @@ public class EnergyRegistry
|
||||||
/*
|
/*
|
||||||
* Default values
|
* Default values
|
||||||
*/
|
*/
|
||||||
Map<WrappedStack, EnergyValue> defaultValuesMap = EnergyValuesDefault.getDefaultValueMap();
|
Map<WrappedStack, EnergyValue> defaultValuesMap = EnergyDefaultValues.getDefaultValueMap();
|
||||||
for (WrappedStack keyStack : defaultValuesMap.keySet())
|
for (WrappedStack keyStack : defaultValuesMap.keySet())
|
||||||
{
|
{
|
||||||
EnergyValue factoredEnergyValue = null;
|
EnergyValue factoredExchangeEnergyValue = null;
|
||||||
WrappedStack factoredKeyStack = null;
|
WrappedStack factoredKeyStack = null;
|
||||||
|
|
||||||
if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
||||||
{
|
{
|
||||||
if (defaultValuesMap.get(keyStack) != null && Float.compare(defaultValuesMap.get(keyStack).getValue(), 0f) > 0)
|
if (defaultValuesMap.get(keyStack) != null && Float.compare(defaultValuesMap.get(keyStack).getValue(), 0f) > 0)
|
||||||
{
|
{
|
||||||
factoredEnergyValue = EnergyHelper.factorEnergyValue(defaultValuesMap.get(keyStack), keyStack.getStackSize());
|
factoredExchangeEnergyValue = EnergyValueHelper.factorEnergyValue(defaultValuesMap.get(keyStack), keyStack.getStackSize());
|
||||||
factoredKeyStack = new WrappedStack(keyStack, 1);
|
factoredKeyStack = new WrappedStack(keyStack, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factoredEnergyValue != null)
|
if (factoredExchangeEnergyValue != null)
|
||||||
{
|
{
|
||||||
if (stackValueMap.containsKey(factoredKeyStack))
|
if (stackValueMap.containsKey(factoredKeyStack))
|
||||||
{
|
{
|
||||||
if (factoredEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
if (factoredExchangeEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
||||||
{
|
{
|
||||||
stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,7 +83,7 @@ public class EnergyRegistry
|
||||||
// {
|
// {
|
||||||
// if (preAssignedValuesMap.get(keyStack) != null && Float.compare(preAssignedValuesMap.get(keyStack).getValue(), 0f) > 0)
|
// if (preAssignedValuesMap.get(keyStack) != null && Float.compare(preAssignedValuesMap.get(keyStack).getValue(), 0f) > 0)
|
||||||
// {
|
// {
|
||||||
// factoredEnergyValue = EmcHelper.factorEnergyValue(preAssignedValuesMap.get(keyStack), keyStack.getStackSize());
|
// factoredEnergyValue = EnergyValueHelper.factorEnergyValue(preAssignedValuesMap.get(keyStack), keyStack.getStackSize());
|
||||||
// factoredKeyStack = new WrappedStack(keyStack, 1);
|
// factoredKeyStack = new WrappedStack(keyStack, 1);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
@ -129,30 +130,30 @@ public class EnergyRegistry
|
||||||
computedStackValues = computeStackMappings();
|
computedStackValues = computeStackMappings();
|
||||||
for (WrappedStack keyStack : computedStackValues.keySet())
|
for (WrappedStack keyStack : computedStackValues.keySet())
|
||||||
{
|
{
|
||||||
EnergyValue factoredEnergyValue = null;
|
EnergyValue factoredExchangeEnergyValue = null;
|
||||||
WrappedStack factoredKeyStack = null;
|
WrappedStack factoredKeyStack = null;
|
||||||
|
|
||||||
if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
if (keyStack != null && keyStack.getWrappedStack() != null && keyStack.getStackSize() > 0)
|
||||||
{
|
{
|
||||||
if (computedStackValues.get(keyStack) != null && Float.compare(computedStackValues.get(keyStack).getValue(), 0f) > 0)
|
if (computedStackValues.get(keyStack) != null && Float.compare(computedStackValues.get(keyStack).getValue(), 0f) > 0)
|
||||||
{
|
{
|
||||||
factoredEnergyValue = EnergyHelper.factorEnergyValue(computedStackValues.get(keyStack), keyStack.getStackSize());
|
factoredExchangeEnergyValue = EnergyValueHelper.factorEnergyValue(computedStackValues.get(keyStack), keyStack.getStackSize());
|
||||||
factoredKeyStack = new WrappedStack(keyStack, 1);
|
factoredKeyStack = new WrappedStack(keyStack, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factoredEnergyValue != null)
|
if (factoredExchangeEnergyValue != null)
|
||||||
{
|
{
|
||||||
if (stackValueMap.containsKey(factoredKeyStack))
|
if (stackValueMap.containsKey(factoredKeyStack))
|
||||||
{
|
{
|
||||||
if (factoredEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
if (factoredExchangeEnergyValue.compareTo(stackValueMap.get(factoredKeyStack)) == -1)
|
||||||
{
|
{
|
||||||
stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stackValueMap.put(factoredKeyStack, factoredEnergyValue);
|
stackValueMap.put(factoredKeyStack, factoredExchangeEnergyValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,8 +234,8 @@ public class EnergyRegistry
|
||||||
|
|
||||||
for (List<WrappedStack> recipeInputs : RecipeRegistry.getInstance().getRecipeMappings().get(recipeOutput))
|
for (List<WrappedStack> recipeInputs : RecipeRegistry.getInstance().getRecipeMappings().get(recipeOutput))
|
||||||
{
|
{
|
||||||
EnergyValue computedValue = EnergyHelper.computeEnergyValueFromList(recipeInputs);
|
EnergyValue computedValue = EnergyValueHelper.computeEnergyValueFromList(recipeInputs);
|
||||||
computedValue = EnergyHelper.factorEnergyValue(computedValue, recipeOutput.getStackSize());
|
computedValue = EnergyValueHelper.factorEnergyValue(computedValue, recipeOutput.getStackSize());
|
||||||
|
|
||||||
if (computedValue != null)
|
if (computedValue != null)
|
||||||
{
|
{
|
||||||
|
@ -261,7 +262,7 @@ public class EnergyRegistry
|
||||||
{
|
{
|
||||||
WrappedStack stack = new WrappedStack(object);
|
WrappedStack stack = new WrappedStack(object);
|
||||||
|
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -274,12 +275,12 @@ public class EnergyRegistry
|
||||||
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
|
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
|
||||||
|
|
||||||
// If its an OreDictionary item, scan its siblings for values
|
// If its an OreDictionary item, scan its siblings for values
|
||||||
if (OreDictionary.getOreID(wrappedItemStack) != -1)
|
if (OreDictionary.getOreIDs(wrappedItemStack).length > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
OreStack oreStack = new OreStack(wrappedItemStack);
|
OreStack oreStack = new OreStack(wrappedItemStack);
|
||||||
|
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -287,7 +288,7 @@ public class EnergyRegistry
|
||||||
{
|
{
|
||||||
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
|
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
|
||||||
{
|
{
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -297,7 +298,7 @@ public class EnergyRegistry
|
||||||
// Else, scan for if there is a wildcard value for it
|
// Else, scan for if there is a wildcard value for it
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (WrappedStack valuedStack : energyRegistry.stackMappings.keySet())
|
for (WrappedStack valuedStack : energyValueRegistry.stackMappings.keySet())
|
||||||
{
|
{
|
||||||
if (valuedStack.getWrappedStack() instanceof ItemStack)
|
if (valuedStack.getWrappedStack() instanceof ItemStack)
|
||||||
{
|
{
|
||||||
|
@ -323,7 +324,7 @@ public class EnergyRegistry
|
||||||
OreStack oreStack = (OreStack) stack.getWrappedStack();
|
OreStack oreStack = (OreStack) stack.getWrappedStack();
|
||||||
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
|
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
|
||||||
{
|
{
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -347,9 +348,9 @@ public class EnergyRegistry
|
||||||
{
|
{
|
||||||
WrappedStack stack = new WrappedStack(object);
|
WrappedStack stack = new WrappedStack(object);
|
||||||
|
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(stack.getWrappedStack())))
|
||||||
{
|
{
|
||||||
return energyRegistry.stackMappings.get(new WrappedStack(stack.getWrappedStack()));
|
return energyValueRegistry.stackMappings.get(new WrappedStack(stack.getWrappedStack()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -360,27 +361,27 @@ public class EnergyRegistry
|
||||||
EnergyValue lowestValue = null;
|
EnergyValue lowestValue = null;
|
||||||
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
|
ItemStack wrappedItemStack = (ItemStack) stack.getWrappedStack();
|
||||||
|
|
||||||
if (OreDictionary.getOreID(wrappedItemStack) != -1)
|
if (OreDictionary.getOreIDs(wrappedItemStack).length > 0)
|
||||||
{
|
{
|
||||||
OreStack oreStack = new OreStack(wrappedItemStack);
|
OreStack oreStack = new OreStack(wrappedItemStack);
|
||||||
|
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreStack)))
|
||||||
{
|
{
|
||||||
return energyRegistry.stackMappings.get(new WrappedStack(oreStack));
|
return energyValueRegistry.stackMappings.get(new WrappedStack(oreStack));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
|
for (ItemStack itemStack : OreDictionary.getOres(OreDictionary.getOreID(wrappedItemStack)))
|
||||||
{
|
{
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(itemStack)))
|
||||||
{
|
{
|
||||||
if (lowestValue == null)
|
if (lowestValue == null)
|
||||||
{
|
{
|
||||||
lowestValue = energyRegistry.stackMappings.get(new WrappedStack(itemStack));
|
lowestValue = energyValueRegistry.stackMappings.get(new WrappedStack(itemStack));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
EnergyValue itemValue = energyRegistry.stackMappings.get(new WrappedStack(itemStack));
|
EnergyValue itemValue = energyValueRegistry.stackMappings.get(new WrappedStack(itemStack));
|
||||||
|
|
||||||
if (itemValue.compareTo(lowestValue) < 0)
|
if (itemValue.compareTo(lowestValue) < 0)
|
||||||
{
|
{
|
||||||
|
@ -395,7 +396,7 @@ public class EnergyRegistry
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (WrappedStack valuedStack : energyRegistry.stackMappings.keySet())
|
for (WrappedStack valuedStack : energyValueRegistry.stackMappings.keySet())
|
||||||
{
|
{
|
||||||
if (valuedStack.getWrappedStack() instanceof ItemStack)
|
if (valuedStack.getWrappedStack() instanceof ItemStack)
|
||||||
{
|
{
|
||||||
|
@ -405,7 +406,7 @@ public class EnergyRegistry
|
||||||
{
|
{
|
||||||
if (valuedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
|
if (valuedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE || wrappedItemStack.getItemDamage() == OreDictionary.WILDCARD_VALUE)
|
||||||
{
|
{
|
||||||
EnergyValue stackValue = energyRegistry.stackMappings.get(valuedStack);
|
EnergyValue stackValue = energyValueRegistry.stackMappings.get(valuedStack);
|
||||||
|
|
||||||
if (stackValue.compareTo(lowestValue) < 0)
|
if (stackValue.compareTo(lowestValue) < 0)
|
||||||
{
|
{
|
||||||
|
@ -414,7 +415,7 @@ public class EnergyRegistry
|
||||||
}
|
}
|
||||||
else if (wrappedItemStack.getItem().isDamageable() && wrappedItemStack.isItemDamaged())
|
else if (wrappedItemStack.getItem().isDamageable() && wrappedItemStack.isItemDamaged())
|
||||||
{
|
{
|
||||||
EnergyValue stackValue = new EnergyValue(energyRegistry.stackMappings.get(valuedStack).getValue() * (1 - (wrappedItemStack.getItemDamage() * 1.0F / wrappedItemStack.getMaxDamage())));
|
EnergyValue stackValue = new EnergyValue(energyValueRegistry.stackMappings.get(valuedStack).getValue() * (1 - (wrappedItemStack.getItemDamage() * 1.0F / wrappedItemStack.getMaxDamage())));
|
||||||
|
|
||||||
if (stackValue.compareTo(lowestValue) < 0)
|
if (stackValue.compareTo(lowestValue) < 0)
|
||||||
{
|
{
|
||||||
|
@ -433,9 +434,9 @@ public class EnergyRegistry
|
||||||
OreStack oreStack = (OreStack) stack.getWrappedStack();
|
OreStack oreStack = (OreStack) stack.getWrappedStack();
|
||||||
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
|
for (ItemStack oreItemStack : OreDictionary.getOres(oreStack.oreName))
|
||||||
{
|
{
|
||||||
if (energyRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
|
if (energyValueRegistry.stackMappings.containsKey(new WrappedStack(oreItemStack)))
|
||||||
{
|
{
|
||||||
return energyRegistry.stackMappings.get(new WrappedStack(oreItemStack));
|
return energyValueRegistry.stackMappings.get(new WrappedStack(oreItemStack));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,8 +467,8 @@ public class EnergyRegistry
|
||||||
{
|
{
|
||||||
List<WrappedStack> stacksInRange = new ArrayList<WrappedStack>();
|
List<WrappedStack> stacksInRange = new ArrayList<WrappedStack>();
|
||||||
|
|
||||||
SortedMap<EnergyValue, List<WrappedStack>> tailMap = energyRegistry.valueMappings.tailMap(start);
|
SortedMap<EnergyValue, List<WrappedStack>> tailMap = energyValueRegistry.valueMappings.tailMap(start);
|
||||||
SortedMap<EnergyValue, List<WrappedStack>> headMap = energyRegistry.valueMappings.headMap(finish);
|
SortedMap<EnergyValue, List<WrappedStack>> headMap = energyValueRegistry.valueMappings.headMap(finish);
|
||||||
|
|
||||||
SortedMap<EnergyValue, List<WrappedStack>> smallerMap;
|
SortedMap<EnergyValue, List<WrappedStack>> smallerMap;
|
||||||
SortedMap<EnergyValue, List<WrappedStack>> biggerMap;
|
SortedMap<EnergyValue, List<WrappedStack>> biggerMap;
|
||||||
|
@ -490,7 +491,7 @@ public class EnergyRegistry
|
||||||
{
|
{
|
||||||
if (biggerMap.containsKey(value))
|
if (biggerMap.containsKey(value))
|
||||||
{
|
{
|
||||||
stacksInRange.addAll(energyRegistry.valueMappings.get(value));
|
stacksInRange.addAll(energyValueRegistry.valueMappings.get(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,8 +17,6 @@ public class OreStack implements Comparable<OreStack>
|
||||||
// Gson serializer for serializing to/deserializing from json
|
// Gson serializer for serializing to/deserializing from json
|
||||||
private static final Gson gsonSerializer = new Gson();
|
private static final Gson gsonSerializer = new Gson();
|
||||||
|
|
||||||
private static final int ORE_DICTIONARY_NOT_FOUND = -1;
|
|
||||||
|
|
||||||
public String oreName;
|
public String oreName;
|
||||||
public int stackSize;
|
public int stackSize;
|
||||||
public static Comparator<OreStack> comparator = new Comparator<OreStack>()
|
public static Comparator<OreStack> comparator = new Comparator<OreStack>()
|
||||||
|
@ -133,7 +131,7 @@ public class OreStack implements Comparable<OreStack>
|
||||||
{
|
{
|
||||||
ItemStack stack = (ItemStack) listElement;
|
ItemStack stack = (ItemStack) listElement;
|
||||||
|
|
||||||
if (OreDictionary.getOreID(stack) != ORE_DICTIONARY_NOT_FOUND)
|
if (OreDictionary.getOreIDs(stack).length > 0)
|
||||||
{
|
{
|
||||||
return new OreStack(stack);
|
return new OreStack(stack);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.pahimar.ee3.handler;
|
package com.pahimar.ee3.handler;
|
||||||
|
|
||||||
import com.pahimar.ee3.util.EmcInitializationHelper;
|
import com.pahimar.ee3.thread.DynamicEnergyValueInitThread;
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraftforge.event.world.WorldEvent;
|
import net.minecraftforge.event.world.WorldEvent;
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ public class WorldEventHandler
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onWorldLoadEvent(WorldEvent.Load event)
|
public void onWorldLoadEvent(WorldEvent.Load event)
|
||||||
{
|
{
|
||||||
EmcInitializationHelper.initEmcRegistry();
|
DynamicEnergyValueInitThread.initEnergyValueRegistry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.pahimar.ee3.thread;
|
||||||
|
|
||||||
|
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||||
|
import com.pahimar.ee3.util.LogHelper;
|
||||||
|
|
||||||
|
public class DynamicEnergyValueInitThread implements Runnable
|
||||||
|
{
|
||||||
|
private static DynamicEnergyValueInitThread instance = new DynamicEnergyValueInitThread();
|
||||||
|
|
||||||
|
public static void initEnergyValueRegistry()
|
||||||
|
{
|
||||||
|
new Thread(instance, "DynamicEV Thread").start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
EnergyValueRegistry.getInstance();
|
||||||
|
long duration = System.currentTimeMillis() - startTime;
|
||||||
|
if (duration > 10)
|
||||||
|
{
|
||||||
|
LogHelper.info(String.format("DynamicEV system initialized after %s ms", duration));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
package com.pahimar.ee3.util;
|
|
||||||
|
|
||||||
import com.pahimar.ee3.exchange.EnergyRegistry;
|
|
||||||
|
|
||||||
public class EmcInitializationHelper implements Runnable
|
|
||||||
{
|
|
||||||
private static EmcInitializationHelper instance = new EmcInitializationHelper();
|
|
||||||
|
|
||||||
public static void initEmcRegistry()
|
|
||||||
{
|
|
||||||
new Thread(instance, "EE3 - DynEmc Init Thread").start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
EnergyRegistry.getInstance();
|
|
||||||
long duration = System.currentTimeMillis() - startTime;
|
|
||||||
if (duration > 10)
|
|
||||||
{
|
|
||||||
LogHelper.info(String.format("DynEmc system initialized after %s ms", duration));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,23 +1,27 @@
|
||||||
package com.pahimar.ee3.exchange;
|
package com.pahimar.ee3.util;
|
||||||
|
|
||||||
|
import com.pahimar.ee3.exchange.EnergyType;
|
||||||
|
import com.pahimar.ee3.exchange.EnergyValue;
|
||||||
|
import com.pahimar.ee3.exchange.EnergyValueRegistry;
|
||||||
|
import com.pahimar.ee3.exchange.WrappedStack;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EnergyHelper
|
public class EnergyValueHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
public static List<WrappedStack> filterStacksByEmc(List<WrappedStack> unfilteredStacks, EnergyValue filterValue)
|
public static List<WrappedStack> filterStacksByEnergyValue(List<WrappedStack> unfilteredStacks, EnergyValue filterValue)
|
||||||
{
|
{
|
||||||
List<WrappedStack> filteredStacks = new ArrayList<WrappedStack>();
|
List<WrappedStack> filteredStacks = new ArrayList<WrappedStack>();
|
||||||
|
|
||||||
for (WrappedStack stack : unfilteredStacks)
|
for (WrappedStack stack : unfilteredStacks)
|
||||||
{
|
{
|
||||||
if (EnergyRegistry.getInstance().hasEnergyValue(stack))
|
if (EnergyValueRegistry.getInstance().hasEnergyValue(stack))
|
||||||
{
|
{
|
||||||
EnergyValue value = EnergyRegistry.getInstance().getEnergyValue(stack);
|
EnergyValue value = EnergyValueRegistry.getInstance().getEnergyValue(stack);
|
||||||
boolean satisfiesFilter = true;
|
boolean satisfiesFilter = true;
|
||||||
float[] valueSubValues = value.components;
|
float[] valueSubValues = value.components;
|
||||||
float[] filterValueSubValues = filterValue.components;
|
float[] filterValueSubValues = filterValue.components;
|
||||||
|
@ -41,9 +45,9 @@ public class EnergyHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public static List<WrappedStack> filterStacksByEmcAndRange(float start, float end, EnergyValue filterValue)
|
public static List<WrappedStack> filterStacksByEnergyValue(float start, float end, EnergyValue filterValue)
|
||||||
{
|
{
|
||||||
return filterStacksByEmc(EnergyRegistry.getInstance().getStacksInRange(start, end), filterValue);
|
return filterStacksByEnergyValue(EnergyValueRegistry.getInstance().getStacksInRange(start, end), filterValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnergyValue computeEnergyValueFromList(List<WrappedStack> wrappedStacks)
|
public static EnergyValue computeEnergyValueFromList(List<WrappedStack> wrappedStacks)
|
||||||
|
@ -64,11 +68,11 @@ public class EnergyHelper
|
||||||
if (itemStack.getItem().getContainerItem(itemStack) != null)
|
if (itemStack.getItem().getContainerItem(itemStack) != null)
|
||||||
{
|
{
|
||||||
stackSize = FluidContainerRegistry.getFluidForFilledItem(itemStack).amount;
|
stackSize = FluidContainerRegistry.getFluidForFilledItem(itemStack).amount;
|
||||||
wrappedStackValue = EnergyRegistry.getInstance().getEnergyValue(FluidContainerRegistry.getFluidForFilledItem(itemStack));
|
wrappedStackValue = EnergyValueRegistry.getInstance().getEnergyValue(FluidContainerRegistry.getFluidForFilledItem(itemStack));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wrappedStackValue = EnergyRegistry.getInstance().getEnergyValue(wrappedStack);
|
wrappedStackValue = EnergyValueRegistry.getInstance().getEnergyValue(wrappedStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we are dealing with a "tool" (container item), assume it's value is 0 (since it won't be used up in the recipe)
|
// If we are dealing with a "tool" (container item), assume it's value is 0 (since it won't be used up in the recipe)
|
||||||
|
@ -78,12 +82,12 @@ public class EnergyHelper
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wrappedStackValue = EnergyRegistry.getInstance().getEnergyValue(wrappedStack);
|
wrappedStackValue = EnergyValueRegistry.getInstance().getEnergyValue(wrappedStack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wrappedStackValue = EnergyRegistry.getInstance().getEnergyValue(wrappedStack);
|
wrappedStackValue = EnergyValueRegistry.getInstance().getEnergyValue(wrappedStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wrappedStackValue != null)
|
if (wrappedStackValue != null)
|
||||||
|
@ -93,9 +97,9 @@ public class EnergyHelper
|
||||||
stackSize = wrappedStack.getStackSize();
|
stackSize = wrappedStack.getStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (EnergyType emcType : EnergyType.TYPES)
|
for (EnergyType energyType : EnergyType.TYPES)
|
||||||
{
|
{
|
||||||
computedSubValues[emcType.ordinal()] += wrappedStackValue.components[emcType.ordinal()] * stackSize;
|
computedSubValues[energyType.ordinal()] += wrappedStackValue.components[energyType.ordinal()] * stackSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -107,17 +111,17 @@ public class EnergyHelper
|
||||||
return new EnergyValue(computedSubValues);
|
return new EnergyValue(computedSubValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnergyValue factorEnergyValue(EnergyValue EnergyValue, int factor)
|
public static EnergyValue factorEnergyValue(EnergyValue ExchangeEnergyValue, int factor)
|
||||||
{
|
{
|
||||||
return factorEnergyValue(EnergyValue, (float) factor);
|
return factorEnergyValue(ExchangeEnergyValue, (float) factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnergyValue factorEnergyValue(EnergyValue EnergyValue, float factor)
|
public static EnergyValue factorEnergyValue(EnergyValue ExchangeEnergyValue, float factor)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((Float.compare(factor, 0f) != 0) && (EnergyValue != null))
|
if ((Float.compare(factor, 0f) != 0) && (ExchangeEnergyValue != null))
|
||||||
{
|
{
|
||||||
float[] factorSubValues = EnergyValue.components;
|
float[] factorSubValues = ExchangeEnergyValue.components;
|
||||||
|
|
||||||
for (int i = 0; i < factorSubValues.length; i++)
|
for (int i = 0; i < factorSubValues.length; i++)
|
||||||
{
|
{
|
||||||
|
@ -128,7 +132,7 @@ public class EnergyHelper
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return EnergyValue;
|
return ExchangeEnergyValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue