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