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