How to check if a mob actually got hit.

Discussion in 'Plugin Development' started by DeadlyScone, Apr 30, 2012.

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

    DeadlyScone

    I'am trying to set the health of the mob(right now just the zombie) i got that part figured out but the one problem that i ran into is that whenever you click it counts as you damaging the mob even though you really don't damage the mob.
    I was wondering how do you check if the mob was ACTUALLY hit in the EntityDamageEvent?

    No one?

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

    theguynextdoor

    Is your aim if the entity gets damaged by a player or another entity of some kind, such as an arrow? If so, then may i point you to the EntityDamageByEntityEvent which then has a getDamager method so you can check which entity damaged that entity. But what may be more useful to you is the getDamage method which return an int of the amount of damage in the event and so all you need to do is check if that int is higher than 0 then you will know if the mob actually got damaged.
     
  3. Offline

    DeadlyScone

    iam checking strictly if the entity was damaged by a player. Ahh... see that what i though also. but the damage will always be > 0 no matter what because the event is not cancelled even though the entity is not being damaged. I found that you can use NoDamageTicks, but i'am not quite sure how to access that method. i think its part of LivingEntity. Any ideas on how to get that method to bring up?

    nevro-mind, i found out how to. Just needed to cast the event with LivingEntity like this. ((LivingEntity)event.getEntity())


    POST:
    It could be that you're grabbing all damage events and not applying any use of the NoDamageTicks. This was the case for me. I was experiencing what I thought was a number of bugs that would allow an entity to get damaged more often or too quickly than expected and without even getting the damage event info to filter it. However, after evaluating every event even those while NoDamageTicks > (MaxNoDamageTicks / 2), this was able to be resolved for me.
    By default, event damage will continue to be sent to the target as rapidly as you click. However the damage received will be reduced to only the difference over and above the new damage vs the original damage that caused the entity's NoDamageTicks to reset to it's MaxNoDamageTicks. Once the NoDamageTicks reaches 1/2 of the MaxNoDamageTicks, it will take full damage again and reset the NoDamageTicks.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
Thread Status:
Not open for further replies.

Share This Page