Added functionality that given two EmcValues, returns a list of stacks
that exist in the range between those two EmcValues
This commit is contained in:
parent
756e444a0a
commit
87ad92479d
|
@ -28,7 +28,6 @@ import com.pahimar.ee3.core.util.LogHelper;
|
|||
import com.pahimar.ee3.core.util.VersionHelper;
|
||||
import com.pahimar.ee3.creativetab.CreativeTabEE3;
|
||||
import com.pahimar.ee3.item.ModItems;
|
||||
import com.pahimar.ee3.item.crafting.RecipeRegistry;
|
||||
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
|
||||
import com.pahimar.ee3.lib.InterModComms;
|
||||
import com.pahimar.ee3.lib.Reference;
|
||||
|
@ -144,7 +143,7 @@ public class EquivalentExchange3 {
|
|||
MinecraftForge.EVENT_BUS.register(new ActionRequestHandler());
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new WorldTransmutationHandler());
|
||||
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new ItemTooltipEventHandler());
|
||||
|
||||
GameRegistry.registerCraftingHandler(new CraftingHandler());
|
||||
|
@ -175,8 +174,6 @@ public class EquivalentExchange3 {
|
|||
|
||||
// Initialize the Addon Handler
|
||||
AddonHandler.init();
|
||||
|
||||
LogHelper.debug(RecipeRegistry.getDiscoveredStacks().size());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
package com.pahimar.ee3.core.handlers;
|
||||
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
import com.pahimar.ee3.emc.EmcRegistry;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
/**
|
||||
* Equivalent-Exchange-3
|
||||
*
|
||||
* ItemTooltipEventHandler
|
||||
*
|
||||
* @author pahimar
|
||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
*
|
||||
*/
|
||||
public class ItemTooltipEventHandler {
|
||||
|
||||
@ForgeSubscribe
|
||||
public void handleItemTooltipEvent(ItemTooltipEvent event) {
|
||||
|
||||
if (EmcRegistry.hasEmcValue(new CustomWrappedStack(event.itemStack))) {
|
||||
event.toolTip.add("EMC: " + EmcRegistry.getEmcValue(new CustomWrappedStack(event.itemStack)).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.pahimar.ee3.core.handlers;
|
||||
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
|
||||
import com.pahimar.ee3.emc.EmcRegistry;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
/**
|
||||
* Equivalent-Exchange-3
|
||||
*
|
||||
* ItemTooltipEventHandler
|
||||
*
|
||||
* @author pahimar
|
||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||
*
|
||||
*/
|
||||
public class ItemTooltipEventHandler {
|
||||
|
||||
@ForgeSubscribe
|
||||
public void handleItemTooltipEvent(ItemTooltipEvent event) {
|
||||
|
||||
if (EmcRegistry.hasEmcValue(new CustomWrappedStack(event.itemStack))) {
|
||||
event.toolTip.add("EMC: " + EmcRegistry.getEmcValue(new CustomWrappedStack(event.itemStack)).value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,38 +11,37 @@ import com.pahimar.ee3.item.CustomWrappedStack;
|
|||
|
||||
public class EmcDefaultValues {
|
||||
|
||||
private static EmcDefaultValues defaultValues = null;
|
||||
private Map<CustomWrappedStack, EmcValue> defaultValueMap;
|
||||
private static EmcDefaultValues emcDefaultValues = null;
|
||||
private Map<CustomWrappedStack, EmcValue> valueMap;
|
||||
|
||||
private EmcDefaultValues() {
|
||||
|
||||
defaultValueMap = new HashMap<CustomWrappedStack, EmcValue>();
|
||||
valueMap = new HashMap<CustomWrappedStack, EmcValue>();
|
||||
}
|
||||
|
||||
public static EmcDefaultValues getInstance() {
|
||||
private static void lazyInit() {
|
||||
|
||||
if (defaultValues == null) {
|
||||
defaultValues = new EmcDefaultValues();
|
||||
defaultValues.init();
|
||||
if (emcDefaultValues == null) {
|
||||
emcDefaultValues = new EmcDefaultValues();
|
||||
emcDefaultValues.init();
|
||||
}
|
||||
|
||||
return defaultValues;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
defaultValueMap.put(new CustomWrappedStack(Block.cobblestone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
defaultValueMap.put(new CustomWrappedStack(Block.wood), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.ESSENTIA, 1))));
|
||||
defaultValueMap.put(new CustomWrappedStack(Block.oreIron), new EmcValue(256, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
defaultValueMap.put(new CustomWrappedStack(Block.oreGold), new EmcValue(2048, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
defaultValueMap.put(new CustomWrappedStack(Block.oreDiamond), new EmcValue(8192, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
defaultValueMap.put(new CustomWrappedStack(Block.oreCoal), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.KINETIC, 1))));
|
||||
valueMap.put(new CustomWrappedStack(Block.cobblestone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.wood), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.ESSENTIA, 1))));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreIron), new EmcValue(256, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreGold), new EmcValue(2048, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreDiamond), new EmcValue(8192, EmcComponent.CORPOREAL_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(Block.oreCoal), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.KINETIC, 1))));
|
||||
|
||||
defaultValueMap.put(new CustomWrappedStack(new EnergyStack(EnergyStack.VANILLA_SMELTING_ENERGY_NAME)), new EmcValue(defaultValueMap.get(new CustomWrappedStack(Block.oreCoal)).getComponentValueByType(EmcType.KINETIC) / (8 * EnergyStack.VANILLA_SMELTING_ENERGY_THRESHOLD), EmcComponent.KINETIC_UNIT_COMPONENT));
|
||||
valueMap.put(new CustomWrappedStack(new EnergyStack(EnergyStack.VANILLA_SMELTING_ENERGY_NAME)), new EmcValue(valueMap.get(new CustomWrappedStack(Block.oreCoal)).getComponentValueByType(EmcType.KINETIC) / (8 * EnergyStack.VANILLA_SMELTING_ENERGY_THRESHOLD), EmcComponent.KINETIC_UNIT_COMPONENT));
|
||||
}
|
||||
|
||||
public Map<CustomWrappedStack, EmcValue> getDefaultValueMap() {
|
||||
public static Map<CustomWrappedStack, EmcValue> getDefaultValueMap() {
|
||||
|
||||
return defaultValueMap;
|
||||
lazyInit();
|
||||
return emcDefaultValues.valueMap;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
package com.pahimar.ee3.emc;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.pahimar.ee3.item.CustomWrappedStack;
|
||||
|
||||
public class EmcRegistry {
|
||||
|
||||
private static EmcRegistry emcRegistry = null;
|
||||
|
||||
private Map<CustomWrappedStack, EmcValue> stackMappings;
|
||||
private SortedMap<EmcValue, List<CustomWrappedStack>> valueMappings;
|
||||
|
||||
private EmcRegistry() {
|
||||
|
||||
stackMappings = new HashMap<CustomWrappedStack, EmcValue>();
|
||||
valueMappings = new TreeMap<EmcValue, List<CustomWrappedStack>>();
|
||||
}
|
||||
private ImmutableSortedMap<CustomWrappedStack, EmcValue> stackMappings;
|
||||
private ImmutableSortedMap<EmcValue, List<CustomWrappedStack>> valueMappings;
|
||||
|
||||
private static void lazyInit() {
|
||||
|
||||
|
@ -30,19 +28,83 @@ public class EmcRegistry {
|
|||
}
|
||||
|
||||
private void init() {
|
||||
|
||||
stackMappings.putAll(EmcDefaultValues.getInstance().getDefaultValueMap());
|
||||
|
||||
ImmutableSortedMap.Builder<CustomWrappedStack, EmcValue> stackMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
||||
ImmutableSortedMap.Builder<EmcValue, List<CustomWrappedStack>> valueMappingsBuilder = ImmutableSortedMap.naturalOrder();
|
||||
|
||||
Map<CustomWrappedStack, EmcValue> defaultValues = EmcDefaultValues.getDefaultValueMap();
|
||||
|
||||
// Handle the stack mappings
|
||||
stackMappingsBuilder.putAll(defaultValues);
|
||||
stackMappings = stackMappingsBuilder.build();
|
||||
|
||||
// Handle the value mappings
|
||||
SortedMap<EmcValue, List<CustomWrappedStack>> tempValueMappings = new TreeMap<EmcValue, List<CustomWrappedStack>>();
|
||||
Set<CustomWrappedStack> stacks = defaultValues.keySet();
|
||||
Iterator<CustomWrappedStack> stackIter = stacks.iterator();
|
||||
|
||||
while (stackIter.hasNext()) {
|
||||
CustomWrappedStack stack = stackIter.next();
|
||||
EmcValue value = defaultValues.get(stack);
|
||||
|
||||
if (tempValueMappings.containsKey(value)) {
|
||||
if (!(tempValueMappings.get(value).contains(stack))) {
|
||||
tempValueMappings.get(value).add(stack);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tempValueMappings.put(value, Arrays.asList(stack));
|
||||
}
|
||||
}
|
||||
|
||||
valueMappingsBuilder.putAll(tempValueMappings);
|
||||
valueMappings = valueMappingsBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
public static boolean hasEmcValue(CustomWrappedStack stack) {
|
||||
|
||||
|
||||
lazyInit();
|
||||
return emcRegistry.stackMappings.containsKey(new CustomWrappedStack(stack.getWrappedStack()));
|
||||
}
|
||||
|
||||
|
||||
public static EmcValue getEmcValue(CustomWrappedStack stack) {
|
||||
|
||||
|
||||
lazyInit();
|
||||
return emcRegistry.stackMappings.get(new CustomWrappedStack(stack.getWrappedStack()));
|
||||
}
|
||||
|
||||
public static List<CustomWrappedStack> getStacksInRange(EmcValue start, EmcValue finish) {
|
||||
|
||||
lazyInit();
|
||||
|
||||
List<CustomWrappedStack> stacksInRange = new ArrayList<CustomWrappedStack>();
|
||||
|
||||
SortedMap<EmcValue, List<CustomWrappedStack>> tailMap = emcRegistry.valueMappings.tailMap(start);
|
||||
SortedMap<EmcValue, List<CustomWrappedStack>> headMap = emcRegistry.valueMappings.headMap(finish);
|
||||
|
||||
SortedMap<EmcValue, List<CustomWrappedStack>> smallerMap;
|
||||
SortedMap<EmcValue, List<CustomWrappedStack>> biggerMap;
|
||||
|
||||
if (!tailMap.isEmpty() && !headMap.isEmpty()) {
|
||||
|
||||
if (tailMap.size() <= headMap.size()) {
|
||||
smallerMap = tailMap;
|
||||
biggerMap = headMap;
|
||||
}
|
||||
else {
|
||||
smallerMap = headMap;
|
||||
biggerMap = tailMap;
|
||||
}
|
||||
|
||||
Iterator<EmcValue> valueIterator = smallerMap.keySet().iterator();
|
||||
while (valueIterator.hasNext()) {
|
||||
EmcValue value = valueIterator.next();
|
||||
if (biggerMap.containsKey(value)) {
|
||||
stacksInRange.addAll(emcRegistry.valueMappings.get(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stacksInRange;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue