I'm making a map, and I require that whenever certain animals are hit a string of events will occur. I tried looking around to see if I could synthesize some form of a working answer but it seems to be flying over my head. Essentially what I want is some form of command that will detect the player nearest to the hit mob, and then I could use chain command blocks for my additional needs. I know I need to use a chain command block, and I know this has to do something with HurtTime, but I just can't piece it all together.

  • Welcome to the Arqade! Can you supply some sample commands that you've tried unsuccessfully? They may help us piece together a working answer for you! Commented Jul 27, 2021 at 20:28

1 Answer 1


Normally, entities have a HurtTime of 0s. You can see this by using /data get entity @s HurtTime, using yourself as an example. When an entity is hit, its HurtTime gets set to 10s and decreases every tick until it has reached 0s again.

You can test for nbt in selectors like this:

execute as @e[nbt={HurtTime:10s}] at @s run particle angry_villager ~ ~2 ~

(Repeating command every tick)

You can tag the player nearest to the hit mob like this:

execute as @e[nbt={HurtTime:10s}] at @s run tag @p add closest_to_mob

(Repeating command every tick)

  • The commands work wonderfully, but I have another problem now. The text I have set just keeps sending in chat indefinitely. How do I remedy this so that the text is only sent once. Also, how would you set the hurt time for specific mobs?
    – Sammy
    Commented Jul 28, 2021 at 5:33
  • You can tag the entity you wish to detect, and use that in the selector. Like so: @e[tag=example,nbt={HurtTime:10s}]. As for your repeating text issue, I don't know how you set it up and cannot help.
    – ginkgo
    Commented Jul 28, 2021 at 13:55
  • @Sammy don't forget to click or tap the checkbox next to this answer if it answered your question! Commented Jul 28, 2021 at 15:06
  • For the text, I attached a chain command block that doesn't require redstone to a chain command block that also doesn't require redstone with the following command you gave earlier, "execute as @e[nbt={HurtTime:10s}] at @s run tag @p add closest_to_mob". Idk if this is enough information, but I hope it is.
    – Sammy
    Commented Jul 28, 2021 at 20:53
  • Nvm, I figured it all out. I combined this answer with another question on the site to create my desired effect. Here's the link to the other question: gaming.stackexchange.com/questions/252661/… If anyone wants, I can go more in depth into how I combined the two to fix my problem
    – Sammy
    Commented Jul 29, 2021 at 3:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .