Topic category: User side tutorials
Considering this has been asked plenty of times in the last week I will give a brief explanation on how to do this.
1) Create a global variable (map or world) / logic / starting value false
2) Create a procedure on player tick update: "IF" item in main hand or if get item from slot N° (it depends on what you need) then set global variable to true "ELSE" set global variable to false
3) Go into your mob AI and add the line attack player. Click on condition and apply same conditions for both fields (start and continue): RETURN global variable = true
In this way all mobs will start attacking you once item is equipped / at hand but if you remove item then they will stop attacking you
If you want for him to keep attacking you after the first attack even if item no longer in hand then just remove conditions to "continue" field.
This works for custom models only
Only solution I have for Vanilla mobs is instead adding another procedure: entity joins the world. "IF" entity = (vanilla mob) then despawn entity and spawn your custom mob which is identical to vanilla mob and also same name. At this point repeat points 1 to 3 applied to your mob
Hope this will help someone
underwhelming-loner, I can't configure this procedure. Please share the file 🙏