13
0
geforkt von Mirrors/Paper

Added entity type IDs as per vanilla spec.

By: Jeremy Wood <farachan@gmail.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-02-01 10:53:36 -05:00
Ursprung 1749f26e03
Commit b2d95b3937

Datei anzeigen

@ -6,45 +6,50 @@ import java.util.Map;
public enum CreatureType { public enum CreatureType {
// These strings MUST match the strings in nms.EntityTypes and are case sensitive. // These strings MUST match the strings in nms.EntityTypes and are case sensitive.
CHICKEN("Chicken", Chicken.class), CREEPER("Creeper", Creeper.class, 50),
COW("Cow", Cow.class), SKELETON("Skeleton", Skeleton.class, 51),
CREEPER("Creeper", Creeper.class), SPIDER("Spider", Spider.class, 52),
GHAST("Ghast", Ghast.class), GIANT("Giant", Giant.class, 53),
GIANT("Giant", Giant.class), ZOMBIE("Zombie", Zombie.class, 54),
MONSTER("Monster", Monster.class), SLIME("Slime", Slime.class, 55),
PIG("Pig", Pig.class), GHAST("Ghast", Ghast.class, 56),
PIG_ZOMBIE("PigZombie", PigZombie.class), PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
SHEEP("Sheep", Sheep.class), ENDERMAN("Enderman", Enderman.class, 58),
SKELETON("Skeleton", Skeleton.class), CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
SLIME("Slime", Slime.class), SILVERFISH("Silverfish", Silverfish.class, 60),
SPIDER("Spider", Spider.class), BLAZE("Blaze", Blaze.class, 61),
SQUID("Squid", Squid.class), MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
ZOMBIE("Zombie", Zombie.class), ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
WOLF("Wolf", Wolf.class), PIG("Pig", Pig.class, 90),
CAVE_SPIDER("CaveSpider", CaveSpider.class), SHEEP("Sheep", Sheep.class, 91),
ENDERMAN("Enderman", Enderman.class), COW("Cow", Cow.class, 92),
SILVERFISH("Silverfish", Silverfish.class), CHICKEN("Chicken", Chicken.class, 93),
ENDER_DRAGON("EnderDragon", EnderDragon.class), SQUID("Squid", Squid.class, 94),
VILLAGER("Villager", Villager.class), WOLF("Wolf", Wolf.class, 95),
BLAZE("Blaze", Blaze.class), MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
MUSHROOM_COW("MushroomCow", MushroomCow.class), SNOWMAN("SnowMan", Snowman.class, 97),
MAGMA_CUBE("LavaSlime", MagmaCube.class), VILLAGER("Villager", Villager.class, 120);
SNOWMAN("SnowMan", Snowman.class);
private String name; private String name;
private Class<? extends Entity> clazz; private Class<? extends Entity> clazz;
private short typeId;
private static final Map<String, CreatureType> mapping = new HashMap<String, CreatureType>(); private static final Map<String, CreatureType> NAME_MAP = new HashMap<String, CreatureType>();
private static final Map<Short, CreatureType> ID_MAP = new HashMap<Short, CreatureType>();
static { static {
for (CreatureType type : EnumSet.allOf(CreatureType.class)) { for (CreatureType type : EnumSet.allOf(CreatureType.class)) {
mapping.put(type.name, type); NAME_MAP.put(type.name, type);
if (type.typeId != 0) {
ID_MAP.put(type.typeId, type);
}
} }
} }
private CreatureType(String name, Class<? extends Entity> clazz) { private CreatureType(String name, Class<? extends Entity> clazz, int typeId) {
this.name = name; this.name = name;
this.clazz = clazz; this.clazz = clazz;
this.typeId = (short) typeId;
} }
public String getName() { public String getName() {
@ -55,7 +60,18 @@ public enum CreatureType {
return clazz; return clazz;
} }
public short getTypeId() {
return typeId;
}
public static CreatureType fromName(String name) { public static CreatureType fromName(String name) {
return mapping.get(name); return NAME_MAP.get(name);
}
public static CreatureType fromId(int id) {
if (id > Short.MAX_VALUE) {
return null;
}
return ID_MAP.get((short) id);
} }
} }