| 1 | package net.minecraft.entity;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Map;
|
| 7 | import java.util.Set;
|
| 8 | import net.minecraft.entity.ai.EntityMinecartMobSpawner;
|
| 9 | import net.minecraft.entity.boss.EntityDragon;
|
| 10 | import net.minecraft.entity.boss.EntityWither;
|
| 11 | import net.minecraft.entity.effect.EntityLightningBolt;
|
| 12 | import net.minecraft.entity.item.EntityArmorStand;
|
| 13 | import net.minecraft.entity.item.EntityBoat;
|
| 14 | import net.minecraft.entity.item.EntityEnderCrystal;
|
| 15 | import net.minecraft.entity.item.EntityEnderEye;
|
| 16 | import net.minecraft.entity.item.EntityEnderPearl;
|
| 17 | import net.minecraft.entity.item.EntityExpBottle;
|
| 18 | import net.minecraft.entity.item.EntityFallingBlock;
|
| 19 | import net.minecraft.entity.item.EntityFireworkRocket;
|
| 20 | import net.minecraft.entity.item.EntityItem;
|
| 21 | import net.minecraft.entity.item.EntityItemFrame;
|
| 22 | import net.minecraft.entity.item.EntityMinecart;
|
| 23 | import net.minecraft.entity.item.EntityMinecartChest;
|
| 24 | import net.minecraft.entity.item.EntityMinecartEmpty;
|
| 25 | import net.minecraft.entity.item.EntityMinecartFurnace;
|
| 26 | import net.minecraft.entity.item.EntityMinecartHopper;
|
| 27 | import net.minecraft.entity.item.EntityMinecartTNT;
|
| 28 | import net.minecraft.entity.item.EntityPainting;
|
| 29 | import net.minecraft.entity.item.EntityTNTPrimed;
|
| 30 | import net.minecraft.entity.item.EntityXPOrb;
|
| 31 | import net.minecraft.entity.monster.EntityBlaze;
|
| 32 | import net.minecraft.entity.monster.EntityCaveSpider;
|
| 33 | import net.minecraft.entity.monster.EntityCreeper;
|
| 34 | import net.minecraft.entity.monster.EntityEnderman;
|
| 35 | import net.minecraft.entity.monster.EntityEndermite;
|
| 36 | import net.minecraft.entity.monster.EntityGhast;
|
| 37 | import net.minecraft.entity.monster.EntityGiantZombie;
|
| 38 | import net.minecraft.entity.monster.EntityGuardian;
|
| 39 | import net.minecraft.entity.monster.EntityIronGolem;
|
| 40 | import net.minecraft.entity.monster.EntityMagmaCube;
|
| 41 | import net.minecraft.entity.monster.EntityMob;
|
| 42 | import net.minecraft.entity.monster.EntityPigZombie;
|
| 43 | import net.minecraft.entity.monster.EntitySilverfish;
|
| 44 | import net.minecraft.entity.monster.EntitySkeleton;
|
| 45 | import net.minecraft.entity.monster.EntitySlime;
|
| 46 | import net.minecraft.entity.monster.EntitySnowman;
|
| 47 | import net.minecraft.entity.monster.EntitySpider;
|
| 48 | import net.minecraft.entity.monster.EntityWitch;
|
| 49 | import net.minecraft.entity.monster.EntityZombie;
|
| 50 | import net.minecraft.entity.passive.EntityBat;
|
| 51 | import net.minecraft.entity.passive.EntityChicken;
|
| 52 | import net.minecraft.entity.passive.EntityCow;
|
| 53 | import net.minecraft.entity.passive.EntityHorse;
|
| 54 | import net.minecraft.entity.passive.EntityMooshroom;
|
| 55 | import net.minecraft.entity.passive.EntityOcelot;
|
| 56 | import net.minecraft.entity.passive.EntityPig;
|
| 57 | import net.minecraft.entity.passive.EntityRabbit;
|
| 58 | import net.minecraft.entity.passive.EntitySheep;
|
| 59 | import net.minecraft.entity.passive.EntitySquid;
|
| 60 | import net.minecraft.entity.passive.EntityVillager;
|
| 61 | import net.minecraft.entity.passive.EntityWolf;
|
| 62 | import net.minecraft.entity.player.EntityPlayer;
|
| 63 | import net.minecraft.entity.projectile.EntityArrow;
|
| 64 | import net.minecraft.entity.projectile.EntityEgg;
|
| 65 | import net.minecraft.entity.projectile.EntityLargeFireball;
|
| 66 | import net.minecraft.entity.projectile.EntityPotion;
|
| 67 | import net.minecraft.entity.projectile.EntitySmallFireball;
|
| 68 | import net.minecraft.entity.projectile.EntitySnowball;
|
| 69 | import net.minecraft.entity.projectile.EntityWitherSkull;
|
| 70 | import net.minecraft.nbt.NBTTagCompound;
|
| 71 | import net.minecraft.stats.StatBase;
|
| 72 | import net.minecraft.stats.StatList;
|
| 73 | import net.minecraft.world.World;
|
| 74 | import org.apache.logging.log4j.LogManager;
|
| 75 | import org.apache.logging.log4j.Logger;
|
| 76 |
|
| 77 | public class EntityList
|
| 78 | {
|
| 79 | private static final Logger logger = LogManager.getLogger();
|
| 80 | private static final Map < String, Class <? extends Entity >> stringToClassMapping = Maps. < String, Class <? extends Entity >> newHashMap();
|
| 81 | private static final Map < Class <? extends Entity > , String > classToStringMapping = Maps. < Class <? extends Entity > , String > newHashMap();
|
| 82 | private static final Map < Integer, Class <? extends Entity >> idToClassMapping = Maps. < Integer, Class <? extends Entity >> newHashMap();
|
| 83 | private static final Map < Class <? extends Entity > , Integer > classToIDMapping = Maps. < Class <? extends Entity > , Integer > newHashMap();
|
| 84 | private static final Map<String, Integer> stringToIDMapping = Maps.<String, Integer>newHashMap();
|
| 85 | public static final Map<Integer, EntityList.EntityEggInfo> entityEggs = Maps.<Integer, EntityList.EntityEggInfo>newLinkedHashMap();
|
| 86 |
|
| 87 | /**
|
| 88 | * adds a mapping between Entity classes and both a string representation and an ID
|
| 89 | */
|
| 90 | private static void addMapping(Class <? extends Entity > entityClass, String entityName, int id)
|
| 91 | {
|
| 92 | if (stringToClassMapping.containsKey(entityName))
|
| 93 | {
|
| 94 | throw new IllegalArgumentException("ID is already registered: " + entityName);
|
| 95 | }
|
| 96 | else if (idToClassMapping.containsKey(Integer.valueOf(id)))
|
| 97 | {
|
| 98 | throw new IllegalArgumentException("ID is already registered: " + id);
|
| 99 | }
|
| 100 | else if (id == 0)
|
| 101 | {
|
| 102 | throw new IllegalArgumentException("Cannot register to reserved id: " + id);
|
| 103 | }
|
| 104 | else if (entityClass == null)
|
| 105 | {
|
| 106 | throw new IllegalArgumentException("Cannot register null clazz for id: " + id);
|
| 107 | }
|
| 108 | else
|
| 109 | {
|
| 110 | stringToClassMapping.put(entityName, entityClass);
|
| 111 | classToStringMapping.put(entityClass, entityName);
|
| 112 | idToClassMapping.put(Integer.valueOf(id), entityClass);
|
| 113 | classToIDMapping.put(entityClass, Integer.valueOf(id));
|
| 114 | stringToIDMapping.put(entityName, Integer.valueOf(id));
|
| 115 | }
|
| 116 | }
|
| 117 |
|
| 118 | /**
|
| 119 | * Adds a entity mapping with egg info.
|
| 120 | */
|
| 121 | private static void addMapping(Class <? extends Entity > entityClass, String entityName, int entityID, int baseColor, int spotColor)
|
| 122 | {
|
| 123 | addMapping(entityClass, entityName, entityID);
|
| 124 | entityEggs.put(Integer.valueOf(entityID), new EntityList.EntityEggInfo(entityID, baseColor, spotColor));
|
| 125 | }
|
| 126 |
|
| 127 | /**
|
| 128 | * Create a new instance of an entity in the world by using the entity name.
|
| 129 | */
|
| 130 | public static Entity createEntityByName(String entityName, World worldIn)
|
| 131 | {
|
| 132 | Entity entity = null;
|
| 133 |
|
| 134 | try
|
| 135 | {
|
| 136 | Class <? extends Entity > oclass = (Class)stringToClassMapping.get(entityName);
|
| 137 |
|
| 138 | if (oclass != null)
|
| 139 | {
|
| 140 | entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {worldIn});
|
| 141 | }
|
| 142 | }
|
| 143 | catch (Exception exception)
|
| 144 | {
|
| 145 | exception.printStackTrace();
|
| 146 | }
|
| 147 |
|
| 148 | return entity;
|
| 149 | }
|
| 150 |
|
| 151 | /**
|
| 152 | * create a new instance of an entity from NBT store
|
| 153 | */
|
| 154 | public static Entity createEntityFromNBT(NBTTagCompound nbt, World worldIn)
|
| 155 | {
|
| 156 | Entity entity = null;
|
| 157 |
|
| 158 | if ("Minecart".equals(nbt.getString("id")))
|
| 159 | {
|
| 160 | nbt.setString("id", EntityMinecart.EnumMinecartType.byNetworkID(nbt.getInteger("Type")).getName());
|
| 161 | nbt.removeTag("Type");
|
| 162 | }
|
| 163 |
|
| 164 | try
|
| 165 | {
|
| 166 | Class <? extends Entity > oclass = (Class)stringToClassMapping.get(nbt.getString("id"));
|
| 167 |
|
| 168 | if (oclass != null)
|
| 169 | {
|
| 170 | entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {worldIn});
|
| 171 | }
|
| 172 | }
|
| 173 | catch (Exception exception)
|
| 174 | {
|
| 175 | exception.printStackTrace();
|
| 176 | }
|
| 177 |
|
| 178 | if (entity != null)
|
| 179 | {
|
| 180 | entity.readFromNBT(nbt);
|
| 181 | }
|
| 182 | else
|
| 183 | {
|
| 184 | logger.warn("Skipping Entity with id " + nbt.getString("id"));
|
| 185 | }
|
| 186 |
|
| 187 | return entity;
|
| 188 | }
|
| 189 |
|
| 190 | /**
|
| 191 | * Create a new instance of an entity in the world by using an entity ID.
|
| 192 | */
|
| 193 | public static Entity createEntityByID(int entityID, World worldIn)
|
| 194 | {
|
| 195 | Entity entity = null;
|
| 196 |
|
| 197 | try
|
| 198 | {
|
| 199 | Class <? extends Entity > oclass = getClassFromID(entityID);
|
| 200 |
|
| 201 | if (oclass != null)
|
| 202 | {
|
| 203 | entity = (Entity)oclass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {worldIn});
|
| 204 | }
|
| 205 | }
|
| 206 | catch (Exception exception)
|
| 207 | {
|
| 208 | exception.printStackTrace();
|
| 209 | }
|
| 210 |
|
| 211 | if (entity == null)
|
| 212 | {
|
| 213 | logger.warn("Skipping Entity with id " + entityID);
|
| 214 | }
|
| 215 |
|
| 216 | return entity;
|
| 217 | }
|
| 218 |
|
| 219 | /**
|
| 220 | * gets the entityID of a specific entity
|
| 221 | */
|
| 222 | public static int getEntityID(Entity entityIn)
|
| 223 | {
|
| 224 | Integer integer = (Integer)classToIDMapping.get(entityIn.getClass());
|
| 225 | return integer == null ? 0 : integer.intValue();
|
| 226 | }
|
| 227 |
|
| 228 | public static Class <? extends Entity > getClassFromID(int entityID)
|
| 229 | {
|
| 230 | return (Class)idToClassMapping.get(Integer.valueOf(entityID));
|
| 231 | }
|
| 232 |
|
| 233 | /**
|
| 234 | * Gets the string representation of a specific entity.
|
| 235 | */
|
| 236 | public static String getEntityString(Entity entityIn)
|
| 237 | {
|
| 238 | return (String)classToStringMapping.get(entityIn.getClass());
|
| 239 | }
|
| 240 |
|
| 241 | /**
|
| 242 | * Returns the ID assigned to it's string representation
|
| 243 | */
|
| 244 | public static int getIDFromString(String entityName)
|
| 245 | {
|
| 246 | Integer integer = (Integer)stringToIDMapping.get(entityName);
|
| 247 | return integer == null ? 90 : integer.intValue();
|
| 248 | }
|
| 249 |
|
| 250 | /**
|
| 251 | * Finds the class using IDtoClassMapping and classToStringMapping
|
| 252 | */
|
| 253 | public static String getStringFromID(int entityID)
|
| 254 | {
|
| 255 | return (String)classToStringMapping.get(getClassFromID(entityID));
|
| 256 | }
|
| 257 |
|
| 258 | public static void func_151514_a()
|
| 259 | {
|
| 260 | }
|
| 261 |
|
| 262 | public static List<String> getEntityNameList()
|
| 263 | {
|
| 264 | Set<String> set = stringToClassMapping.keySet();
|
| 265 | List<String> list = Lists.<String>newArrayList();
|
| 266 |
|
| 267 | for (String s : set)
|
| 268 | {
|
| 269 | Class <? extends Entity > oclass = (Class)stringToClassMapping.get(s);
|
| 270 |
|
| 271 | if ((oclass.getModifiers() & 1024) != 1024)
|
| 272 | {
|
| 273 | list.add(s);
|
| 274 | }
|
| 275 | }
|
| 276 |
|
| 277 | list.add("LightningBolt");
|
| 278 | return list;
|
| 279 | }
|
| 280 |
|
| 281 | public static boolean isStringEntityName(Entity entityIn, String entityName)
|
| 282 | {
|
| 283 | String s = getEntityString(entityIn);
|
| 284 |
|
| 285 | if (s == null && entityIn instanceof EntityPlayer)
|
| 286 | {
|
| 287 | s = "Player";
|
| 288 | }
|
| 289 | else if (s == null && entityIn instanceof EntityLightningBolt)
|
| 290 | {
|
| 291 | s = "LightningBolt";
|
| 292 | }
|
| 293 |
|
| 294 | return entityName.equals(s);
|
| 295 | }
|
| 296 |
|
| 297 | public static boolean isStringValidEntityName(String entityName)
|
| 298 | {
|
| 299 | return "Player".equals(entityName) || getEntityNameList().contains(entityName);
|
| 300 | }
|
| 301 |
|
| 302 | static
|
| 303 | {
|
| 304 | addMapping(EntityItem.class, "Item", 1);
|
| 305 | addMapping(EntityXPOrb.class, "XPOrb", 2);
|
| 306 | addMapping(EntityEgg.class, "ThrownEgg", 7);
|
| 307 | addMapping(EntityLeashKnot.class, "LeashKnot", 8);
|
| 308 | addMapping(EntityPainting.class, "Painting", 9);
|
| 309 | addMapping(EntityArrow.class, "Arrow", 10);
|
| 310 | addMapping(EntitySnowball.class, "Snowball", 11);
|
| 311 | addMapping(EntityLargeFireball.class, "Fireball", 12);
|
| 312 | addMapping(EntitySmallFireball.class, "SmallFireball", 13);
|
| 313 | addMapping(EntityEnderPearl.class, "ThrownEnderpearl", 14);
|
| 314 | addMapping(EntityEnderEye.class, "EyeOfEnderSignal", 15);
|
| 315 | addMapping(EntityPotion.class, "ThrownPotion", 16);
|
| 316 | addMapping(EntityExpBottle.class, "ThrownExpBottle", 17);
|
| 317 | addMapping(EntityItemFrame.class, "ItemFrame", 18);
|
| 318 | addMapping(EntityWitherSkull.class, "WitherSkull", 19);
|
| 319 | addMapping(EntityTNTPrimed.class, "PrimedTnt", 20);
|
| 320 | addMapping(EntityFallingBlock.class, "FallingSand", 21);
|
| 321 | addMapping(EntityFireworkRocket.class, "FireworksRocketEntity", 22);
|
| 322 | addMapping(EntityArmorStand.class, "ArmorStand", 30);
|
| 323 | addMapping(EntityBoat.class, "Boat", 41);
|
| 324 | addMapping(EntityMinecartEmpty.class, EntityMinecart.EnumMinecartType.RIDEABLE.getName(), 42);
|
| 325 | addMapping(EntityMinecartChest.class, EntityMinecart.EnumMinecartType.CHEST.getName(), 43);
|
| 326 | addMapping(EntityMinecartFurnace.class, EntityMinecart.EnumMinecartType.FURNACE.getName(), 44);
|
| 327 | addMapping(EntityMinecartTNT.class, EntityMinecart.EnumMinecartType.TNT.getName(), 45);
|
| 328 | addMapping(EntityMinecartHopper.class, EntityMinecart.EnumMinecartType.HOPPER.getName(), 46);
|
| 329 | addMapping(EntityMinecartMobSpawner.class, EntityMinecart.EnumMinecartType.SPAWNER.getName(), 47);
|
| 330 | addMapping(EntityMinecartCommandBlock.class, EntityMinecart.EnumMinecartType.COMMAND_BLOCK.getName(), 40);
|
| 331 | addMapping(EntityLiving.class, "Mob", 48);
|
| 332 | addMapping(EntityMob.class, "Monster", 49);
|
| 333 | addMapping(EntityCreeper.class, "Creeper", 50, 894731, 0);
|
| 334 | addMapping(EntitySkeleton.class, "Skeleton", 51, 12698049, 4802889);
|
| 335 | addMapping(EntitySpider.class, "Spider", 52, 3419431, 11013646);
|
| 336 | addMapping(EntityGiantZombie.class, "Giant", 53);
|
| 337 | addMapping(EntityZombie.class, "Zombie", 54, 44975, 7969893);
|
| 338 | addMapping(EntitySlime.class, "Slime", 55, 5349438, 8306542);
|
| 339 | addMapping(EntityGhast.class, "Ghast", 56, 16382457, 12369084);
|
| 340 | addMapping(EntityPigZombie.class, "PigZombie", 57, 15373203, 5009705);
|
| 341 | addMapping(EntityEnderman.class, "Enderman", 58, 1447446, 0);
|
| 342 | addMapping(EntityCaveSpider.class, "CaveSpider", 59, 803406, 11013646);
|
| 343 | addMapping(EntitySilverfish.class, "Silverfish", 60, 7237230, 3158064);
|
| 344 | addMapping(EntityBlaze.class, "Blaze", 61, 16167425, 16775294);
|
| 345 | addMapping(EntityMagmaCube.class, "LavaSlime", 62, 3407872, 16579584);
|
| 346 | addMapping(EntityDragon.class, "EnderDragon", 63);
|
| 347 | addMapping(EntityWither.class, "WitherBoss", 64);
|
| 348 | addMapping(EntityBat.class, "Bat", 65, 4996656, 986895);
|
| 349 | addMapping(EntityWitch.class, "Witch", 66, 3407872, 5349438);
|
| 350 | addMapping(EntityEndermite.class, "Endermite", 67, 1447446, 7237230);
|
| 351 | addMapping(EntityGuardian.class, "Guardian", 68, 5931634, 15826224);
|
| 352 | addMapping(EntityPig.class, "Pig", 90, 15771042, 14377823);
|
| 353 | addMapping(EntitySheep.class, "Sheep", 91, 15198183, 16758197);
|
| 354 | addMapping(EntityCow.class, "Cow", 92, 4470310, 10592673);
|
| 355 | addMapping(EntityChicken.class, "Chicken", 93, 10592673, 16711680);
|
| 356 | addMapping(EntitySquid.class, "Squid", 94, 2243405, 7375001);
|
| 357 | addMapping(EntityWolf.class, "Wolf", 95, 14144467, 13545366);
|
| 358 | addMapping(EntityMooshroom.class, "MushroomCow", 96, 10489616, 12040119);
|
| 359 | addMapping(EntitySnowman.class, "SnowMan", 97);
|
| 360 | addMapping(EntityOcelot.class, "Ozelot", 98, 15720061, 5653556);
|
| 361 | addMapping(EntityIronGolem.class, "VillagerGolem", 99);
|
| 362 | addMapping(EntityHorse.class, "EntityHorse", 100, 12623485, 15656192);
|
| 363 | addMapping(EntityRabbit.class, "Rabbit", 101, 10051392, 7555121);
|
| 364 | addMapping(EntityVillager.class, "Villager", 120, 5651507, 12422002);
|
| 365 | addMapping(EntityEnderCrystal.class, "EnderCrystal", 200);
|
| 366 | }
|
| 367 |
|
| 368 | public static class EntityEggInfo
|
| 369 | {
|
| 370 | public final int spawnedID;
|
| 371 | public final int primaryColor;
|
| 372 | public final int secondaryColor;
|
| 373 | public final StatBase field_151512_d;
|
| 374 | public final StatBase field_151513_e;
|
| 375 |
|
| 376 | public EntityEggInfo(int id, int baseColor, int spotColor)
|
| 377 | {
|
| 378 | this.spawnedID = id;
|
| 379 | this.primaryColor = baseColor;
|
| 380 | this.secondaryColor = spotColor;
|
| 381 | this.field_151512_d = StatList.getStatKillEntity(this);
|
| 382 | this.field_151513_e = StatList.getStatEntityKilledBy(this);
|
| 383 | }
|
| 384 | }
|
| 385 | }
|
| 386 |
|