summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Wood <farachan@gmail.com>2012-02-01 10:53:36 -0500
committerEvilSeph <evilseph@gmail.com>2012-02-03 02:07:05 -0500
commit8d2637ee0da3cf8d6d5275d7d5a0c30a922c297f (patch)
tree5eb9879a834c662caf557ccc8d8ef7286d96f95d
parent687710c2a15b3012606d3123ee2d778d5f445125 (diff)
downloadbukkit-8d2637ee0da3cf8d6d5275d7d5a0c30a922c297f.tar
bukkit-8d2637ee0da3cf8d6d5275d7d5a0c30a922c297f.tar.gz
bukkit-8d2637ee0da3cf8d6d5275d7d5a0c30a922c297f.tar.lz
bukkit-8d2637ee0da3cf8d6d5275d7d5a0c30a922c297f.tar.xz
bukkit-8d2637ee0da3cf8d6d5275d7d5a0c30a922c297f.zip
Added entity type IDs as per vanilla spec.
-rw-r--r--src/main/java/org/bukkit/entity/CreatureType.java74
1 files changed, 45 insertions, 29 deletions
diff --git a/src/main/java/org/bukkit/entity/CreatureType.java b/src/main/java/org/bukkit/entity/CreatureType.java
index 2f1ab5a5..b6a27d86 100644
--- a/src/main/java/org/bukkit/entity/CreatureType.java
+++ b/src/main/java/org/bukkit/entity/CreatureType.java
@@ -6,45 +6,50 @@ import java.util.Map;
public enum CreatureType {
// These strings MUST match the strings in nms.EntityTypes and are case sensitive.
- CHICKEN("Chicken", Chicken.class),
- COW("Cow", Cow.class),
- CREEPER("Creeper", Creeper.class),
- GHAST("Ghast", Ghast.class),
- GIANT("Giant", Giant.class),
- MONSTER("Monster", Monster.class),
- PIG("Pig", Pig.class),
- PIG_ZOMBIE("PigZombie", PigZombie.class),
- SHEEP("Sheep", Sheep.class),
- SKELETON("Skeleton", Skeleton.class),
- SLIME("Slime", Slime.class),
- SPIDER("Spider", Spider.class),
- SQUID("Squid", Squid.class),
- ZOMBIE("Zombie", Zombie.class),
- WOLF("Wolf", Wolf.class),
- CAVE_SPIDER("CaveSpider", CaveSpider.class),
- ENDERMAN("Enderman", Enderman.class),
- SILVERFISH("Silverfish", Silverfish.class),
- ENDER_DRAGON("EnderDragon", EnderDragon.class),
- VILLAGER("Villager", Villager.class),
- BLAZE("Blaze", Blaze.class),
- MUSHROOM_COW("MushroomCow", MushroomCow.class),
- MAGMA_CUBE("LavaSlime", MagmaCube.class),
- SNOWMAN("SnowMan", Snowman.class);
+ CREEPER("Creeper", Creeper.class, 50),
+ SKELETON("Skeleton", Skeleton.class, 51),
+ SPIDER("Spider", Spider.class, 52),
+ GIANT("Giant", Giant.class, 53),
+ ZOMBIE("Zombie", Zombie.class, 54),
+ SLIME("Slime", Slime.class, 55),
+ GHAST("Ghast", Ghast.class, 56),
+ PIG_ZOMBIE("PigZombie", PigZombie.class, 57),
+ ENDERMAN("Enderman", Enderman.class, 58),
+ CAVE_SPIDER("CaveSpider", CaveSpider.class, 59),
+ SILVERFISH("Silverfish", Silverfish.class, 60),
+ BLAZE("Blaze", Blaze.class, 61),
+ MAGMA_CUBE("LavaSlime", MagmaCube.class, 62),
+ ENDER_DRAGON("EnderDragon", EnderDragon.class, 63),
+ PIG("Pig", Pig.class, 90),
+ SHEEP("Sheep", Sheep.class, 91),
+ COW("Cow", Cow.class, 92),
+ CHICKEN("Chicken", Chicken.class, 93),
+ SQUID("Squid", Squid.class, 94),
+ WOLF("Wolf", Wolf.class, 95),
+ MUSHROOM_COW("MushroomCow", MushroomCow.class, 96),
+ SNOWMAN("SnowMan", Snowman.class, 97),
+ VILLAGER("Villager", Villager.class, 120);
private String name;
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 {
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.clazz = clazz;
+ this.typeId = (short) typeId;
}
public String getName() {
@@ -55,7 +60,18 @@ public enum CreatureType {
return clazz;
}
+ public short getTypeId() {
+ return typeId;
+ }
+
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);
}
-}
+} \ No newline at end of file