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