How to make vanilla mobs not attack the player if the player has a special potion effect?

Started by frodo01 on

Topic category: Help with modding (Java Edition)

Last seen on 18:56, 16. Mar 2024
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make vanilla mobs not attack the player if the player has a special potion effect?

It is necessary for all undead to stop attacking the player with the "undead" effect, and golems and villagers considered the player an enemy, but I do not know how to do this and I will be grateful for any help

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can use the 'attempt to…
Mon, 10/02/2023 - 10:56

You can use the 'attempt to set attack target' block to make golems target the player easily enough. Getting undead to avoid the player is much trickier, but not impossible. 

You can't tell an entity to reset its attack target, (you might be able to use the 'stop navigation' function, but I'm not totally sure). What you can do is create an invisible entity with no hitbox, which, when summoned, sets the attack targets of all zombies to itself instead, and then despawns. (Also effectively resetting their attack targets.)

Alternatively, you could make your own custom variants of undead mobs, (none of their AI is very complex), and replace vanilla undead with custom ones when the player has the effect. (Which you could configure to help the player, if you wanted.) Then just have the custom ones revert back to vanilla ones if there isn't a player nearby with an effect.

Last seen on 16:31, 12. May 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mindthemoods hi could you…
Thu, 02/15/2024 - 19:21

Mindthemoods hi could you add a screen shot for the first option you gave i cant find the block 'attempt to set attack target'

thanks in advance

Last seen on 20:37, 26. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is the function you're…
Thu, 02/15/2024 - 22:04

This is the function you're looking for:

You may need to change the entities being reffered to depending on which one you want to be attacked. In most triggers, the target entity is the one that initiated the trigger, and the source entity is the one doing the action. (In your case, it will likely be setting the attack target of the event/target entity to the nearest entity of type 'player')

Last seen on 16:31, 12. May 2024
Joined Feb 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I'm still not entirely sure…
Fri, 02/16/2024 - 11:13

I'm still not entirely sure on how you change the mobs you want to either ignore or attack the player. ill explain my situation. so I'm making a mod for a server and there will be a undead/necromancer roll so i wanted to have a staff that allows you to be seen as a undead character so I've made the staff give you a potion effect and that potion effect will be the thing making undead stop attacking you and mobs like iron golems attack you instead.  how do i do that? can you show a screen shot again I'm sorry I'm still a bit new and there isn't many great sources for this stuff.

thank you in advance