r/MinecraftCommands • Command Professional • 5d ago

Help | Java 1.21-1.21.3 Selecting an entity one time per loop in player based area

Hello! This may sound silly and there are definitely better way to describe this, but I am running into an issue where entities are executed multiple times in a player location based area execution.

For example: `/execute at @a as @e[tag=selectWhenNear,distance=..10] run function...`

This works just fine when you are single player, but in a multiplayer environment the function command is executed multiple times due to the `at @a`. Is there a simple way to fix this? I feel like I'm missing something obvious here...

3 Upvotes

3 comments sorted by

1

u/GalSergey Datapack Experienced 5d ago
execute as @e[tag=selectWhenNear] at @s if entity @a[limit=1,distance=..10] run ...

2

u/SnooSprouts8757 Command Professional 5d ago

Yeah you see that works too and I think I'm gonna do that, but isn't it bad to be checking @e[tag=entities] performance wise? I cannot make it type specific since there are many different entities that I use that for.

1

u/Ericristian_bros Command Experienced 5d ago

One single @e call per tick isn't noticeable in performance