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