001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005 import java.util.List;
006
007 public class ItemEditableBook extends Item
008 {
009 public ItemEditableBook(int par1)
010 {
011 super(par1);
012 this.setMaxStackSize(1);
013 }
014
015 public static boolean validBookTagContents(NBTTagCompound par0NBTTagCompound)
016 {
017 if (!ItemWritableBook.validBookTagPages(par0NBTTagCompound))
018 {
019 return false;
020 }
021 else if (!par0NBTTagCompound.hasKey("title"))
022 {
023 return false;
024 }
025 else
026 {
027 String var1 = par0NBTTagCompound.getString("title");
028 return var1 != null && var1.length() <= 16 ? par0NBTTagCompound.hasKey("author") : false;
029 }
030 }
031
032 public String getItemDisplayName(ItemStack par1ItemStack)
033 {
034 if (par1ItemStack.hasTagCompound())
035 {
036 NBTTagCompound var2 = par1ItemStack.getTagCompound();
037 NBTTagString var3 = (NBTTagString)var2.getTag("title");
038
039 if (var3 != null)
040 {
041 return var3.toString();
042 }
043 }
044
045 return super.getItemDisplayName(par1ItemStack);
046 }
047
048 @SideOnly(Side.CLIENT)
049
050 /**
051 * allows items to add custom lines of information to the mouseover description
052 */
053 public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
054 {
055 if (par1ItemStack.hasTagCompound())
056 {
057 NBTTagCompound var5 = par1ItemStack.getTagCompound();
058 NBTTagString var6 = (NBTTagString)var5.getTag("author");
059
060 if (var6 != null)
061 {
062 par3List.add("\u00a77" + String.format(StatCollector.translateToLocalFormatted("book.byAuthor", new Object[] {var6.data}), new Object[0]));
063 }
064 }
065 }
066
067 /**
068 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
069 */
070 public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
071 {
072 par3EntityPlayer.displayGUIBook(par1ItemStack);
073 return par1ItemStack;
074 }
075
076 /**
077 * If this function returns true (or the item is damageable), the ItemStack's NBT tag will be sent to the client.
078 */
079 public boolean getShareTag()
080 {
081 return true;
082 }
083
084 @SideOnly(Side.CLIENT)
085 public boolean hasEffect(ItemStack par1ItemStack)
086 {
087 return true;
088 }
089 }