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

Started by No3 on Tue, 11/22/2022 - 18:08

Topic category: Help with modding (Java Edition)

Last seen on 13:34, 24. Nov 2022
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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
Last seen on 19:10, 27. Dec 2022
Joined May 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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.

Last seen on 13:34, 24. Nov 2022
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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

Last seen on 13:34, 24. Nov 2022
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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.

Last seen on 02:47, 13. Dec 2022
Joined Oct 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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.