Minecraft – How to /tellraw the location of an arrow

minecraft-commandsminecraft-java-edition

I'm pretty new to NBT tags so there's a good chance this is a simple mistake, but I'm trying to tell the nearest player the XYZ location of an arrow that has hit the ground, currently I've got this running in a repeating command block:

execute as @e[type=minecraft:arrow , nbt={inGround:1b}] run tellraw @p {"nbt" : "" , "entity" : "@e[type=minecraft:arrow , nbt=inGround:1b]"}

This just prints a blank message at me.
It would be good if after this prints a second command block then kills that arrow but I don't even know where to begin with that.

Also, if anyone has any good resources on this topic, I would greatly appreciate it, there is very little good documentation that I've found.

I'm using Minecraft JE 1.16.

Best Answer

Problems:

  • NBT should be surrounded in {}s. You did this in the first part with /execute as, but this needs also to be the same with the target selector in JSON text of the /tellraw.
    nbt=inGround:1bnbt={inGround:1b}
  • You haven't specified an NBT path to find the arrow's position. Use the JSON argument {"nbt":"Pos[0]"}. Pos[0] for X, Pos[1] for Y, and Pos[2] for Z.
    Pos is an array of three numbers representing entity position.

Fixed command (for X position):

execute as @e[type=minecraft:arrow , nbt={inGround:1b}] run tellraw @p [{"nbt":"Pos[0]","entity":"@e[type=minecraft:arrow,nbt={inGround:1b}]"}]

Suggestions

You don't need to use /execute to switch the executing entity to the arrow. Running the /tellraw from the command block will do just fine.

Command with suggestions applied:

tellraw @p [{"nbt":"Pos[0]","entity":"@e[type=minecraft:arrow,nbt={inGround:1b},limit=1]"}]

Resources

Your one stop go-to resource for all your Minecraft commands needs is the Minecraft Wiki. The MC Wiki includes lots of documentation on how raw JSON text format works, with useful information on commands, and technical info on how they work. I used this page as resource to compile this answer for you.