001 package net.minecraft.item.crafting;
002
003 import java.util.ArrayList;
004 import java.util.Iterator;
005 import java.util.List;
006 import net.minecraft.inventory.InventoryCrafting;
007 import net.minecraft.item.ItemStack;
008 import net.minecraft.world.World;
009
010 public class ShapelessRecipes implements IRecipe
011 {
012 /** Is the ItemStack that you get when craft the recipe. */
013 private final ItemStack recipeOutput;
014
015 /** Is a List of ItemStack that composes the recipe. */
016 public final List recipeItems;
017
018 public ShapelessRecipes(ItemStack par1ItemStack, List par2List)
019 {
020 this.recipeOutput = par1ItemStack;
021 this.recipeItems = par2List;
022 }
023
024 public ItemStack getRecipeOutput()
025 {
026 return this.recipeOutput;
027 }
028
029 /**
030 * Used to check if a recipe matches current crafting inventory
031 */
032 public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
033 {
034 ArrayList var3 = new ArrayList(this.recipeItems);
035
036 for (int var4 = 0; var4 < 3; ++var4)
037 {
038 for (int var5 = 0; var5 < 3; ++var5)
039 {
040 ItemStack var6 = par1InventoryCrafting.getStackInRowAndColumn(var5, var4);
041
042 if (var6 != null)
043 {
044 boolean var7 = false;
045 Iterator var8 = var3.iterator();
046
047 while (var8.hasNext())
048 {
049 ItemStack var9 = (ItemStack)var8.next();
050
051 if (var6.itemID == var9.itemID && (var9.getItemDamage() == -1 || var6.getItemDamage() == var9.getItemDamage()))
052 {
053 var7 = true;
054 var3.remove(var9);
055 break;
056 }
057 }
058
059 if (!var7)
060 {
061 return false;
062 }
063 }
064 }
065 }
066
067 return var3.isEmpty();
068 }
069
070 /**
071 * Returns an Item that is the result of this recipe
072 */
073 public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
074 {
075 return this.recipeOutput.copy();
076 }
077
078 /**
079 * Returns the size of the recipe area
080 */
081 public int getRecipeSize()
082 {
083 return this.recipeItems.size();
084 }
085 }