Making mobs know whether to attack each other or not [SOLVED]

Started by No3 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Making mobs know whether to attack each other or not [SOLVED]
Thu, 11/24/2022 - 03:20 (edited)

Hi, I was trying to make sort of a soldier mob, which you can decide who it belongs to and who will it attack. I initially tried to do it through IDs made with NBT tags, by checking whether the other "soldier" had matching IDs (So 2 and 2) or different (5 and 72). Issue is, attack conditions don't support both event/target entity and source entity. I also tried taming, but tamed soldiers will attack other tamed soldiers... Is there a way to do this?

 

Basically I want Soldier A to attack Soldier B if I wish to, but I also want to be able to set Soldier B as an ally troop (without having to interact myself with Soldier B such as in hitting them or viceversa)

Edited by No3 on Thu, 11/24/2022 - 03:20
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
have you tried using the…
Wed, 11/23/2022 - 17:01

have you tried using the block "Get entity Event/Target Entity is targeting for attack"? this block does not require source entity to work.

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I tried to do that, but the…
Thu, 11/24/2022 - 02:35

I tried to do that, but the game just crashes the moment both entities see each other

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay finally found a…
Thu, 11/24/2022 - 03:19

Okay finally found a solution:

Doing it through NBTs so far crashes every attempt.

Doing it through tamed mobs doesn't work for some strange reason (there's always a chance that im dumb but hey)

So I tried an alternative method: Items

 

I made the attack condition check whether the item that mob A has in its main-hand is the same as mob B's. If it's the same, they are allies, if it's different, they are enemies. Doing it this way works like wonders, I made an item to be able to change their man-hand item (which doesn't physically show upbecause it's a custom entity but that's a good thing for me), and everytime I match their items, they stop attacking, and begin their attack again as soon as their items don't match up.

Joined Oct 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Very good solution but could…
Mon, 11/28/2022 - 20:59

Very good solution but could you please show an image of the procedure or procedures, that way it would be much better.