package com.infinityraider.agricraft.crafting;


import com.infinityraider.agricraft.items.blocks.ItemBlockCustomWood;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

import java.util.ArrayList;
import java.util.List;

public class RecipeShapelessCustomWood extends ShapelessRecipes {

    public RecipeShapelessCustomWood(ItemStack recipeOutput, List<ItemStack> recipeItems) {
        super(recipeOutput, recipeItems);
    }

    @Override
    @SuppressWarnings("unchecked")
    public boolean matches(InventoryCrafting inventoryCrafting, World world) {
        List recipeItems = new ArrayList(this.recipeItems);
        for(int column = 0; column < 3; column++) {
            for(int row = 0; row < 3; row++) {
                ItemStack itemStackToMatch = inventoryCrafting.getStackInRowAndColumn(row, column);
                if(itemStackToMatch != null) {
                    boolean match = false;
                    for (Object recipeItem : recipeItems) {
                        ItemStack itemStack = (ItemStack) recipeItem;
                        if (itemStackToMatch.getItem() == itemStack.getItem() && (itemStack.getItemDamage() == 32767 || itemStackToMatch.getItemDamage() == itemStack.getItemDamage())) {
                            if (itemStackToMatch.getItem() instanceof ItemBlockCustomWood) {
                                NBTTagCompound tag = itemStack.getTagCompound();
                                NBTTagCompound tagToMatch = itemStackToMatch.getTagCompound();
                                if (tagToMatch !=null && tag != null && tagToMatch.equals(tag)) {
                                    match = true;
                                    recipeItems.remove(itemStack);
                                    break;
                                }
                            } else {
                                match = true;
                                recipeItems.remove(itemStack);
                                break;
                            }
                        }
                    }
                    if(!match) {
                        return false;
                    }
                }
            }
        }
        return recipeItems.isEmpty();
    }
}

@@ -41,16 +41,62 @@
 fting;%0A%0A
+import com.agricraft.agricore.util.TypeHelper;
 %0Aimport 
@@ -774,23 +774,49 @@
     
-List recipeItem
+// Copy recipe%0A        final List element
 s = 
@@ -855,24 +855,25 @@
 %0A        for
+ 
 (int column 
@@ -916,16 +916,17 @@
      for
+ 
 (int row
@@ -957,32 +957,38 @@
                 
+final 
 ItemStack itemSt
@@ -981,26 +981,17 @@
 emStack 
-itemStackT
+t
 oMatch =
@@ -1064,27 +1064,19 @@
       if
-(itemStackT
+ (t
 oMatch !
@@ -1164,31 +1164,19 @@
 ect 
-recipeItem : recipeItem
+o : element
 s) %7B
@@ -1204,1015 +1204,175 @@
     
-ItemStack itemStack = (ItemStack) recipeItem;%0A                        if (itemS
+if (s
 tack
-To
+s
 Match
-.getItem() == itemStack.getItem() && (itemStack.getItemDamage() == 32767 %7C%7C itemStackToMatch.getItemDamage() == itemStack.getItemDamage())) %7B%0A                            if (itemStackToMatch.getItem() instanceof ItemBlockCustomWood) %7B%0A                                NBTTagCompound tag = itemStack.getTagCompound();%0A                                NBTTagCompound tagToMatch = itemStackToMatch.getTagCompound();%0A                                if (tagToMatch !=null && tag != null && tagToMatch.equals(tag)) %7B%0A                                    match = true;%0A                                    recipeItems.remove(itemStack);%0A                                    break;%0A                                %7D%0A                            %7D else %7B%0A                                match = true;%0A                                recipeItems.remove(itemStack);%0A                                break;%0A                            %7D
+(toMatch, (ItemStack) o)) %7B%0A                            elements.remove(o);%0A                            match = true;%0A                            break;
 %0A   
@@ -1438,16 +1438,17 @@
       if
+ 
 (!match)
@@ -1571,35 +1571,837 @@
 urn 
-recipeItems.isEmpty();%0A    %7D
+elements.isEmpty();%0A    %7D%0A%0A    private boolean stacksMatch(ItemStack itemStackToMatch, ItemStack itemStack) %7B%0A        if (itemStackToMatch.getItem() == itemStack.getItem() && metasMatch(itemStackToMatch, itemStack)) %7B%0A            if (itemStackToMatch.getItem() instanceof ItemBlockCustomWood) %7B%0A                NBTTagCompound tag = itemStack.getTagCompound();%0A                NBTTagCompound tagToMatch = itemStackToMatch.getTagCompound();%0A                return tagToMatch != null && tag != null && tagToMatch.equals(tag);%0A            %7D else %7B%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A%0A    private boolean metasMatch(ItemStack itemStackToMatch, ItemStack itemStack) %7B%0A        return itemStack.getItemDamage() == 32767 %7C%7C itemStackToMatch.getItemDamage() == itemStack.getItemDamage();%0A    %7D%0A
 %0A%7D%0A

Clean Shapless Custom Wood Recipe