How to check for a tamed entity nearby (not the nearest entity).

Started by Pizzaperson23 on

Topic category: Help with modding (Java Edition)

Last seen on 18:49, 27. Jan 2024
Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to check for a tamed entity nearby (not the nearest entity).

I am making a mob(x) that always attacks you unless a tamed version of another entity(y) is nearby. I am also not trying to make the procedure look for the nearest entity but any of the entities that are tamed nearby. Is there a way to do this? If so, how?

Last seen on 20:43, 20. Aug 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could do this with an…
Mon, 12/11/2023 - 12:48

You could do this with an entity iterator- essentially, it will check every entity in a radius. In this case, you would want to check if the entity iterator is the desired entity type, and is tamed to another entity. (Probably check that the entity's owner is a subtype of living entity, and therefore exists.) If you're using this to determine whether or not to set the attack target to the nearest player, it'll probably be fine, but if the mob is already aggroed, it won't do anything. 

If you want to reset the mob's attack target, there's a weird workaround where you can spawn an invisible entity, set the mob's attack target to that entity, and then despawn the invisible entity, which stops them from attacking, though it can cause some weird visual glitches. (You can make your own invisible entity, or probably just use a built in one like markers.)

Last seen on 18:49, 27. Jan 2024
Joined Nov 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Also, I put the procedure…
Wed, 12/13/2023 - 22:18

Also, I put the procedure under the event/target entity's update tick procedure for that entity.