Reminder to self: come back and review the RecipeRegistry stuff and how

it relates to DynEMC
This commit is contained in:
pahimar 2013-10-06 21:50:43 -04:00
parent c8f0968316
commit 0639d4a917
8 changed files with 111 additions and 177 deletions

View file

@ -6,6 +6,7 @@ import java.util.Arrays;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraftforge.common.MinecraftForge;
@ -166,6 +167,8 @@ public class EquivalentExchange3 {
// recipe registry works
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(Item.bucketWater, Arrays.asList(Item.bucketEmpty, Block.waterStill)));
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(Item.bucketLava, Arrays.asList(Item.bucketEmpty, Block.lavaStill)));
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(Item.coal, Arrays.asList(Block.oreCoal)));
FMLInterModComms.sendMessage(Reference.MOD_ID, InterModComms.ADD_RECIPE, NBTHelper.encodeRecipeAsNBT(new ItemStack(Item.coal.itemID, 1, 1), Arrays.asList(Item.coal)));
}
@EventHandler
@ -176,9 +179,9 @@ public class EquivalentExchange3 {
// Initialize the DynEMC system
DynEMC dynEMC = DynEMC.getInstance();
//dynEMC.printDebugDump();
dynEMC.printDebugDump();
EmcRegistry.printDebugDump();
EmcRegistry.getInstance().printDebugDump();
}
@EventHandler

View file

@ -1,6 +1,8 @@
package com.pahimar.ee3.core.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
@ -172,4 +174,67 @@ public class RecipeHelper {
return recipeInputs;
}
/**
* Collates an uncollated, unsorted List of Objects into a sorted, collated
* List of CustomWrappedStacks
*
* @param uncollatedStacks
* List of objects for collating
* @return A sorted, collated List of CustomWrappedStacks
*/
public static List<CustomWrappedStack> collateInputStacks(List<?> uncollatedStacks) {
List<CustomWrappedStack> collatedStacks = new ArrayList<CustomWrappedStack>();
CustomWrappedStack stack = null;
boolean found = false;
for (Object object : uncollatedStacks) {
found = false;
if (CustomWrappedStack.canBeWrapped(object)) {
stack = new CustomWrappedStack(object);
if (collatedStacks.isEmpty()) {
collatedStacks.add(stack);
}
else {
for (int i = 0; i < collatedStacks.size(); i++) {
if (collatedStacks.get(i).getWrappedStack() != null) {
if (stack.getWrappedStack() instanceof ItemStack && collatedStacks.get(i).getWrappedStack() instanceof ItemStack) {
if (ItemUtil.compare((ItemStack) stack.getWrappedStack(), (ItemStack) collatedStacks.get(i).getWrappedStack())) {
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + stack.getStackSize());
found = true;
}
}
else if (stack.getWrappedStack() instanceof OreStack && collatedStacks.get(i).getWrappedStack() instanceof OreStack) {
if (OreStack.compareOreNames((OreStack) stack.getWrappedStack(), (OreStack) collatedStacks.get(i).getWrappedStack())) {
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + stack.getStackSize());
found = true;
}
}
else if (stack.getWrappedStack() instanceof EnergyStack && collatedStacks.get(i).getWrappedStack() instanceof EnergyStack) {
if (EnergyStack.compareEnergyNames((EnergyStack) stack.getWrappedStack(), (EnergyStack) collatedStacks.get(i).getWrappedStack())) {
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + stack.getStackSize());
found = true;
}
}
}
}
if (!found) {
collatedStacks.add(stack);
}
}
}
}
Collections.sort(collatedStacks);
return collatedStacks;
}
}

View file

