    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        /**
    157         * Gets the string representation of a specific entity.
    158         */
    159        public static String getEntityString(Entity par0Entity)
    160        {
    161            return (String)classToStringMapping.get(par0Entity.getClass());
    162        }
    163
    164        /**
    165         * Finds the class using IDtoClassMapping and classToStringMapping
    166         */
    167        public static String getStringFromID(int par0)
    168        {
    169            Class var1 = (Class)IDtoClassMapping.get(Integer.valueOf(par0));
    170            return var1 != null ? (String)classToStringMapping.get(var1) : null;
    171        }
    172
    173        static
    174        {
    175            addMapping(EntityItem.class, "Item", 1);
    176            addMapping(EntityXPOrb.class, "XPOrb", 2);
    177            addMapping(EntityPainting.class, "Painting", 9);
    178            addMapping(EntityArrow.class, "Arrow", 10);
    179            addMapping(EntitySnowball.class, "Snowball", 11);
    180            addMapping(EntityLargeFireball.class, "Fireball", 12);
    181            addMapping(EntitySmallFireball.class, "SmallFireball", 13);
    182            addMapping(EntityEnderPearl.class, "ThrownEnderpearl", 14);
    183            addMapping(EntityEnderEye.class, "EyeOfEnderSignal", 15);
    184            addMapping(EntityPotion.class, "ThrownPotion", 16);
    185            addMapping(EntityExpBottle.class, "ThrownExpBottle", 17);
    186            addMapping(EntityItemFrame.class, "ItemFrame", 18);
    187            addMapping(EntityWitherSkull.class, "WitherSkull", 19);
    188            addMapping(EntityTNTPrimed.class, "PrimedTnt", 20);
    189            addMapping(EntityFallingSand.class, "FallingSand", 21);
    190            addMapping(EntityMinecart.class, "Minecart", 40);
    191            addMapping(EntityBoat.class, "Boat", 41);
    192            addMapping(EntityLiving.class, "Mob", 48);
    193            addMapping(EntityMob.class, "Monster", 49);
    194            addMapping(EntityCreeper.class, "Creeper", 50, 894731, 0);
    195            addMapping(EntitySkeleton.class, "Skeleton", 51, 12698049, 4802889);
    196            addMapping(EntitySpider.class, "Spider", 52, 3419431, 11013646);
    197            addMapping(EntityGiantZombie.class, "Giant", 53);
    198            addMapping(EntityZombie.class, "Zombie", 54, 44975, 7969893);
    199            addMapping(EntitySlime.class, "Slime", 55, 5349438, 8306542);
    200            addMapping(EntityGhast.class, "Ghast", 56, 16382457, 12369084);
    201            addMapping(EntityPigZombie.class, "PigZombie", 57, 15373203, 5009705);
    202            addMapping(EntityEnderman.class, "Enderman", 58, 1447446, 0);
    203            addMapping(EntityCaveSpider.class, "CaveSpider", 59, 803406, 11013646);
    204            addMapping(EntitySilverfish.class, "Silverfish", 60, 7237230, 3158064);
    205            addMapping(EntityBlaze.class, "Blaze", 61, 16167425, 16775294);
    206            addMapping(EntityMagmaCube.class, "LavaSlime", 62, 3407872, 16579584);
    207            addMapping(EntityDragon.class, "EnderDragon", 63);
    208            addMapping(EntityWither.class, "WitherBoss", 64);
    209            addMapping(EntityBat.class, "Bat", 65, 4996656, 986895);
    210            addMapping(EntityWitch.class, "Witch", 66, 3407872, 5349438);
    211            addMapping(EntityPig.class, "Pig", 90, 15771042, 14377823);
    212            addMapping(EntitySheep.class, "Sheep", 91, 15198183, 16758197);
    213            addMapping(EntityCow.class, "Cow", 92, 4470310, 10592673);
    214            addMapping(EntityChicken.class, "Chicken", 93, 10592673, 16711680);
    215            addMapping(EntitySquid.class, "Squid", 94, 2243405, 7375001);
    216            addMapping(EntityWolf.class, "Wolf", 95, 14144467, 13545366);
    217            addMapping(EntityMooshroom.class, "MushroomCow", 96, 10489616, 12040119);
    218            addMapping(EntitySnowman.class, "SnowMan", 97);
    219            addMapping(EntityOcelot.class, "Ozelot", 98, 15720061, 5653556);
    220            addMapping(EntityIronGolem.class, "VillagerGolem", 99);
    221            addMapping(EntityVillager.class, "Villager", 120, 5651507, 12422002);
    222            addMapping(EntityEnderCrystal.class, "EnderCrystal", 200);
    223        }
    224    }