package net.minecraft.item;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.util.StringUtils;
import net.minecraft.world.World;

public class ItemEditableBook extends Item
{
	private static final String __OBFID = "CL_00000077";

	public ItemEditableBook()
	{
		this.setMaxStackSize(1);
	}

	public static boolean validBookTagContents(NBTTagCompound par0NBTTagCompound)
	{
		if (!ItemWritableBook.func_150930_a(par0NBTTagCompound))
		{
			return false;
		}
		else if (!par0NBTTagCompound.hasKey("title", 8))
		{
			return false;
		}
		else
		{
			String s = par0NBTTagCompound.getString("title");
			return s != null && s.length() <= 16 ? par0NBTTagCompound.hasKey("author", 8) : false;
		}
	}

	public String getItemStackDisplayName(ItemStack par1ItemStack)
	{
		if (par1ItemStack.hasTagCompound())
		{
			NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();
			String s = nbttagcompound.getString("title");

			if (!StringUtils.isNullOrEmpty(s))
			{
				return s;
			}
		}

		return super.getItemStackDisplayName(par1ItemStack);
	}

	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
	{
		if (par1ItemStack.hasTagCompound())
		{
			NBTTagCompound nbttagcompound = par1ItemStack.getTagCompound();
			String s = nbttagcompound.getString("author");

			if (!StringUtils.isNullOrEmpty(s))
			{
				par3List.add(EnumChatFormatting.GRAY + StatCollector.translateToLocalFormatted("book.byAuthor", new Object[] {s}));
			}
		}
	}

	public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
	{
		par3EntityPlayer.displayGUIBook(par1ItemStack);
		return par1ItemStack;
	}

	public boolean getShareTag()
	{
		return true;
	}

	@SideOnly(Side.CLIENT)
	public boolean hasEffect(ItemStack par1ItemStack)
	{
		return true;
	}
}