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