Mekanism-tilera-Edition/common/buildcraft/api/recipes/AssemblyRecipe.java

89 lines
2.3 KiB
Java
Raw Normal View History

2013-04-13 16:35:13 +02:00
package buildcraft.api.recipes;
2013-12-26 21:00:08 +01:00
import java.util.ArrayList;
2013-04-13 16:35:13 +02:00
import java.util.LinkedList;
import net.minecraft.item.ItemStack;
2013-12-26 21:00:08 +01:00
import net.minecraftforge.oredict.OreDictionary;
2013-04-13 16:35:13 +02:00
public class AssemblyRecipe {
public static LinkedList<AssemblyRecipe> assemblyRecipes = new LinkedList<AssemblyRecipe>();
2013-12-26 21:00:08 +01:00
public final Object[] input;
2013-04-13 16:35:13 +02:00
public final ItemStack output;
public final float energy;
public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) {
this.input = input;
this.output = output;
this.energy = energy;
}
2013-12-26 21:00:08 +01:00
/**
* This version of AssemblyRecipe supports the OreDictionary
*
* @param input Object... containing either an ItemStack, or a paired string
* and integer(ex: "dyeBlue", 1)
* @param energy MJ cost to produce
* @param output resulting ItemStack
*/
public AssemblyRecipe(int energy, ItemStack output, Object... input) {
this.output = output;
this.energy = energy;
this.input = input;
2013-04-13 16:35:13 +02:00
2013-12-26 21:00:08 +01:00
for (int i = 0; i < input.length; i++) {
if (input[i] instanceof String) {
input[i] = OreDictionary.getOres((String) input[i]);
}
}
}
2013-04-13 16:35:13 +02:00
2013-12-26 21:00:08 +01:00
public boolean canBeDone(ItemStack... items) {
for (int i = 0; i < input.length; i++) {
if (input[i] == null)
2013-04-13 16:35:13 +02:00
continue;
2013-12-26 21:00:08 +01:00
if (input[i] instanceof ItemStack) {
ItemStack requirement = (ItemStack) input[i];
int found = 0; // Amount of ingredient found in inventory
int expected = requirement.stackSize;
for (ItemStack item : items) {
if (item == null)
continue;
if (item.isItemEqual(requirement))
found += item.stackSize; // Adds quantity of stack to amount found
2013-04-13 16:35:13 +02:00
}
2013-12-26 21:00:08 +01:00
// Return false if the amount of ingredient found
// is not enough
if (found < expected)
return false;
} else if (input[i] instanceof ArrayList) {
ArrayList<ItemStack> oreList = (ArrayList<ItemStack>) input[i];
int found = 0; // Amount of ingredient found in inventory
int expected = (Integer) input[i++ + 1];
for (ItemStack item : items) {
if (item == null)
continue;
for (ItemStack oreItem : oreList) {
if (OreDictionary.itemMatches(oreItem, item, true)) {
found += item.stackSize;
break;
}
}
2013-04-13 16:35:13 +02:00
}
2013-12-26 21:00:08 +01:00
// Return false if the amount of ingredient found
// is not enough
if (found < expected)
return false;
}
2013-04-13 16:35:13 +02:00
}
return true;
}
}