Jump to content

[1.8] [SOLVED] Making mobs ignore the player?


Recommended Posts

You don't want to remove their AI tasks - then they won't attack anyone EVER again.


Easy way: cancel LivingAttackEvent when the target is wearing your item. Downside is that mobs may still 'target' the player, i.e. walking towards it and such, but you won't take any damage.


Another way: use LivingSetAttackTargetEvent to set the attacker's current target to null (or another nearby selectable target) if the target is wearing your item, but this doesn't (or perhaps didn't) work for all entities (e.g. creepers, iirc, as well as some others) so you'd have to account for that by using some fancier magic such as ASM.


Best way is a combination of the above 2 - the 2nd to prevent most mobs from even trying to target the player, and the 1st to stop them from doing any damage if they still end up targeting despite your other efforts.


Probably more ways as well, but that's all I can think of at the moment.

Link to comment
Share on other sites

I've already tried setting its target to null in the event, but the field is final, and the entity's saved target is private. I already have the item canceling damage, but that's not the point.

How did you set the target to null? I've done it using ((EntityLiving) event.entity).setAttackTarget(null); and that works for most mobs. 1.8 is better than 1.7.10 for this since now most mobs are using the AI system, whereas before spiders and many others were not, meaning they wouldn't be affected at all.


Anyway, the above should work (mostly) - the mobs won't even walk towards you. If it's not working for you, show your code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.