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 ItemSkull extends Item
008    {
009        private static final String[] skullTypes = new String[] {"skeleton", "wither", "zombie", "char", "creeper"};
010        private static final int[] field_82806_b = new int[] {224, 225, 226, 227, 228};
011    
012        public ItemSkull(int par1)
013        {
014            super(par1);
015            this.setCreativeTab(CreativeTabs.tabDecorations);
016            this.setMaxDamage(0);
017            this.setHasSubtypes(true);
018        }
019    
020        /**
021         * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
022         * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
023         */
024        public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
025        {
026            if (par7 == 0)
027            {
028                return false;
029            }
030            else if (!par3World.getBlockMaterial(par4, par5, par6).isSolid())
031            {
032                return false;
033            }
034            else
035            {
036                if (par7 == 1)
037                {
038                    ++par5;
039                }
040    
041                if (par7 == 2)
042                {
043                    --par6;
044                }
045    
046                if (par7 == 3)
047                {
048                    ++par6;
049                }
050    
051                if (par7 == 4)
052                {
053                    --par4;
054                }
055    
056                if (par7 == 5)
057                {
058                    ++par4;
059                }
060    
061                if (!par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack))
062                {
063                    return false;
064                }
065                else if (!Block.skull.canPlaceBlockAt(par3World, par4, par5, par6))
066                {
067                    return false;
068                }
069                else
070                {
071                    par3World.setBlockAndMetadataWithNotify(par4, par5, par6, Block.skull.blockID, par7);
072                    int var11 = 0;
073    
074                    if (par7 == 1)
075                    {
076                        var11 = MathHelper.floor_double((double)(par2EntityPlayer.rotationYaw * 16.0F / 360.0F) + 0.5D) & 15;
077                    }
078    
079                    TileEntity var12 = par3World.getBlockTileEntity(par4, par5, par6);
080    
081                    if (var12 != null && var12 instanceof TileEntitySkull)
082                    {
083                        String var13 = "";
084    
085                        if (par1ItemStack.hasTagCompound() && par1ItemStack.getTagCompound().hasKey("SkullOwner"))
086                        {
087                            var13 = par1ItemStack.getTagCompound().getString("SkullOwner");
088                        }
089    
090                        ((TileEntitySkull)var12).func_82118_a(par1ItemStack.getItemDamage(), var13);
091                        ((TileEntitySkull)var12).func_82116_a(var11);
092                        ((BlockSkull)Block.skull).func_82529_a(par3World, par4, par5, par6, (TileEntitySkull)var12);
093                    }
094    
095                    --par1ItemStack.stackSize;
096                    return true;
097                }
098            }
099        }
100    
101        @SideOnly(Side.CLIENT)
102    
103        /**
104         * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
105         */
106        public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
107        {
108            for (int var4 = 0; var4 < skullTypes.length; ++var4)
109            {
110                par3List.add(new ItemStack(par1, 1, var4));
111            }
112        }
113    
114        /**
115         * Returns the metadata of the block which this Item (ItemBlock) can place
116         */
117        public int getMetadata(int par1)
118        {
119            return par1;
120        }
121    
122        @SideOnly(Side.CLIENT)
123    
124        /**
125         * Gets an icon index based on an item's damage value
126         */
127        public int getIconFromDamage(int par1)
128        {
129            if (par1 < 0 || par1 >= skullTypes.length)
130            {
131                par1 = 0;
132            }
133    
134            return field_82806_b[par1];
135        }
136    
137        public String getItemNameIS(ItemStack par1ItemStack)
138        {
139            int var2 = par1ItemStack.getItemDamage();
140    
141            if (var2 < 0 || var2 >= skullTypes.length)
142            {
143                var2 = 0;
144            }
145    
146            return super.getItemName() + "." + skullTypes[var2];
147        }
148    
149        public String getItemDisplayName(ItemStack par1ItemStack)
150        {
151            return par1ItemStack.getItemDamage() == 3 && par1ItemStack.hasTagCompound() && par1ItemStack.getTagCompound().hasKey("SkullOwner") ? StatCollector.translateToLocalFormatted("item.skull.player.name", new Object[] {par1ItemStack.getTagCompound().getString("SkullOwner")}): super.getItemDisplayName(par1ItemStack);
152        }
153    }