how to get nearest entity to an entity

Started by carnivowrist on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to get nearest entity to an entity

I'm trying to make a procedure in which each tick (or every X ticks) it will set the attack target of an entity to the nearest entity to it, but if i use "get nearest entity" it will select itself, and so if i make it the attack target, the entity attacks itself as it considers itself the nearest. I tried other things like "for each entity as 'entity iterator' at X Y Z" --> set the attack target to entity iterator, which works well but this sets the attack target of the entity to the furthest entity to it.. i have no solutions