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 /** 033 * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer 034 */ 035 public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) 036 { 037 par3EntityPlayer.displayGUIBook(par1ItemStack); 038 return par1ItemStack; 039 } 040 041 @SideOnly(Side.CLIENT) 042 public String getItemDisplayName(ItemStack par1ItemStack) 043 { 044 if (par1ItemStack.hasTagCompound()) 045 { 046 NBTTagCompound var2 = par1ItemStack.getTagCompound(); 047 NBTTagString var3 = (NBTTagString)var2.getTag("title"); 048 049 if (var3 != null) 050 { 051 return var3.toString(); 052 } 053 } 054 055 return super.getItemDisplayName(par1ItemStack); 056 } 057 058 @SideOnly(Side.CLIENT) 059 060 /** 061 * allows items to add custom lines of information to the mouseover description 062 */ 063 public void addInformation(ItemStack par1ItemStack, List par2List) 064 { 065 if (par1ItemStack.hasTagCompound()) 066 { 067 NBTTagCompound var3 = par1ItemStack.getTagCompound(); 068 NBTTagString var4 = (NBTTagString)var3.getTag("author"); 069 070 if (var4 != null) 071 { 072 par2List.add("\u00a77" + String.format(StatCollector.translateToLocalFormatted("book.byAuthor", new Object[] {var4.data}), new Object[0])); 073 } 074 } 075 } 076 077 /** 078 * If this function returns true (or the item is damageable), the ItemStack's NBT tag will be sent to the client. 079 */ 080 public boolean getShareTag() 081 { 082 return true; 083 } 084 085 @SideOnly(Side.CLIENT) 086 public boolean hasEffect(ItemStack par1ItemStack) 087 { 088 return true; 089 } 090 }