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, World par2World)
030        {
031            ArrayList var3 = new ArrayList(this.recipeItems);
032    
033            for (int var4 = 0; var4 < 3; ++var4)
034            {
035                for (int var5 = 0; var5 < 3; ++var5)
036                {
037                    ItemStack var6 = par1InventoryCrafting.getStackInRowAndColumn(var5, var4);
038    
039                    if (var6 != null)
040                    {
041                        boolean var7 = false;
042                        Iterator var8 = var3.iterator();
043    
044                        while (var8.hasNext())
045                        {
046                            ItemStack var9 = (ItemStack)var8.next();
047    
048                            if (var6.itemID == var9.itemID && (var9.getItemDamage() == -1 || var6.getItemDamage() == var9.getItemDamage()))
049                            {
050                                var7 = true;
051                                var3.remove(var9);
052                                break;
053                            }
054                        }
055    
056                        if (!var7)
057                        {
058                            return false;
059                        }
060                    }
061                }
062            }
063    
064            return var3.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    }