Cancelling Blaze Environment Damage

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

  1. Offline

    Scizzr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Honestly, I'm not sure where to look.

    Any help is sill appreciated.
  4. Online

    evilmidget38 BukkitDev Staff

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  5. Offline

    Scizzr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME

    This post has been edited 1 time. It was last edited by Scizzr Jul 21, 2012.
  6. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Scizzr
    Try DamageCause.DROWN.
  7. Offline

    Scizzr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.

    This post has been edited 1 time. It was last edited by Scizzr Jul 21, 2012.
  8. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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?

    This post has been edited 4 times. It was last edited by Scizzr Jul 21, 2012.
  10. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. :)

    This post has been edited 3 times. It was last edited by Scizzr Jul 21, 2012.
  12. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  15. Offline

    Scizzr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @Scizzr
    We should submit a ticket to Bukkit about this.
  17. Offline

    Scizzr

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This:

    :D
    r0306 likes this.

Share This Page