001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import cpw.mods.fml.common.registry.VillagerRegistry;
006    
007    import java.util.Iterator;
008    import java.util.List;
009    
010    public class ItemMonsterPlacer extends Item
011    {
012        public ItemMonsterPlacer(int par1)
013        {
014            super(par1);
015            this.setHasSubtypes(true);
016            this.setCreativeTab(CreativeTabs.tabMisc);
017        }
018    
019        @SideOnly(Side.CLIENT)
020        public String getItemDisplayName(ItemStack par1ItemStack)
021        {
022            String var2 = ("" + StatCollector.translateToLocal(this.getItemName() + ".name")).trim();
023            String var3 = EntityList.getStringFromID(par1ItemStack.getItemDamage());
024    
025            if (var3 != null)
026            {
027                var2 = var2 + " " + StatCollector.translateToLocal("entity." + var3 + ".name");
028            }
029    
030            return var2;
031        }
032    
033        @SideOnly(Side.CLIENT)
034        public int getColorFromDamage(int par1, int par2)
035        {
036            EntityEggInfo var3 = (EntityEggInfo)EntityList.entityEggs.get(Integer.valueOf(par1));
037            return var3 != null ? (par2 == 0 ? var3.primaryColor : var3.secondaryColor) : 16777215;
038        }
039    
040        /**
041         * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
042         * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
043         */
044        public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
045        {
046            if (par3World.isRemote)
047            {
048                return true;
049            }
050            else
051            {
052                int var11 = par3World.getBlockId(par4, par5, par6);
053                par4 += Facing.offsetsXForSide[par7];
054                par5 += Facing.offsetsYForSide[par7];
055                par6 += Facing.offsetsZForSide[par7];
056                double var12 = 0.0D;
057    
058                if (par7 == 1 && var11 == Block.fence.blockID || var11 == Block.netherFence.blockID)
059                {
060                    var12 = 0.5D;
061                }
062    
063                if (spawnCreature(par3World, par1ItemStack.getItemDamage(), (double)par4 + 0.5D, (double)par5 + var12, (double)par6 + 0.5D) && !par2EntityPlayer.capabilities.isCreativeMode)
064                {
065                    --par1ItemStack.stackSize;
066                }
067    
068                return true;
069            }
070        }
071    
072        /**
073         * Spawns the creature specified by the egg's type in the location specified by the last three parameters.
074         * Parameters: world, entityID, x, y, z.
075         */
076        public static boolean spawnCreature(World par0World, int par1, double par2, double par4, double par6)
077        {
078            if (!EntityList.entityEggs.containsKey(Integer.valueOf(par1)))
079            {
080                return false;
081            }
082            else
083            {
084                Entity var8 = EntityList.createEntityByID(par1, par0World);
085    
086                if (var8 != null)
087                {
088                    var8.setLocationAndAngles(par2, par4, par6, par0World.rand.nextFloat() * 360.0F, 0.0F);
089    
090                    if (var8 instanceof EntityVillager)
091                    {
092                        EntityVillager var9 = (EntityVillager)var8;
093                        VillagerRegistry.applyRandomTrade(var9, var9.getRNG());
094                        par0World.spawnEntityInWorld(var9);
095                        return true;
096                    }
097    
098                    par0World.spawnEntityInWorld(var8);
099                    ((EntityLiving)var8).playLivingSound();
100                }
101    
102                return var8 != null;
103            }
104        }
105    
106        @SideOnly(Side.CLIENT)
107        public boolean requiresMultipleRenderPasses()
108        {
109            return true;
110        }
111    
112        @SideOnly(Side.CLIENT)
113    
114        /**
115         * Gets an icon index based on an item's damage value and the given render pass
116         */
117        public int getIconFromDamageForRenderPass(int par1, int par2)
118        {
119            return par2 > 0 ? super.getIconFromDamageForRenderPass(par1, par2) + 16 : super.getIconFromDamageForRenderPass(par1, par2);
120        }
121    
122        @SideOnly(Side.CLIENT)
123    
124        /**
125         * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
126         */
127        public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
128        {
129            Iterator var4 = EntityList.entityEggs.values().iterator();
130    
131            while (var4.hasNext())
132            {
133                EntityEggInfo var5 = (EntityEggInfo)var4.next();
134                par3List.add(new ItemStack(par1, 1, var5.spawnedID));
135            }
136        }
137    }