@ -2,15 +2,11 @@ package com.pahimar.ee3.emc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.graph.Node;
import com.pahimar.ee3.graph.WeightedDirectedGraph;
import com.pahimar.ee3.graph.WeightedDirectedEdge;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.crafting.RecipeRegistry;
@ -44,39 +40,7 @@ public class DynEMC {
}
private void populateGraph() {
for (CustomWrappedStack discoveredStack : recipeRegistry.getDiscoveredStacks()) {
graph.addNode(discoveredStack);
}
Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipeMappings = recipeRegistry.getRecipeMappings();
Set<CustomWrappedStack> recipeKeySet = recipeMappings.keySet();
Iterator<CustomWrappedStack> recipeKeySetIterator = recipeKeySet.iterator();
while (recipeKeySetIterator.hasNext()) {
CustomWrappedStack recipeOutput = recipeKeySetIterator.next();
for (List<CustomWrappedStack> recipeInputs : recipeMappings.get(recipeOutput)) {
CustomWrappedStack unWrappedRecipeOutput = new CustomWrappedStack(recipeOutput.getWrappedStack());
if (graph.containsNode(unWrappedRecipeOutput)) {
for (CustomWrappedStack recipeInput : recipeInputs) {
// Unwrapped the wrapped stacks so that we actually find them in the graph
CustomWrappedStack unWrappedRecipeInput = new CustomWrappedStack(recipeInput.getWrappedStack());
if (graph.containsNode(unWrappedRecipeInput)) {
if (recipeOutput.getStackSize() != 0) {
graph.addEdge(unWrappedRecipeOutput, unWrappedRecipeInput, (recipeInput.getStackSize() * 1.0f) / recipeOutput.getStackSize());
}
}
}
}
}
}
}
public void printDebugDump() {
@ -90,20 +54,20 @@ public class DynEMC {
LogHelper.debug("");
List<Node<CustomWrappedStack>> nodes = new ArrayList<Node<CustomWrappedStack>>();
nodes.addAll(graph.getAllNodes());
nodes.addAll(graph.getLeafNodes());
Collections.sort(nodes);
for (Node<CustomWrappedStack> node : nodes) {
LogHelper.debug("Node: " + node);
LogHelper.debug("Edges FROM this Node:");
for (WeightedDirectedEdge<CustomWrappedStack> fromEdge : graph.edgesFrom(node)) {
LogHelper.debug(" * " + fromEdge);
}
LogHelper.debug("Edges TO this Node:");
for (WeightedDirectedEdge<CustomWrappedStack> toEdge : graph.edgesTo(node)) {
LogHelper.debug(" * " + toEdge);
}
LogHelper.debug("");
// LogHelper.debug("Edges FROM this Node:");
// for (WeightedDirectedEdge<CustomWrappedStack> fromEdge : graph.edgesFrom(node)) {
// LogHelper.debug(" * " + fromEdge);
// }
// LogHelper.debug("Edges TO this Node:");
// for (WeightedDirectedEdge<CustomWrappedStack> toEdge : graph.edgesTo(node)) {
// LogHelper.debug(" * " + toEdge);
// }
// LogHelper.debug("");
}
}
}

View file

@ -1,41 +1,48 @@
package com.pahimar.ee3.emc;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.block.Block;
import com.pahimar.ee3.core.util.EnergyStack;
import com.pahimar.ee3.item.CustomWrappedStack;
public class EmcDefaultValues {
private static EmcDefaultValues defaultValues = null;
private Map<CustomWrappedStack, EmcValue> defaultValueMap;
private EmcDefaultValues() {
defaultValueMap = new HashMap<CustomWrappedStack, EmcValue>();
}
public static EmcDefaultValues getInstance() {
if (defaultValues == null) {
defaultValues = new EmcDefaultValues();
defaultValues.init();
}
return defaultValues;
}
private void init() {
defaultValueMap.put(
new CustomWrappedStack(new EnergyStack(EnergyStack.VANILLA_SMELTING_ENERGY_NAME, 1)),
new EmcValue(1, EmcComponent.KINETIC_UNIT_COMPONENT)
);
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))));
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));
}
public Map<CustomWrappedStack, EmcValue> getDefaultValueMap() {
return defaultValueMap;
}
}

View file

