When a mob is spawned via a player-initiated action (either a player-entered /summon command or a player right-clicking a spawn egg), and its last_hurt_by_mob NBT tag is written via /data modify on the exact same tick it spawns, the mob's AI ignores the written value for 100 game ticks (5 seconds):
Although
/data getconfirms that last_hurt_by_mob contains a valid, alive target UUID, the mob's AI does not respond to it.The
/execute on targetsubcommand fails to select any target during this period.
This behavior only occurs when the spawning action is initiated by a player. When the identical /data modify is applied to mobs spawned via non-player sources (command blocks, dispensers, functions), the AI responds immediately.
The following observations have been consistently reproduced:
The
/data modifywrite is successful —/data getconfirms the tag contains the correct UUID.The AI ignores this value for exactly 100 ticks unless interrupted.
The AI responds immediately if:
The tag is manually removed (
/data modify entity ... last_hurt_by_mob set value {})The tag is cleared by vanilla's 100-tick auto-clear mechanism (then re-written by the tick command)
The mob takes native damage from an attacker (e.g., melee attack, arrow) — based on testing, these are the types of damage that have been observed to overwrite
last_hurt_by_moband trigger an AI response
This indicates that the AI only begins respecting last_hurt_by_mob after the tag has undergone a "state change" (removal or overwrite by an attacker).
Trigger Condition Analysis:
Through systematic testing, the trigger condition has been narrowed down to a single factor: the spawning action must be initiated by a player.
Test Case | Spawning Initiated By | Command Executor | AI Ignores for 100 Ticks? |
|---|---|---|---|
Player enters | Player | Player | ✅ Yes |
Player right-clicks spawn egg | Player | Player | ✅ Yes |
Command block runs | Command block | Command block | ❌ No |
Command block runs | Command block | Player (via as) | ❌ No |
Command block runs | Command block | Command block | ❌ No |
Dispenser ejects spawn egg | Dispenser | Dispenser | ❌ No |
Key finding: The trigger is not whether the executor (@s) is a player, but whether the spawn was initiated by a player. When a command block uses execute as @p, the executor becomes a player, but the spawn is still initiated by the command block — and the AI responds immediately.
Comparative Test: last_hurt_by_mob vs angry_at:
To determine whether this issue affects all AI-related NBT tags or is specific to last_hurt_by_mob, the following comparative test was conducted:
NBT Tag | Mob | Player-Initiated Spawn | AI Ignores for 100 Ticks? |
|---|---|---|---|
last_hurt_by_mob | Pillager / Zombie | ✅ | ✅ Yes |
angry_at | Zombified Piglin | ✅ | ❌ No |
Test command for angry_at:
execute as @e[type=zombified_piglin] unless data entity @s angry_at at @s if entity @e[type=#raiders,distance=..16] run data modify entity @s angry_at set from entity @n[type=#raiders,distance=..16] UUIDTest command for last_hurt_by_mob:
execute as @e[type=#undead,type=!zombified_piglin] unless data entity @s last_hurt_by_mob at @s if entity @e[type=#raiders,distance=..16] run data modify entity @s last_hurt_by_mob set from entity @n[type=#raiders,distance=..16] UUID
execute as @e[type=#raiders] unless data entity @s last_hurt_by_mob at @s if entity @e[type=#undead,distance=..16] run data modify entity @s last_hurt_by_mob set from entity @n[type=#undead,distance=..16] UUID
Thank you for helping us improve Minecraft! We saved your files: