Minecraft Java Edition Commands – How to Test for an Entity Relative to a Player

minecraft-commandsminecraft-java-edition

Im looking for a way to test if an entity is at a player's coordinates.

I've tried

/testfor @e[type=Shulker,name=Code] @a[r=1]

But it gives this

Data tag parsing failed: Invalid tag encountered, expected '{' as first char.

Best Answer

You should use /execute to have the command executed from the player rather than the command block:

/execute @a ~ ~ ~ /testfor @e[type=Shulker,name=Code,r=1]