Important EntityDamageEvent Question

Discussion in 'Plugin Development' started by nossr50, Mar 23, 2011.

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

    nossr50

    Is there anyway to tell if the event actually inflicts damage on the entity? For example, if you spam click something 1000 times with an autoclicker this event will get called everytime and report damage everytime, but thanks to minecrafts "invincibility" after taking damage mechanics only one of these events will truly do damage.

    How do we tell if the entity is going to actually take damage or not?
     
  2. Offline

    Edward Hand

    The entity will take damage if the following condition is met:
    Code:
    CraftEntity cEntity = (CraftEntity)theEntity;
    if(cEntity.getHandle().noDamageTicks < cEntity.getHandle().maxNoDamageTicks/2.0F)
       //damage gets done
     
  3. Offline

    nossr50

    You are like the god damn Batman of solving plugin development issues
    I love you

    maxNoDamageTicks can't be resolved
    Any idea why?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 13, 2016
  4. Offline

    Edward Hand

    Ah. Casting needed:
    Code:
    CraftEntity cEntity = (CraftEntity)theEntity;
    EntityLiving entity = (EntityLiving)cEntity.getHandle();
    if(entity.noDamageTicks < entity.maxNoDamageTicks/2.0F)
     
  5. Offline

    nossr50

    And what is this part for?
    Code:
    /2.0F
     
  6. Offline

    Edward Hand

    Here's a brief summary of how the damage cooldown works:
    • Every time a living entity is damaged, its noDamageTicks property gets set to maxNoDamageTicks.
    • Every tick, if noDamageTicks>0, the value of noDamageTicks is decreased by 1.
    • When an entity later receives damage, the value of noDamageTicks is compared with maxNoDamageTicks.
    • If noDamageTicks>maxNoDamageTicks/2 (first half of cooldown) then damage will only be done if the damage is greater than the last damage recieved - then the damage is the difference between the last damage and the new damage. The ticks value is not changed.
    • If noDamageTicks<maxNoDamageTicks/2 (later half of cooldown) then full damage is done, ticks value is bumped up again and the cycle restarts.
    Does that make sense?
     
  7. Offline

    nossr50

    Yeah, thanks for the reply
     
  8. Offline

    Edward Hand

    According to twitter, there was a commit 10 hours ago implementing notDamageTicks and maxNoDamageTicks etc into craftbukkit proper. You might want to move over to those at some point as its considered cleaner.
     
Thread Status:
Not open for further replies.

Share This Page