Some auto resolution of emc values, but loads of work still to be done

This commit is contained in:
pahimar 2013-10-18 01:23:11 -04:00
parent 576a90e50d
commit 7b3a8f3f09
5 changed files with 123 additions and 24 deletions

View file

@ -26,6 +26,8 @@ import com.pahimar.ee3.core.helper.LogHelper;
import com.pahimar.ee3.core.helper.VersionHelper;
import com.pahimar.ee3.core.proxy.CommonProxy;
import com.pahimar.ee3.creativetab.CreativeTabEE3;
import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.ModItems;
import com.pahimar.ee3.item.crafting.RecipesAlchemicalBagDyes;
import com.pahimar.ee3.lib.InterModComms;
@ -170,6 +172,8 @@ public class EquivalentExchange3 {
// Initialize the Addon Handler
AddonHandler.init();
EmcRegistry.hasEmcValue(new CustomWrappedStack(Block.wood));
}
@EventHandler

View file

@ -1,10 +1,15 @@
package com.pahimar.ee3.core.handlers;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import com.pahimar.ee3.emc.EmcComponent;
import com.pahimar.ee3.emc.EmcRegistry;
import com.pahimar.ee3.emc.EmcValue;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.OreStack;
import com.pahimar.ee3.item.crafting.RecipeRegistry;
/**
* Equivalent-Exchange-3
@ -16,12 +21,34 @@ import com.pahimar.ee3.item.CustomWrappedStack;
*
*/
public class ItemTooltipEventHandler {
private static boolean debug = true;
@ForgeSubscribe
public void handleItemTooltipEvent(ItemTooltipEvent event) {
if (EmcRegistry.hasEmcValue(new CustomWrappedStack(event.itemStack))) {
event.toolTip.add("EMC: " + EmcRegistry.getEmcValue(new CustomWrappedStack(event.itemStack)).value);
CustomWrappedStack stack = new CustomWrappedStack(event.itemStack);
if (debug) {
event.toolTip.add(EnumChatFormatting.AQUA + "ID: " + event.itemStack.itemID + ", Meta: " + event.itemStack.getItemDamage());
if (stack.getWrappedStack() instanceof OreStack) {
event.toolTip.add(EnumChatFormatting.AQUA + "OreDictionary Item");
}
if (RecipeRegistry.getRecipeMappings().containsKey(stack)) {
event.toolTip.add(EnumChatFormatting.AQUA + "Made from a recipe");
}
}
if (EmcRegistry.hasEmcValue(stack)) {
EmcValue emcValue = EmcRegistry.getEmcValue(stack);
event.toolTip.add("");
event.toolTip.add("EMC: " + emcValue.value);
if (debug) {
for (EmcComponent emcComponent : emcValue.getComponents()) {
event.toolTip.add(" * " + emcComponent.getType() + ": " + emcValue.getComponentValueByType(emcComponent.getType()));
}
}
}
}
}

View file

@ -40,5 +40,4 @@ public class EmcHelper {
public static List<CustomWrappedStack> filterStacksByEmcAndRange(float start, float end, EmcValue filterValue) {
return filterStacksByEmc(EmcRegistry.getStacksInRange(start, end), filterValue);
}
}
}

View file

