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