Can you tp entities to other entities in java 1.16.1

im trying to create a trident that when thrown will make salmon tp to it. the example command is tp @e[type=husk] @e[type=snowball] this was the test but it didnt work with (@e[type=snowball]) being red. Am i doing something wrong or is it possible at all.


Look at the error message caused by @e[type=snowball].

Only one entity is allowed, but the provided selector allows more than one at position 0:

What you need to do is limit the number of entities returned to 1. So try the following instead:

@e[type=snowball,limit=1]

Learn more about these concepts on the Minecraft Wiki:

  • Target selector arguments

What should that command do if there is more than one snowball on the map? It doesn't make sense to teleport one entity to more than one, and Minecraft can't tell which snowball you mean, so it throws an error.

Do you want to ...

Teleport each husk to the snowball nearest to the command block?

/tp @e[type=husk] @e[type=snowball,sort=nearest,limit=1]

Teleport each husk to the nearest snowball to the husk?

/execute as @e[type=husk] at @s run tp @s @e[type=snowball,sort=nearest,limit=1]

Pick a random snowball and teleport all husks to it?

/tp @e[type=husk] @e[type=snowball,sort=nearest,limit=1]

Assume there is only ever one snowball, and cause unknown behavior if there turns out to be more than one?

/tp @e[type=husk] @e[type=snowball,limit=1]

Something else I haven't thought of?

You have to include limit=1 somewhere in the command to tell Minecraft to only pick one entity to try to teleport things to. At that point, it's a good idea to decide what should happen if there is more than one snowball (or trident in the non-hypothetical case) and modify the command accordingly.