package net.minecraft.item.crafting;

import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

public class RecipeBookCloning implements IRecipe
{
	private static final String __OBFID = "CL_00000081";

	public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
	{
		int i = 0;
		ItemStack itemstack = null;

		for (int j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
		{
			ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(j);

			if (itemstack1 != null)
			{
				if (itemstack1.getItem() == Items.written_book)
				{
					if (itemstack != null)
					{
						return false;
					}

					itemstack = itemstack1;
				}
				else
				{
					if (itemstack1.getItem() != Items.writable_book)
					{
						return false;
					}

					++i;
				}
			}
		}

		return itemstack != null && i > 0;
	}

	public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
	{
		int i = 0;
		ItemStack itemstack = null;

		for (int j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
		{
			ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(j);

			if (itemstack1 != null)
			{
				if (itemstack1.getItem() == Items.written_book)
				{
					if (itemstack != null)
					{
						return null;
					}

					itemstack = itemstack1;
				}
				else
				{
					if (itemstack1.getItem() != Items.writable_book)
					{
						return null;
					}

					++i;
				}
			}
		}

		if (itemstack != null && i >= 1)
		{
			ItemStack itemstack2 = new ItemStack(Items.written_book, i + 1);
			itemstack2.setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());

			if (itemstack.hasDisplayName())
			{
				itemstack2.setStackDisplayName(itemstack.getDisplayName());
			}

			return itemstack2;
		}
		else
		{
			return null;
		}
	}

	public int getRecipeSize()
	{
		return 9;
	}

	public ItemStack getRecipeOutput()
	{
		return null;
	}
}