Topic category: Help with Minecraft modding (Java Edition)
I am trying to create a mod with a set of creatures with a custom tag that will attack any mob that DOES NOT share the same tag as them. Currently I am stuck on making one mob attack everything except for its own kind.
Under the ai and goals tab, there is an "Attack entities of type" block set to "living entity" and a procedure that is supposed to check if the entity the mob is targeting to attack does not have a specific custom tag. No matter how much I try to modify the procedure the mobs will still attack each other instead of other mobs. I do not wish to use the "On Entity Tick Update" trigger for a solution as I intend on using that for another behavior. I have tried to look for solutions from people who have had a similar problem, but the solutions that have been provided either do not work or result in a crash.
The procedure (still not quite used to using Imgur, tell me if the link doesn't work)
For now, I have the ai and goals set to a list of vanilla mobs it can attack, but I would rather not have a long list of every individual mob.
I am at my wits end here, I am in desperate need for help with this. I feel like I am running around in circles trying to find a solution that works.
(I hadn't touched Mcreator in a bit over a year and when I looked at my profile it seems I had a problem like this before with a crash as a result. This time, I just can't seem to get the condition procedure to actually work.)
You can put multiple things into a tick update procedure with no issue
So you have a condition on the ai task, get entity event/target entity is targeting for attack =/ tagged in entity tags as same_tag
Is it on the continue condition and/or start condition?
I have tried both the start condition and continue conditions, and tried multiple modifications to the procedure, but none of it had worked Either it will attack anything including its own kind or it will just not attack anything at all. It could be possible to put it in the tick update procedures, but I feel it would be inefficient to have to import that part of the procedure each time I want to apply it to a mob that would have more behaviors in the tick updates.
To be honest I don't think it's very possible either way
Cancelling the attack target each tick may work, otherwise you could add the continue condition to the same but for the wander as well, but then you would need to switch/refresh the attack target on tick, could also use the avoid ai task to make it move away from the same mobs
Can do it with code though
Hmm... I'll poke around some and see what works. I want to be careful with checking the attack target each tick though, as I can see it causing some performance issues if its running that task every tick for several mobs at once. I had the mistake of something a little bit similar with one of the first mobs I made (it would check every tick if there was a player near it for its invisibility to drop) and it caused significant performance issues. So I want to try and avoid doing that unless if there truly is no other option.
Maybe try the "Entity sets its attack target" global trigger? Check if the source entity has the tag, and if the target entity also has the tag, and if yes to both, set attack target of source entity to "no entity"?
I have tried to use that global trigger suggestion, but it had yielded no results. The mobs will still attack each other. Still searching for a solution, my attempts to mess with the conditions for ai and goal behaviors have resulted in either the condition not working/being ignored or a build failure.
I had found a partial solution with finding and setting the attack target each tick.
The procedure made: https://imgur.com/a/g1WF4sI
I seem to be getting closer, but there is some problems with this solution though...
The first problem is that it will always prioritize the player first, and cause the mob to obsessively chase the player even if they are in Creative or Spectator. I do not want the mob to attempt to attack players in Creative and Spectator, but I cannot seem to get the part to check if the target is a player not in Creative or Spectator to work.
The second problem is that the entity will detect other mobs even if it cannot see them and set the attack target to that mob. I'm not sure how to set it to only attack something within its line of sight.