Cancelling Blaze Environment Damage

Discussion in 'Plugin Development' started by Scizzr, Jul 19, 2012.

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

    Scizzr

    So I'm working on a plugin and one of the annoyances is that Blaze mobs take damage from rain and water. I haven't found a way to cancel this yet and I've tried several damage checks (EntityDamageEvent, EntityDamageByEntityEvent, EntityDamageByBlockEvent) with no success.

    Anyone care to share advice? :)
     
  2. Offline

    ferrybig

    look at the source code of bukkit where the blaze gets damage by the weather, and see what event it calls there
     
  3. Offline

    Scizzr

    Honestly, I'm not sure where to look.

    Any help is sill appreciated.
     
  4. Offline

    evilmidget38 Retired Staff

  5. Offline

    Scizzr

    No luck there. It's not firing a Damage event nor does it fire a death event when the Blaze dies.

    I appreciate your help though.
     
  6. Offline

    r0306

    Scizzr
    Try DamageCause.DROWN.
     
  7. Offline

    Scizzr

    It's not firing an EntityDamageEvent. At all. There's nothing to check.
    Code:
    @EventHandler(priority = EventPriority.MONITOR)
    public void onEntityDamage(final EntityDamageEvent e) {
        Entity ent = e.getEntity();
       
        if (ent instanceof Blaze) {
            Bukkit.broadcastMessage("Blaze hurt:" + e.getCause().name());
        }
    }
    
    I punch it, it's triggered (ENTITY_ATTACK) but in the situation I need to cancel, it doesn't trigger. Not from rain, not from water.

    Thanks though.
     
  8. Offline

    r0306

    Scizzr
    Actually, if you check inside an entitydamage event for every type of damage cause and none of them matches, you can probably assume that they are being hurt by water contact.
     
  9. Offline

    Scizzr

    Do me a favor and test it out. You'll see what I'm talking about. :)

    As my code is, I am literally checking for any and every DamageCause (since I am not filtering them out with an 'if' statement).

    This should result in any damage the Blaze takes being broadcast.

    It doesn't.


    Edit: If water contact damages the Blaze, shouldn't that fire at least a DamageCause.CONTACT? If so, why doesn't it?
     
  10. Offline

    r0306

    Scizzr
    I think they forgot to add that feature in the bukkit api. A workaround for this would be to listen in on a move event, check if the entity is a blaze, then get the location of the blaze and check if it's in water or if the light level of the location is above 10, which would indicate that the blaze is out in the open if the world is raining. Then you can schedule a repeating task every 1 second to broadcast the damage until you cancel it when the blaze dies in an entity death event.
     
  11. Offline

    Scizzr

    That's another thing: The Blaze dying from the rain or water doesn't fire an EntityDeathEvent. So, yeah. Lol :D

    Edit: Code
    Code:
    @EventHandler(priority = EventPriority.MONITOR)
    public void onEntityDeath(final EntityDeathEvent e) {
        Entity ent = e.getEntity();
     
        if (ent instanceof Blaze) {
            Bukkit.broadcastMessage("Blaze dead");
        }
    }
    
    Edit 2: Added a ticket. Hopefully it'll be fixed in the 1.3 release. :)
     
  12. Offline

    r0306

    Scizzr
    Hmm. That means that you would have to schedule a repeating task and check if the blaze is dead or the entity is removed.
     
  13. Offline

    Scizzr

    Exactly what I've done.

    If you're curious why I want this, it's for 'pets' in a plugin I'm working on. They just respawn so its not a big deal. Just annoying having them respawn-loop in the rain. ^_^
     
  14. Offline

    r0306

  15. Offline

    Scizzr

    Respawning every 3 seconds? Yeah.
    I'm storing the entity's UUID in a hashMap and checking every 3 seconds for its existence. If it doesn't exist, I'm removing the UUID from the HashMap and re-spawning another Blaze.

    I've been doing that all day, I was just stuck on this issue all the while.

    ^_^
     
  16. Offline

    r0306

    Scizzr
    We should submit a ticket to Bukkit about this.
     
  17. Offline

    Scizzr

    This:

    :D
     
    r0306 likes this.
Thread Status:
Not open for further replies.

Share This Page