@ -1,13 +1,17 @@
package com.pahimar.ee3.emc;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.EnergyStack;
import com.pahimar.ee3.item.crafting.RecipeRegistry;
public class EmcDefaultValues {
@ -29,15 +33,90 @@ public class EmcDefaultValues {
private void init() {
valueMap.put(new CustomWrappedStack(Block.stone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
valueMap.put(new CustomWrappedStack(Block.grass), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
valueMap.put(new CustomWrappedStack(Block.dirt), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
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.sand), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
valueMap.put(new CustomWrappedStack(Block.leaves), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
valueMap.put(new CustomWrappedStack(Block.glass), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
valueMap.put(new CustomWrappedStack(Block.tallGrass), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
for (int meta = 0; meta < 16; meta ++) {
valueMap.put(new CustomWrappedStack(new ItemStack(Block.tallGrass.blockID, 1, meta)), new EmcValue(1, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 9), EmcComponent.AMORPHOUS_UNIT_COMPONENT)));
}
valueMap.put(new CustomWrappedStack(Block.deadBush), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
valueMap.put(new CustomWrappedStack(Block.ice), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
valueMap.put(new CustomWrappedStack(Block.wood), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), EmcComponent.ESSENTIA_UNIT_COMPONENT)));
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))));
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));
// Temp, testing resolution on multiple passes through
for (int i = 0; i < 16; i++) {
attemptValueAssignment();
}
}
private void attemptValueAssignment() {
for (CustomWrappedStack stack : RecipeRegistry.getDiscoveredStacks()) {
if (!valueMap.containsKey(stack)) {
for (CustomWrappedStack recipeOutput : RecipeRegistry.getRecipeMappings().keySet()) {
if (recipeOutput.getWrappedStack().equals(stack.getWrappedStack())) {
Collection<List<CustomWrappedStack>> recipeInputLists = RecipeRegistry.getRecipeMappings().get(recipeOutput);
for (List<CustomWrappedStack> recipeInputs : recipeInputLists) {
if (listEmcCheck(recipeInputs)) {
valueMap.put(stack, computeEmcValueFromList(recipeOutput.getStackSize(), recipeInputs));
}
}
}
}
}
}
}
private boolean listEmcCheck(List<CustomWrappedStack> stacks) {
boolean everyElementHasEmc = true;
if (stacks.size() > 0) {
for (CustomWrappedStack stack : stacks) {
if (!valueMap.containsKey(new CustomWrappedStack(stack.getWrappedStack()))) {
everyElementHasEmc = false;
}
}
}
else {
return false;
}
return everyElementHasEmc;
}
public EmcValue computeEmcValueFromList(int recipeOutputSize, List<CustomWrappedStack> recipeInputs) {
if (listEmcCheck(recipeInputs)) {
EmcValue computedValue = new EmcValue();
for (CustomWrappedStack stack : recipeInputs) {
computedValue = new EmcValue(computedValue.value + (stack.getStackSize() * valueMap.get(new CustomWrappedStack(stack.getWrappedStack())).value));
}
// TODO Need to come up with a better way of handling sub values/components of calculated emc values
computedValue = new EmcValue(computedValue.value / recipeOutputSize, EmcComponent.OMNI_UNIT_COMPONENT);
return computedValue;
}
else {
return null;
}
}
public static Map<CustomWrappedStack, EmcValue> getDefaultValueMap() {

View file

@ -2,7 +2,6 @@ package com.pahimar.ee3.item.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
@ -69,23 +68,14 @@ public class RecipeRegistry {
List<CustomWrappedStack> foundStacks = new ArrayList<CustomWrappedStack>();
// Scan stacks from known recipes
SortedSet<CustomWrappedStack> recipeOutputSet = new TreeSet<CustomWrappedStack>();
recipeOutputSet.addAll(recipeMap.keySet());
Iterator<CustomWrappedStack> recipeOutputIterator = recipeOutputSet.iterator();
while (recipeOutputIterator.hasNext()) {
CustomWrappedStack recipeOutput = recipeOutputIterator.next();
if (recipeOutput.getWrappedStack() != null) {
if (!foundStacks.contains(recipeOutput.getWrappedStack())) {
foundStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack()));
}
for (CustomWrappedStack recipeOutput : recipeMap.keySet()) {
if (!foundStacks.contains(new CustomWrappedStack(recipeOutput.getWrappedStack()))) {
foundStacks.add(new CustomWrappedStack(recipeOutput.getWrappedStack()));
}
for (List<CustomWrappedStack> recipeInputList : recipeMap.get(recipeOutput)) {
for (CustomWrappedStack recipeInput : recipeInputList) {
if (!foundStacks.contains(recipeInput.getWrappedStack())) {
if (!foundStacks.contains(new CustomWrappedStack(recipeInput.getWrappedStack()))) {
foundStacks.add(new CustomWrappedStack(recipeInput.getWrappedStack()));
}
}
@ -99,16 +89,16 @@ public class RecipeRegistry {
for (int meta = 0; meta < 16; meta++) {
CustomWrappedStack wrappedItemStack = new CustomWrappedStack(new ItemStack(Item.itemsList[i].itemID, 1, meta));
if (!foundStacks.contains(wrappedItemStack.getWrappedStack())) {
foundStacks.add(new CustomWrappedStack(wrappedItemStack.getWrappedStack()));
if (!foundStacks.contains(wrappedItemStack)) {
foundStacks.add(wrappedItemStack);
}
}
}
else {
CustomWrappedStack wrappedItemStack = new CustomWrappedStack(Item.itemsList[i]);
if (!foundStacks.contains(wrappedItemStack.getWrappedStack())) {
foundStacks.add(new CustomWrappedStack(wrappedItemStack.getWrappedStack()));
if (!foundStacks.contains(wrappedItemStack)) {
foundStacks.add(wrappedItemStack);
}
}
}