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