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