Detect mob type

Discussion in 'Plugin Development' started by matejdro, Jan 12, 2011.

Thread Status:
Not open for further replies.
  1. Offline


    Is there a way to detect mob type from onEntityDamagedByEntity event? As mob type i mean like Zombie, Creeper etc.
  2. Offline


    Based upon what I see in the javadocs you should be able to do something like:
    // Is the entity a creeper?!
    if (entity instanceof Creeper) {
    // Oh! It's just a piggeh!
    } else if (entity instanceof Pig) {
    I have no idea if this works in the latest build -- I haven't yet needed to test this functionality.
  3. Offline


    entity <- Get entity object
    if (entity.getClass().getName() == [desired Entity class location]) {
  4. Offline


    The caveat, of course, is that the desired class name will not be obvious. The class name for creepers, for example, seems to be "org.bukkit.craftbukkit.entity.CraftCreeper". I'm also not certain that reference equality will work across class loaders (it may or may not depending upon the JVM implementation).

    In spite of being not very object-oriented, I think the instanceof test is much simpler.
  5. Offline


    Wow, that was a great update to entities. Thanks!

    Also, what is the difference between for example org.bukkit.entity.Creeper and org.bukkit.craftbukkit.entity.CraftCreeper
  6. Offline


    Okay, I have a question. Cloth blocks change colors by changing the byte.
    Is the same thing possible with mob spawners? in a line of code how would you define each type of spawner individulally?
  7. Offline


    Also, onEntityDamagedByEntity seems to behave very weird. For example sometimes when i hit mob, event will trigger 3x.

    Any idea?
Thread Status:
Not open for further replies.

Share This Page