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