001package net.minecraft.entity; 002 003import java.util.HashMap; 004import java.util.LinkedHashMap; 005import java.util.Map; 006import java.util.logging.Level; 007 008import cpw.mods.fml.common.FMLLog; 009import net.minecraft.entity.ai.EntityMinecartMobSpawner; 010import net.minecraft.entity.boss.EntityDragon; 011import net.minecraft.entity.boss.EntityWither; 012import net.minecraft.entity.item.EntityBoat; 013import net.minecraft.entity.item.EntityEnderCrystal; 014import net.minecraft.entity.item.EntityEnderEye; 015import net.minecraft.entity.item.EntityEnderPearl; 016import net.minecraft.entity.item.EntityExpBottle; 017import net.minecraft.entity.item.EntityFallingSand; 018import net.minecraft.entity.item.EntityFireworkRocket; 019import net.minecraft.entity.item.EntityItem; 020import net.minecraft.entity.item.EntityItemFrame; 021import net.minecraft.entity.item.EntityMinecartChest; 022import net.minecraft.entity.item.EntityMinecartEmpty; 023import net.minecraft.entity.item.EntityMinecartFurnace; 024import net.minecraft.entity.item.EntityMinecartHopper; 025import net.minecraft.entity.item.EntityMinecartTNT; 026import net.minecraft.entity.item.EntityPainting; 027import net.minecraft.entity.item.EntityTNTPrimed; 028import net.minecraft.entity.item.EntityXPOrb; 029import net.minecraft.entity.monster.EntityBlaze; 030import net.minecraft.entity.monster.EntityCaveSpider; 031import net.minecraft.entity.monster.EntityCreeper; 032import net.minecraft.entity.monster.EntityEnderman; 033import net.minecraft.entity.monster.EntityGhast; 034import net.minecraft.entity.monster.EntityGiantZombie; 035import net.minecraft.entity.monster.EntityIronGolem; 036import net.minecraft.entity.monster.EntityMagmaCube; 037import net.minecraft.entity.monster.EntityMob; 038import net.minecraft.entity.monster.EntityPigZombie; 039import net.minecraft.entity.monster.EntitySilverfish; 040import net.minecraft.entity.monster.EntitySkeleton; 041import net.minecraft.entity.monster.EntitySlime; 042import net.minecraft.entity.monster.EntitySnowman; 043import net.minecraft.entity.monster.EntitySpider; 044import net.minecraft.entity.monster.EntityWitch; 045import net.minecraft.entity.monster.EntityZombie; 046import net.minecraft.entity.passive.EntityBat; 047import net.minecraft.entity.passive.EntityChicken; 048import net.minecraft.entity.passive.EntityCow; 049import net.minecraft.entity.passive.EntityMooshroom; 050import net.minecraft.entity.passive.EntityOcelot; 051import net.minecraft.entity.passive.EntityPig; 052import net.minecraft.entity.passive.EntitySheep; 053import net.minecraft.entity.passive.EntitySquid; 054import net.minecraft.entity.passive.EntityVillager; 055import net.minecraft.entity.passive.EntityWolf; 056import net.minecraft.entity.projectile.EntityArrow; 057import net.minecraft.entity.projectile.EntityLargeFireball; 058import net.minecraft.entity.projectile.EntityPotion; 059import net.minecraft.entity.projectile.EntitySmallFireball; 060import net.minecraft.entity.projectile.EntitySnowball; 061import net.minecraft.entity.projectile.EntityWitherSkull; 062import net.minecraft.nbt.NBTTagCompound; 063import net.minecraft.world.World; 064 065public class EntityList 066{ 067 /** Provides a mapping between entity classes and a string */ 068 public static Map stringToClassMapping = new HashMap(); 069 070 /** Provides a mapping between a string and an entity classes */ 071 public static Map classToStringMapping = new HashMap(); 072 073 /** provides a mapping between an entityID and an Entity Class */ 074 public static Map IDtoClassMapping = new HashMap(); 075 076 /** provides a mapping between an Entity Class and an entity ID */ 077 private static Map classToIDMapping = new HashMap(); 078 079 /** Maps entity names to their numeric identifiers */ 080 private static Map stringToIDMapping = new HashMap(); 081 082 /** This is a HashMap of the Creative Entity Eggs/Spawners. */ 083 public static HashMap entityEggs = new LinkedHashMap(); 084 085 /** 086 * adds a mapping between Entity classes and both a string representation and an ID 087 */ 088 public static void addMapping(Class par0Class, String par1Str, int par2) 089 { 090 stringToClassMapping.put(par1Str, par0Class); 091 classToStringMapping.put(par0Class, par1Str); 092 IDtoClassMapping.put(Integer.valueOf(par2), par0Class); 093 classToIDMapping.put(par0Class, Integer.valueOf(par2)); 094 stringToIDMapping.put(par1Str, Integer.valueOf(par2)); 095 } 096 097 /** 098 * Adds a entity mapping with egg info. 099 */ 100 public static void addMapping(Class par0Class, String par1Str, int par2, int par3, int par4) 101 { 102 addMapping(par0Class, par1Str, par2); 103 entityEggs.put(Integer.valueOf(par2), new EntityEggInfo(par2, par3, par4)); 104 } 105 106 /** 107 * Create a new instance of an entity in the world by using the entity name. 108 */ 109 public static Entity createEntityByName(String par0Str, World par1World) 110 { 111 Entity entity = null; 112 113 try 114 { 115 Class oclass = (Class)stringToClassMapping.get(par0Str); 116 117 if (oclass != null) 118 { 119 entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par1World}); 120 } 121 } 122 catch (Exception exception) 123 { 124 exception.printStackTrace(); 125 } 126 127 return entity; 128 } 129 130 /** 131 * create a new instance of an entity from NBT store 132 */ 133 public static Entity createEntityFromNBT(NBTTagCompound par0NBTTagCompound, World par1World) 134 { 135 Entity entity = null; 136 137 if ("Minecart".equals(par0NBTTagCompound.getString("id"))) 138 { 139 switch (par0NBTTagCompound.getInteger("Type")) 140 { 141 case 0: 142 par0NBTTagCompound.setString("id", "MinecartRideable"); 143 break; 144 case 1: 145 par0NBTTagCompound.setString("id", "MinecartChest"); 146 break; 147 case 2: 148 par0NBTTagCompound.setString("id", "MinecartFurnace"); 149 } 150 151 par0NBTTagCompound.removeTag("Type"); 152 } 153 154 Class oclass = null; 155 try 156 { 157 oclass = (Class)stringToClassMapping.get(par0NBTTagCompound.getString("id")); 158 159 if (oclass != null) 160 { 161 entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par1World}); 162 } 163 } 164 catch (Exception exception) 165 { 166 exception.printStackTrace(); 167 } 168 169 if (entity != null) 170 { 171 try 172 { 173 entity.readFromNBT(par0NBTTagCompound); 174 } 175 catch (Exception e) 176 { 177 FMLLog.log(Level.SEVERE, e, 178 "An Entity %s(%s) has thrown an exception during loading, its state cannot be restored. Report this to the mod author", 179 par0NBTTagCompound.getString("id"), oclass.getName()); 180 entity = null; 181 } 182 } 183 else 184 { 185 par1World.func_98180_V().func_98236_b("Skipping Entity with id " + par0NBTTagCompound.getString("id")); 186 } 187 188 return entity; 189 } 190 191 /** 192 * Create a new instance of an entity in the world by using an entity ID. 193 */ 194 public static Entity createEntityByID(int par0, World par1World) 195 { 196 Entity entity = null; 197 198 try 199 { 200 Class oclass = getClassFromID(par0); 201 202 if (oclass != null) 203 { 204 entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par1World}); 205 } 206 } 207 catch (Exception exception) 208 { 209 exception.printStackTrace(); 210 } 211 212 if (entity == null) 213 { 214 par1World.func_98180_V().func_98236_b("Skipping Entity with id " + par0); 215 } 216 217 return entity; 218 } 219 220 /** 221 * gets the entityID of a specific entity 222 */ 223 public static int getEntityID(Entity par0Entity) 224 { 225 Class oclass = par0Entity.getClass(); 226 return classToIDMapping.containsKey(oclass) ? ((Integer)classToIDMapping.get(oclass)).intValue() : 0; 227 } 228 229 /** 230 * Return the class assigned to this entity ID. 231 */ 232 public static Class getClassFromID(int par0) 233 { 234 return (Class)IDtoClassMapping.get(Integer.valueOf(par0)); 235 } 236 237 /** 238 * Gets the string representation of a specific entity. 239 */ 240 public static String getEntityString(Entity par0Entity) 241 { 242 return (String)classToStringMapping.get(par0Entity.getClass()); 243 } 244 245 /** 246 * Finds the class using IDtoClassMapping and classToStringMapping 247 */ 248 public static String getStringFromID(int par0) 249 { 250 Class oclass = getClassFromID(par0); 251 return oclass != null ? (String)classToStringMapping.get(oclass) : null; 252 } 253 254 static 255 { 256 addMapping(EntityItem.class, "Item", 1); 257 addMapping(EntityXPOrb.class, "XPOrb", 2); 258 addMapping(EntityPainting.class, "Painting", 9); 259 addMapping(EntityArrow.class, "Arrow", 10); 260 addMapping(EntitySnowball.class, "Snowball", 11); 261 addMapping(EntityLargeFireball.class, "Fireball", 12); 262 addMapping(EntitySmallFireball.class, "SmallFireball", 13); 263 addMapping(EntityEnderPearl.class, "ThrownEnderpearl", 14); 264 addMapping(EntityEnderEye.class, "EyeOfEnderSignal", 15); 265 addMapping(EntityPotion.class, "ThrownPotion", 16); 266 addMapping(EntityExpBottle.class, "ThrownExpBottle", 17); 267 addMapping(EntityItemFrame.class, "ItemFrame", 18); 268 addMapping(EntityWitherSkull.class, "WitherSkull", 19); 269 addMapping(EntityTNTPrimed.class, "PrimedTnt", 20); 270 addMapping(EntityFallingSand.class, "FallingSand", 21); 271 addMapping(EntityFireworkRocket.class, "FireworksRocketEntity", 22); 272 addMapping(EntityBoat.class, "Boat", 41); 273 addMapping(EntityMinecartEmpty.class, "MinecartRideable", 42); 274 addMapping(EntityMinecartChest.class, "MinecartChest", 43); 275 addMapping(EntityMinecartFurnace.class, "MinecartFurnace", 44); 276 addMapping(EntityMinecartTNT.class, "MinecartTNT", 45); 277 addMapping(EntityMinecartHopper.class, "MinecartHopper", 46); 278 addMapping(EntityMinecartMobSpawner.class, "MinecartSpawner", 47); 279 addMapping(EntityLiving.class, "Mob", 48); 280 addMapping(EntityMob.class, "Monster", 49); 281 addMapping(EntityCreeper.class, "Creeper", 50, 894731, 0); 282 addMapping(EntitySkeleton.class, "Skeleton", 51, 12698049, 4802889); 283 addMapping(EntitySpider.class, "Spider", 52, 3419431, 11013646); 284 addMapping(EntityGiantZombie.class, "Giant", 53); 285 addMapping(EntityZombie.class, "Zombie", 54, 44975, 7969893); 286 addMapping(EntitySlime.class, "Slime", 55, 5349438, 8306542); 287 addMapping(EntityGhast.class, "Ghast", 56, 16382457, 12369084); 288 addMapping(EntityPigZombie.class, "PigZombie", 57, 15373203, 5009705); 289 addMapping(EntityEnderman.class, "Enderman", 58, 1447446, 0); 290 addMapping(EntityCaveSpider.class, "CaveSpider", 59, 803406, 11013646); 291 addMapping(EntitySilverfish.class, "Silverfish", 60, 7237230, 3158064); 292 addMapping(EntityBlaze.class, "Blaze", 61, 16167425, 16775294); 293 addMapping(EntityMagmaCube.class, "LavaSlime", 62, 3407872, 16579584); 294 addMapping(EntityDragon.class, "EnderDragon", 63); 295 addMapping(EntityWither.class, "WitherBoss", 64); 296 addMapping(EntityBat.class, "Bat", 65, 4996656, 986895); 297 addMapping(EntityWitch.class, "Witch", 66, 3407872, 5349438); 298 addMapping(EntityPig.class, "Pig", 90, 15771042, 14377823); 299 addMapping(EntitySheep.class, "Sheep", 91, 15198183, 16758197); 300 addMapping(EntityCow.class, "Cow", 92, 4470310, 10592673); 301 addMapping(EntityChicken.class, "Chicken", 93, 10592673, 16711680); 302 addMapping(EntitySquid.class, "Squid", 94, 2243405, 7375001); 303 addMapping(EntityWolf.class, "Wolf", 95, 14144467, 13545366); 304 addMapping(EntityMooshroom.class, "MushroomCow", 96, 10489616, 12040119); 305 addMapping(EntitySnowman.class, "SnowMan", 97); 306 addMapping(EntityOcelot.class, "Ozelot", 98, 15720061, 5653556); 307 addMapping(EntityIronGolem.class, "VillagerGolem", 99); 308 addMapping(EntityVillager.class, "Villager", 120, 5651507, 12422002); 309 addMapping(EntityEnderCrystal.class, "EnderCrystal", 200); 310 } 311}