    001    package net.minecraft.src;
    002
    003    public class ShapedRecipes implements IRecipe
    004    {
    005        /** How many horizontal slots this recipe is wide. */
    006        public final int recipeWidth;
    007
    008        /** How many vertical slots this recipe uses. */
    009        public final int recipeHeight;
    010
    011        /** Is a array of ItemStack that composes the recipe. */
    012        public final ItemStack[] recipeItems;
    013
    014        /** Is the ItemStack that you get when craft the recipe. */
    015        private ItemStack recipeOutput;
    016
    017        /** Is the itemID of the output item that you get when craft the recipe. */
    018        public final int recipeOutputItemID;
    019
    020        public ShapedRecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
    021        {
    022            this.recipeOutputItemID = par4ItemStack.itemID;
    023            this.recipeWidth = par1;
    024            this.recipeHeight = par2;
    025            this.recipeItems = par3ArrayOfItemStack;
    026            this.recipeOutput = par4ItemStack;
    027        }
    028
    029        public ItemStack getRecipeOutput()
    030        {
    031            return this.recipeOutput;
    032        }
    033
    034        /**
    035         * Used to check if a recipe matches current crafting inventory
    036         */
    037        public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
    038        {
    039            for (int var3 = 0; var3 <= 3 - this.recipeWidth; ++var3)
    040            {
    041                for (int var4 = 0; var4 <= 3 - this.recipeHeight; ++var4)
    042                {
    043                    if (this.checkMatch(par1InventoryCrafting, var3, var4, true))
    044                    {
    045                        return true;
    046                    }
    047
    048                    if (this.checkMatch(par1InventoryCrafting, var3, var4, false))
    049                    {
    050                        return true;
    051                    }
    052                }
    053            }
    054
    055            return false;
    056        }
    057
    058        /**
    059         * Checks if the region of a crafting inventory is match for the recipe.
    060         */
    061        private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
    062        {
    063            for (int var5 = 0; var5 < 3; ++var5)
    064            {
    065                for (int var6 = 0; var6 < 3; ++var6)
    066                {
    067                    int var7 = var5 - par2;
    068                    int var8 = var6 - par3;
    069                    ItemStack var9 = null;
    070
    071                    if (var7 >= 0 && var8 >= 0 && var7 < this.recipeWidth && var8 < this.recipeHeight)
    072                    {
    073                        if (par4)
    074                        {
    075                            var9 = this.recipeItems[this.recipeWidth - var7 - 1 + var8 * this.recipeWidth];
    076                        }
    077                        else
    078                        {
    079                            var9 = this.recipeItems[var7 + var8 * this.recipeWidth];
    080                        }
    081                    }
    082
    083                    ItemStack var10 = par1InventoryCrafting.getStackInRowAndColumn(var5, var6);
    084
    085                    if (var10 != null || var9 != null)
    086                    {
    087                        if (var10 == null && var9 != null || var10 != null && var9 == null)
    088                        {
    089                            return false;
    090                        }
    091
    092                        if (var9.itemID != var10.itemID)
    093                        {
    094                            return false;
    095                        }
    096
    097                        if (var9.getItemDamage() != -1 && var9.getItemDamage() != var10.getItemDamage())
    098                        {
    099                            return false;
    100                        }
    101                    }
    102                }
    103            }
    104
    105            return true;
    106        }
    107
    108        /**
    109         * Returns an Item that is the result of this recipe
    110         */
    111        public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
    112        {
    113            return this.getRecipeOutput().copy();
    114        }
    115
    116        /**
    117         * Returns the size of the recipe area
    118         */
    119        public int getRecipeSize()
    120        {
    121            return this.recipeWidth * this.recipeHeight;
    122        }
    123    }