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