Started by
AtsuniMaoko_
on
Topic category: Help with Minecraft modding (Java Edition)
Hello, i'm making a mod and i have a problem:
I want to make that when the player have a specific tag i have created (i have already make the condition for the player how to get the tag), the mobs with the tag "raiders" stop attack the player, the villagers like mobs flee the player and the iron golem mob now attack the player automactically.
My problem is that i don't know which block in procedure to use and precisely how to make that.
I have already looked for similar issues but I didn't find a satisfying answer.
You would not want to do this with tags, as tags cannot be altered while inside the game. (You could make a tag that does this and add the player to it, but you wouldn't be able to remove it.) Instead, you'll want to make a player-based logic variable, as this can be changed from true to false at any time, and will be specific to each individual player.
Getting golems to attack the player is pretty easy, you can make a procedure that runs on player tick update, and, if the variable is true for that player, does an entity iterator and makes any golems in its radius attack the player. (There's a 'set attack target' function that works on any entities with combat abilities.)
Getting pillagers to not attack the player is harder. Entities that have built in neutrality behaviors such as piglins can be neutralized with custom code, but I've never tried it for straight up hostile ones. You can summon invisible entities to set their attack targets to, then despawn them, but this only temporarily resets attack targets, and tends to look weird. You could also try the built in 'team' commands that supposedly make hostile entities work with each other/other players, but I've never been able to get this working, and it's kind of sketchy. A proper solution will probably require custom code.