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