How to get nearest entity of a group?

Started by privatacc on

Topic category: Help with Minecraft modding (Java Edition)

Joined Feb 2026
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to get nearest entity of a group?

in Element Tags you can group up entities, how does one get the nearest one? i once did it via math by calculating all the mobs, for 2-3 mobs this is fine, but when you add more and more it gets messy inside the procedures and the mod needs to calculate alot.

I want Mob A to react if Mob B is nearby (Reaction B)
but if Mob C is closer to Mob A I want Mob A to have Reaction C
and so on.

I'm very bad at explaining sry.
 
what we have is:
Get nearest entity at x: [] y: [] z: [] in square cube with size [] of type

what I would need is:
Get nearest entity at x: [] y: [] z: [] in square cube with size [] of group []

What I had:
Set Local XCordMobA to X cord of Mob A
Set Local YCordMobA to Y cord of Mob A
Set Local ZCordMobA to Z cord of Mob A

Set Local XCordMobB to X cord of Mob B
Set Local YCordMobB to Y cord of Mob B
Set Local ZCordMobB to Z cord of Mob B

Set Local XCordMobC to X cord of Mob C
Set Local YCordMobC to Y cord of Mob C
Set Local ZCordMobC to Z cord of Mob C

and then calculate what the shortest distant is to get the reaction i wanted, but i mean you can see how this is going to cause problems. cuz rn these are only 3 of my modded entities, but they should also react to player and some vanilla entities.

MCreator 2024.2 Forge