    001package net.minecraft.item;
    002
    003import net.minecraft.entity.player.EntityPlayer;
    004import net.minecraft.nbt.NBTTagCompound;
    005import net.minecraft.nbt.NBTTagList;
    006import net.minecraft.nbt.NBTTagString;
    007import net.minecraft.world.World;
    008
    009public class ItemWritableBook extends Item
    010{
    011    public ItemWritableBook(int par1)
    012    {
    013        super(par1);
    014        this.setMaxStackSize(1);
    015    }
    016
    017    /**
    018     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    019     */
    020    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    021    {
    022        par3EntityPlayer.displayGUIBook(par1ItemStack);
    023        return par1ItemStack;
    024    }
    025
    026    /**
    027     * If this function returns true (or the item is damageable), the ItemStack's NBT tag will be sent to the client.
    028     */
    029    public boolean getShareTag()
    030    {
    031        return true;
    032    }
    033
    034    public static boolean validBookTagPages(NBTTagCompound par0NBTTagCompound)
    035    {
    036        if (par0NBTTagCompound == null)
    037        {
    038            return false;
    039        }
    040        else if (!par0NBTTagCompound.hasKey("pages"))
    041        {
    042            return false;
    043        }
    044        else
    045        {
    046            NBTTagList var1 = (NBTTagList)par0NBTTagCompound.getTag("pages");
    047
    048            for (int var2 = 0; var2 < var1.tagCount(); ++var2)
    049            {
    050                NBTTagString var3 = (NBTTagString)var1.tagAt(var2);
    051
    052                if (var3.data == null)
    053                {
    054                    return false;
    055                }
    056
    057                if (var3.data.length() > 256)
    058                {
    059                    return false;
    060                }
    061            }
    062
    063            return true;
    064        }
    065    }
    066}