Some more work on DynEMC

This commit is contained in:
pahimar 2013-06-18 22:20:50 -04:00
parent 87f1108632
commit 9ac6722860
5 changed files with 66 additions and 50 deletions

View file

@ -169,6 +169,7 @@ public class EquivalentExchange3 {
AddonHandler.init();
// Initialize the DynEMC system
@SuppressWarnings("unused")
DynEMC dynEMC = DynEMC.getInstance();
}

View file

@ -35,6 +35,11 @@ public class LogHelper {
log(Level.SEVERE, message);
}
public static void debug(String message) {
log(Level.WARNING, "[DEBUG] " + message);
}
public static void warning(String message) {
log(Level.WARNING, message);

View file

@ -34,7 +34,7 @@ public class RecipeHelper {
*
* @return A list of CustomWrappedStacks that contains all wild card meta ItemStacks in the vanilla Crafting Manager
*/
public static ArrayList<CustomWrappedStack> discoverWildCards() {
public static ArrayList<CustomWrappedStack> populateWildCards() {
ArrayList<CustomWrappedStack> wildCards = new ArrayList<CustomWrappedStack>();
@ -87,7 +87,6 @@ public class RecipeHelper {
public static ArrayList<CustomWrappedStack> getRecipeInputs(IRecipe recipe) {
ArrayList<CustomWrappedStack> recipeInputs = new ArrayList<CustomWrappedStack>();
ItemStack itemStack = null;
OreStack oreStack = null;
if (recipe instanceof ShapedRecipes) {
@ -96,11 +95,7 @@ public class RecipeHelper {
for (int i = 0; i < shapedRecipe.recipeItems.length; i++) {
if (shapedRecipe.recipeItems[i] instanceof ItemStack) {
itemStack = shapedRecipe.recipeItems[i];
itemStack.stackSize = 1;
recipeInputs.add(new CustomWrappedStack(itemStack));
recipeInputs.add(new CustomWrappedStack(shapedRecipe.recipeItems[i]));
}
}
}
@ -110,11 +105,7 @@ public class RecipeHelper {
for (Object object : shapelessRecipe.recipeItems) {
if (object instanceof ItemStack) {
itemStack = (ItemStack) object;
itemStack.stackSize = 1;
recipeInputs.add(new CustomWrappedStack(itemStack));
recipeInputs.add(new CustomWrappedStack(object));
}
}
}
@ -132,7 +123,6 @@ public class RecipeHelper {
if (!shapedOreRecipeList.isEmpty()) {
oreStack = new OreStack((ItemStack) shapedOreRecipeList.get(0));
oreStack.stackSize = 1;
recipeInputs.add(new CustomWrappedStack(oreStack));
}
@ -141,11 +131,7 @@ public class RecipeHelper {
* Else it is possibly an ItemStack
*/
else if (shapedOreRecipe.getInput()[i] instanceof ItemStack) {
itemStack = (ItemStack) shapedOreRecipe.getInput()[i];
itemStack.stackSize = 1;
recipeInputs.add(new CustomWrappedStack(itemStack));
recipeInputs.add(new CustomWrappedStack(shapedOreRecipe.getInput()[i]));
}
}
}
@ -160,16 +146,12 @@ public class RecipeHelper {
if (!shapelessOreRecipeList.isEmpty()) {
oreStack = new OreStack((ItemStack) shapelessOreRecipeList.get(0));
oreStack.stackSize = 1;
recipeInputs.add(new CustomWrappedStack(oreStack));
}
}
else if (object instanceof ItemStack) {
itemStack = (ItemStack) object;
itemStack.stackSize = 1;
recipeInputs.add(new CustomWrappedStack(itemStack));
recipeInputs.add(new CustomWrappedStack(object));
}
}
}
@ -187,6 +169,10 @@ public class RecipeHelper {
if (customWrappedStack.getWrappedStack() instanceof ItemStack) {
return getReverseRecipes((ItemStack) customWrappedStack.getWrappedStack());
}
else if (customWrappedStack.getWrappedStack() instanceof OreStack) {
// TODO Return recipes for OreStacks
LogHelper.debug("ReverseRecipe for OreStack: " + customWrappedStack.toString());
}
return new ArrayList<IRecipe>();
}

View file

@ -18,7 +18,7 @@ import com.pahimar.ee3.core.util.RecipeHelper;
import com.pahimar.ee3.emc.graph.WeightedDirectedGraph;
import com.pahimar.ee3.emc.graph.WeightedEdge;
import com.pahimar.ee3.item.CustomWrappedStack;
import com.pahimar.ee3.item.crafting.RecipeManager;
import com.pahimar.ee3.item.crafting.RecipeRegistry;
public class DynEMC {
@ -51,7 +51,7 @@ public class DynEMC {
private void init() {
RecipeManager recipeManager = RecipeManager.getInstance();
RecipeRegistry recipeManager = RecipeRegistry.getInstance();
}
private void populateItemList() {
@ -250,29 +250,29 @@ public class DynEMC {
public void printDebugDump() {
LogHelper.info("***** START NODES *****");
LogHelper.debug("***** START NODES *****");
Iterator<CustomWrappedStack> nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
CustomWrappedStack node = nodeIter.next();
LogHelper.info("Node: " + node);
LogHelper.debug("Node: " + node);
}
LogHelper.info("***** END NODES *****");
LogHelper.debug("***** END NODES *****");
LogHelper.info("***** START EDGES FROM *****");
LogHelper.debug("***** START EDGES FROM *****");
nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
CustomWrappedStack node = nodeIter.next();
Set<WeightedEdge<CustomWrappedStack>> edgesFrom = graph.edgesFrom(node);
for (WeightedEdge<CustomWrappedStack> edge : edgesFrom) {
LogHelper.info("Crafting Output: " + node);
LogHelper.info("Crafting Input: " + edge.getTarget());
LogHelper.info("Weight: " + edge.getWeight());
LogHelper.info("");
LogHelper.debug("Crafting Output: " + node);
LogHelper.debug("Crafting Input: " + edge.getTarget());
LogHelper.debug("Weight: " + edge.getWeight());
LogHelper.debug("");
}
}
LogHelper.info("***** END EDGES FROM *****");
LogHelper.debug("***** END EDGES FROM *****");
LogHelper.info("***** START EDGES TO *****");
LogHelper.debug("***** START EDGES TO *****");
nodeIter = graph.iterator();
while (nodeIter.hasNext()) {
CustomWrappedStack node = nodeIter.next();
@ -280,13 +280,13 @@ public class DynEMC {
Iterator<WeightedEdge<CustomWrappedStack>> edgeIter = edgesTo.iterator();
while (edgeIter.hasNext()) {
WeightedEdge<CustomWrappedStack> edge = edgeIter.next();
LogHelper.info("From: " + node);
LogHelper.info("To: " + edge.getTarget());
LogHelper.info("Weight: " + edge.getWeight());
LogHelper.info("");
LogHelper.debug("From: " + node);
LogHelper.debug("To: " + edge.getTarget());
LogHelper.debug("Weight: " + edge.getWeight());
LogHelper.debug("");
}
}
LogHelper.info("***** END EDGES TO *****");
LogHelper.debug("***** END EDGES TO *****");
}
@Override

View file

@ -4,34 +4,39 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.pahimar.ee3.core.util.LogHelper;
import com.pahimar.ee3.core.util.OreStack;
import com.pahimar.ee3.core.util.RecipeHelper;
import com.pahimar.ee3.item.CustomWrappedStack;
public class RecipeManager {
public class RecipeRegistry {
private static RecipeManager recipeManager = null;
private static RecipeRegistry recipeRegistry = null;
private Multimap<CustomWrappedStack, List<CustomWrappedStack>> recipeMap;
private List<CustomWrappedStack> wildCardStacks;
@SuppressWarnings("unused")
private List<CustomWrappedStack> wildCardList;
private RecipeManager() {
private RecipeRegistry() {
recipeMap = HashMultimap.create();
wildCardStacks = RecipeHelper.discoverWildCards();
wildCardList = RecipeHelper.populateWildCards();
}
public static RecipeManager getInstance() {
public static RecipeRegistry getInstance() {
if (recipeManager == null) {
recipeManager = new RecipeManager();
if (recipeRegistry == null) {
recipeRegistry = new RecipeRegistry();
}
return recipeManager;
return recipeRegistry;
}
public boolean hasRecipe(CustomWrappedStack customWrappedStack) {
@ -68,9 +73,10 @@ public class RecipeManager {
public void addRecipe(CustomWrappedStack recipeOutput, List<?> recipeInputs) {
@SuppressWarnings("unused")
ArrayList<CustomWrappedStack> collatedStacks = new ArrayList<CustomWrappedStack>();
CustomWrappedStack wrappedInput = null;
CustomWrappedStack wrappedInputStack = null;
/**
* For every input in the input list, check to see if we have discovered
@ -79,6 +85,24 @@ public class RecipeManager {
*/
for (Object object : recipeInputs) {
if (object instanceof ItemStack || object instanceof OreStack) {
wrappedInputStack = new CustomWrappedStack(object);
}
else if (object instanceof CustomWrappedStack) {
wrappedInputStack = (CustomWrappedStack) object;
}
LogHelper.warning(wrappedInputStack.toString());
}
}
// TODO Temporary for testing, remove this later
static {
CustomWrappedStack recipeOutput = new CustomWrappedStack(new ItemStack(Item.stick));
List<IRecipe> recipes = RecipeHelper.getReverseRecipes(recipeOutput);
for (IRecipe recipe : recipes) {
recipeRegistry.addRecipe(recipeOutput, RecipeHelper.getRecipeInputs(recipe));
}
}
}