@ -1,16 +1,12 @@
package com.pahimar.ee3.emc;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import com.pahimar.ee3.core.util.EnergyStack;
import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.item.CustomWrappedStack;
@ -42,21 +38,7 @@ public class EmcRegistry {
// Grab the default value map
Map<CustomWrappedStack, EmcValue> defaultValueMap = EmcDefaultValues.getInstance().getDefaultValueMap();
// stackMappings.put(new CustomWrappedStack(), new EmcValue());
// Vanilla Smelting Energy
stackMappings.put(new CustomWrappedStack(Block.cobblestone), new EmcValue(1, EmcComponent.CORPOREAL_UNIT_COMPONENT));
stackMappings.put(new CustomWrappedStack(Block.wood), new EmcValue(32, EmcComponent.CORPOREAL_UNIT_COMPONENT));
stackMappings.put(new CustomWrappedStack(Block.oreIron), new EmcValue(256, EmcComponent.CORPOREAL_UNIT_COMPONENT));
stackMappings.put(new CustomWrappedStack(Block.oreGold), new EmcValue(2048, EmcComponent.CORPOREAL_UNIT_COMPONENT));
stackMappings.put(new CustomWrappedStack(Block.oreDiamond), new EmcValue(8192, EmcComponent.CORPOREAL_UNIT_COMPONENT));
stackMappings.put(new CustomWrappedStack(Item.coal), new EmcValue(32, Arrays.asList(new EmcComponent(EmcType.CORPOREAL, 4), new EmcComponent(EmcType.KINETIC, 1))));
stackMappings.put(
new CustomWrappedStack(new EnergyStack(EnergyStack.VANILLA_SMELTING_ENERGY_NAME)),
new EmcValue(
getEmcValue(new CustomWrappedStack(Item.coal)).getComponentValueByType(EmcType.KINETIC) / (8 * EnergyStack.VANILLA_SMELTING_ENERGY_THRESHOLD),
EmcComponent.KINETIC_UNIT_COMPONENT));
stackMappings.putAll(defaultValueMap);
}
public boolean hasEmcValue(CustomWrappedStack wrappedStack) {
@ -89,13 +71,14 @@ public class EmcRegistry {
}
public static void printDebugDump() {
public void printDebugDump() {
Iterator<CustomWrappedStack> stackIter = EmcRegistry.getInstance().stackMappings.keySet().iterator();
CustomWrappedStack stack = null;
while (stackIter.hasNext()) {
stack = stackIter.next();
LogHelper.debug(stack + ": " + EmcRegistry.getInstance().stackMappings.get(stack));
List<CustomWrappedStack> keyList = new ArrayList<CustomWrappedStack>();
keyList.addAll(stackMappings.keySet());
Collections.sort(keyList);
for (CustomWrappedStack stack : keyList) {
LogHelper.debug(stack + " == " + stackMappings.get(stack));
}
}
}

View file

@ -1,84 +0,0 @@
package com.pahimar.ee3.item.crafting;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.minecraft.item.ItemStack;
import com.pahimar.ee3.core.util.EnergyStack;
import com.pahimar.ee3.core.util.ItemUtil;
import com.pahimar.ee3.core.util.OreStack;
import com.pahimar.ee3.item.CustomWrappedStack;
public class CondensedRecipe {
public CustomWrappedStack output;
public List<CustomWrappedStack> inputs;
public CondensedRecipe(Object output, List<?> inputs) {
this.output = new CustomWrappedStack(output);
this.inputs = collateInputStacks(inputs);
}
public CondensedRecipe(Object output, Object... inputs) {
this(output, Arrays.asList(inputs));
}
private List<CustomWrappedStack> collateInputStacks(List<?> uncollatedStacks) {
List<CustomWrappedStack> collatedStacks = new ArrayList<CustomWrappedStack>();
CustomWrappedStack stack = null;
boolean found = false;
for (Object object : uncollatedStacks) {
found = false;
if (CustomWrappedStack.canBeWrapped(object)) {
stack = new CustomWrappedStack(object);
if (collatedStacks.isEmpty()) {
collatedStacks.add(stack);
}
else {
for (int i = 0; i < collatedStacks.size(); i++) {
if (collatedStacks.get(i).getWrappedStack() != null) {
if (stack.getWrappedStack() instanceof ItemStack && collatedStacks.get(i).getWrappedStack() instanceof ItemStack) {
if (ItemUtil.compare((ItemStack) stack.getWrappedStack(), (ItemStack) collatedStacks.get(i).getWrappedStack())) {
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + stack.getStackSize());
found = true;
}
}
else if (stack.getWrappedStack() instanceof OreStack && collatedStacks.get(i).getWrappedStack() instanceof OreStack) {
if (OreStack.compareOreNames((OreStack) stack.getWrappedStack(), (OreStack) collatedStacks.get(i).getWrappedStack())) {
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + stack.getStackSize());
found = true;
}
}
else if (stack.getWrappedStack() instanceof EnergyStack && collatedStacks.get(i).getWrappedStack() instanceof EnergyStack) {
if (EnergyStack.compareEnergyNames((EnergyStack) stack.getWrappedStack(), (EnergyStack) collatedStacks.get(i).getWrappedStack())) {
collatedStacks.get(i).setStackSize(collatedStacks.get(i).getStackSize() + stack.getStackSize());
found = true;
}
}
}
}
if (!found) {
collatedStacks.add(stack);
}
}
}
}
return collatedStacks;
}
}

View file

@ -14,7 +14,6 @@ import com.google.common.collect.Multimap;
import com.pahimar.ee3.core.util.EnergyStack;
import com.pahimar.ee3.core.util.ItemUtil;
import com.pahimar.ee3.core.util.OreStack;
import com.pahimar.ee3.core.util.RecipeHelper;
import com.pahimar.ee3.item.CustomWrappedStack;
public class RecipeRegistry {
@ -29,7 +28,6 @@ public class RecipeRegistry {
private RecipeRegistry() {
recipeMap = HashMultimap.create();
wildCardStacks = RecipeHelper.populateWildCards();
discoveredStacks = new ArrayList<CustomWrappedStack>();
recipelessStacks = new ArrayList<CustomWrappedStack>();
}

View file

@ -16,8 +16,6 @@ public class RecipesVanilla {
private static Multimap<CustomWrappedStack, List<CustomWrappedStack>> vanillaRecipes = null;
ArrayList<CustomWrappedStack> discoveredItems = new ArrayList<CustomWrappedStack>();
public static Multimap<CustomWrappedStack, List<CustomWrappedStack>> getVanillaRecipes() {
if (vanillaRecipes == null) {