package manilla.util.crafting;

import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.world.World;

public class BShapedRecipe extends ShapedRecipes
{
    /** How many horizontal slots this recipe uses. */
    private int recipeWidth;

    /** How many vertical slots this recipe uses. */
    private int recipeHeight;
    
    /** How many slots wide the grid is. */
    private int craftingWidth = 3;
    
    /** How many slots tall the grid is. */
    private int craftingHeight = 3;

    /** Is a array of ItemStack that composes the recipe. */
    protected ItemStack[] recipeItems;

    public BShapedRecipe(int width, int height, ItemStack[] inputStacks, ItemStack output)
    {
    	super(width, height, inputStacks, output);
        this.recipeWidth = width;
        this.recipeHeight = height;
        this.recipeItems = inputStacks;
    }
    
    public void setCraftingSize(int width, int height) {
    	craftingWidth = width;
    	craftingHeight = height;
    }

    /**
     * Used to check if a recipe matches the current crafting inventory
     */
    public boolean matches(InventoryCrafting craftingInventory, World w)
    {
        for (int x = 0; x <= craftingWidth - this.recipeWidth; ++x) {
            for (int y = 0; y <= craftingHeight - this.recipeHeight; ++y) {
                if (this.checkMatch(craftingInventory, x, y, true))
                {
                    return true;
                }

                if (this.checkMatch(craftingInventory, x, y, false))
                {
                    return true;
                }
            }
        }

        return false;
    }

    /**
     * Checks if the region of a crafting inventory is a match for the recipe.
     */
    private boolean checkMatch(InventoryCrafting craftingInventory, int x, int y, boolean flag)
    {
        for (int j = 0; j < craftingWidth; ++j)
        {
            for (int k = 0; k < craftingHeight; ++k)
            {
                int col = j - x;
                int row = k - y;
                ItemStack result = null;

                if (col >= 0 && row >= 0 && col < recipeWidth && row < recipeHeight)
                {
                    if (flag)
                    {
                        result = recipeItems[this.recipeWidth - col - 1 + row * recipeWidth];
                    }
                    else
                    {
                        result = recipeItems[col + row * recipeWidth];
                    }
                }

                ItemStack existing = craftingInventory.getStackInRowAndColumn(j, k);

                if (existing != null || result != null)
                {
                    if (existing == null && result != null || existing != null && result == null)
                    {
                        return false;
                    }

                    if (result != existing)
                    {
                        return false;
                    }

                    if (result.getItemDamage() != 32767 && result.getItemDamage() != existing.getItemDamage())
                    {
                        return false;
                    }
                }
            }
        }

        return true;
    }
}

@@ -5,29 +5,47 @@
 age 
-manilla.util.crafting
+net.acomputerdog.BlazeLoader.api.recipe
 ;%0A%0Ai

Update BShapedRecipe.java