I have a good idea and its Mob AI that allows it to attack if you look at it.
Issue comments
Ok I totally forgot about enderman, my bad.
To answer why we don't add all AI tasks possible: most AI tasks are bound to a specific entity type and can't be used by other entities. We can't bypass this because this is how Java works.
I have checked the code of EntityEnderman and the task to attack when looked is this one: EntityEnderman.AIFindPlayer
This is, unfortunately, Enderman specific task. If I find a workaround for this we will, of course, implement more AI tasks, but for now I don't think we could do this.
We can only use AI that is defined in Minecraft. I have checked package net.minecraft.entity.ai which contains all AI tasks and there is no such task. Are there any mobs that do this in Minecraft so I can check how they do this?