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