2012-08-06 00:59:53 +00:00
|
|
|
package net.minecraftforge.oredict;
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
2012-11-06 00:15:43 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.List;
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2012-12-13 05:58:35 +00:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.item.crafting.CraftingManager;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
|
|
|
import net.minecraft.world.World;
|
2012-08-01 23:35:35 +00:00
|
|
|
|
2013-03-11 21:43:23 +00:00
|
|
|
public class ShapelessOreRecipe implements IRecipe
|
2012-08-01 23:35:35 +00:00
|
|
|
{
|
|
|
|
private ItemStack output = null;
|
2013-03-11 21:43:23 +00:00
|
|
|
private ArrayList input = new ArrayList();
|
2012-08-01 23:35:35 +00:00
|
|
|
|
|
|
|
public ShapelessOreRecipe(Block result, Object... recipe){ this(new ItemStack(result), recipe); }
|
|
|
|
public ShapelessOreRecipe(Item result, Object... recipe){ this(new ItemStack(result), recipe); }
|
2013-03-11 21:43:23 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
public ShapelessOreRecipe(ItemStack result, Object... recipe)
|
|
|
|
{
|
|
|
|
output = result.copy();
|
|
|
|
for (Object in : recipe)
|
|
|
|
{
|
|
|
|
if (in instanceof ItemStack)
|
|
|
|
{
|
|
|
|
input.add(((ItemStack)in).copy());
|
|
|
|
}
|
|
|
|
else if (in instanceof Item)
|
|
|
|
{
|
|
|
|
input.add(new ItemStack((Item)in));
|
|
|
|
}
|
|
|
|
else if (in instanceof Block)
|
|
|
|
{
|
|
|
|
input.add(new ItemStack((Block)in));
|
|
|
|
}
|
|
|
|
else if (in instanceof String)
|
|
|
|
{
|
|
|
|
input.add(OreDictionary.getOres((String)in));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
String ret = "Invalid shapeless ore recipe: ";
|
|
|
|
for (Object tmp : recipe)
|
|
|
|
{
|
|
|
|
ret += tmp + ", ";
|
|
|
|
}
|
|
|
|
ret += output;
|
|
|
|
throw new RuntimeException(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 00:15:43 +00:00
|
|
|
ShapelessOreRecipe(ShapelessRecipes recipe, Map<ItemStack, String> replacements)
|
|
|
|
{
|
|
|
|
output = recipe.getRecipeOutput();
|
|
|
|
|
|
|
|
for(ItemStack ingred : ((List<ItemStack>)recipe.recipeItems))
|
|
|
|
{
|
|
|
|
Object finalObj = ingred;
|
|
|
|
for(Entry<ItemStack, String> replace : replacements.entrySet())
|
|
|
|
{
|
|
|
|
if(OreDictionary.itemMatches(replace.getKey(), ingred, false))
|
|
|
|
{
|
|
|
|
finalObj = OreDictionary.getOres(replace.getValue());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input.add(finalObj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
@Override
|
|
|
|
public int getRecipeSize(){ return input.size(); }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getRecipeOutput(){ return output; }
|
2013-03-11 21:43:23 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
@Override
|
|
|
|
public ItemStack getCraftingResult(InventoryCrafting var1){ return output.copy(); }
|
2013-03-11 21:43:23 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
@Override
|
2013-03-11 21:43:23 +00:00
|
|
|
public boolean matches(InventoryCrafting var1, World world)
|
2012-08-01 23:35:35 +00:00
|
|
|
{
|
|
|
|
ArrayList required = new ArrayList(input);
|
|
|
|
|
|
|
|
for (int x = 0; x < var1.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
ItemStack slot = var1.getStackInSlot(x);
|
|
|
|
|
|
|
|
if (slot != null)
|
|
|
|
{
|
|
|
|
boolean inRecipe = false;
|
|
|
|
Iterator req = required.iterator();
|
|
|
|
|
|
|
|
while (req.hasNext())
|
|
|
|
{
|
|
|
|
boolean match = false;
|
2013-03-11 21:43:23 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
Object next = req.next();
|
2013-03-11 21:43:23 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
if (next instanceof ItemStack)
|
|
|
|
{
|
|
|
|
match = checkItemEquals((ItemStack)next, slot);
|
|
|
|
}
|
|
|
|
else if (next instanceof ArrayList)
|
|
|
|
{
|
|
|
|
for (ItemStack item : (ArrayList<ItemStack>)next)
|
|
|
|
{
|
|
|
|
match = match || checkItemEquals(item, slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
inRecipe = true;
|
|
|
|
required.remove(next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inRecipe)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return required.isEmpty();
|
|
|
|
}
|
2013-03-11 21:43:23 +00:00
|
|
|
|
2012-08-01 23:35:35 +00:00
|
|
|
private boolean checkItemEquals(ItemStack target, ItemStack input)
|
|
|
|
{
|
2013-03-11 21:43:23 +00:00
|
|
|
return (target.itemID == input.itemID && (target.getItemDamage() == OreDictionary.WILDCARD_VALUE || target.getItemDamage() == input.getItemDamage()));
|
2012-08-01 23:35:35 +00:00
|
|
|
}
|
2013-01-29 01:33:53 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-11 21:43:23 +00:00
|
|
|
* Returns the input for this recipe, any mod accessing this value should never
|
2013-01-29 01:33:53 +00:00
|
|
|
* manipulate the values in this array as it will effect the recipe itself.
|
|
|
|
* @return The recipes input vales.
|
|
|
|
*/
|
|
|
|
public ArrayList getInput()
|
|
|
|
{
|
|
|
|
return this.input;
|
|
|
|
}
|
2012-08-01 23:35:35 +00:00
|
|
|
}
|