package de.impelon.disenchanter.blocks;

import de.impelon.disenchanter.DisenchanterMain;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.oredict.RecipeSorter;
import net.minecraftforge.oredict.ShapedOreRecipe;

public class UpgradeTableRecipe extends ShapedOreRecipe {
	
	private final PropertyBool addedProperty;
	
	static {
	    RecipeSorter.register(DisenchanterMain.MODID + ":upgradeTable", UpgradeTableRecipe.class, RecipeSorter.Category.SHAPED, "after:forge:shapedore");
	}

	public UpgradeTableRecipe(PropertyBool addedProperty, ItemStack result, Object... recipe) {
		super(result, recipe);
		this.addedProperty = addedProperty;
	}
	
	@Override
	public boolean matches(InventoryCrafting grid, World world) {
		for (int slot = 0; slot < grid.getSizeInventory(); slot++) {
			ItemStack st = grid.getStackInSlot(slot);
			if (st != null && st.getItem() == Item.getItemFromBlock(DisenchanterMain.proxy.disenchantmentTable))
				if (DisenchanterMain.proxy.disenchantmentTable.getStateFromMeta(st.getItemDamage()).getValue(this.addedProperty))
					return false;
		}
		return super.matches(grid, world);
	}

	@Override
	public ItemStack getCraftingResult(InventoryCrafting grid) {
		ItemStack table = null;
		for (int slot = 0; slot < grid.getSizeInventory(); slot++) {
				ItemStack st = grid.getStackInSlot(slot);
				if (st != null && st.getItem() == Item.getItemFromBlock(DisenchanterMain.proxy.disenchantmentTable))
					table = st.copy();
		}

		ItemStack res = super.getCraftingResult(grid);
		res.setItemDamage(table.getItemDamage() + DisenchanterMain.proxy.disenchantmentTable.
				getMetaFromState(DisenchanterMain.proxy.disenchantmentTable.getDefaultState().withProperty(this.addedProperty, true)));
		return res;
	}

}

@@ -29,14 +29,16 @@
 ter.
-blocks
+crafting
 ;%0D%0A%0D
@@ -263,16 +263,61 @@
 Stack;%0D%0A
+import net.minecraft.util.ResourceLocation;%0D%0A
 import n
@@ -555,16 +555,18 @@
 ty;%0D%0A%09%0D%0A
+//
 %09static 
@@ -568,16 +568,18 @@
 atic %7B%0D%0A
+//
 %09    Rec
@@ -722,20 +722,607 @@
 ore%22);%0D%0A
+//
 %09%7D%0D%0A
+%09%0D%0A%09/* %0D%0A%09 * TODO: remove constructor if converted to JSON recipe%0D%0A%09 * see: %0D%0A%09 * https://github.com/Vazkii/Botania/blob/master/src/main/java/vazkii/botania/common/crafting/recipe/ArmorUpgradeRecipe.java%0D%0A%09 * https://github.com/Vazkii/Botania/blob/master/src/main/java/vazkii/botania/common/crafting/recipe/AncientWillRecipe.java%0D%0A%09 * https://github.com/Vazkii/Botania/blob/master/src/main/java/vazkii/botania/common/crafting/ModCraftingRecipes.java%0D%0A%09 * https://github.com/Vazkii/Botania/blob/master/src/main/java/vazkii/botania/common/crafting/FluxfieldConditionFactory.java%0D%0A%09 */%0D%0A%09
 %0D%0A%09publi
@@ -1413,16 +1413,16 @@
  %7B%0D%0A
-
 %09%09super(
 resu
@@ -1417,16 +1417,22 @@
 %09%09super(
+null, 
 result, 

Update to 1.12