I'm trying to create a mob hit detection system. I have researched online beforehand to this question, however I haven't come to any conclusion on my success yet.

I'm simply after, when a mob is hit, it summons 1 orb of experience so the players can use their mending, as I have mob drops off so they do not drop xp upon death.

If you have any way to do this, I'd love to hear it, any help is gladly appreciated. I'm on Minecraft ForgeOptiFine 1.14.4, hopefully that helps! I've got a feeling it's about the HurtTime NBT, I just can't get my head around it.


HurtTime increases once the mob is hit. So detecting a hit is as simple as running a command when its the value is greater than 0.

Place down a repeating command block and attach 2 chain command blocks it to. Set them all to always active and paste these in (in the exact same order):

/execute as @e[nbt=!{HurtTime:0s},tag=!ignore] at @s if data entity @s HurtTime run summon minecraft:experience_orb
/execute as @e[nbt=!{HurtTime:0s}] if data entity @s HurtTime run tag @s add ignore
/tag @e[tag=ignore,nbt={HurtTime:0s}] remove ignore

Also, in case you are wondering what the 2 other commands are, it takes a few seconds for the HurtTime value to go back to 0 so those commands make sure that you only get 1 XP orb during that time.

Command block layout: enter image description here