Minecraft – way I can testfor an entities coordinates, then use /tellraw to put the coordinates in the chat

minecraft-java-edition

Is there a way I can /testfor an entities coordinates, then use /tellraw to put the coordinates in the chat?

For example, if I use /spreadplayers ~ ~ 50000 50001 false @e[type=ArmorStand,r=1]

After it has teleported can I have the game detect its coordinates, and say them in chat?

Best Answer

Not easily.

You'll have to convert the player's position into a scoreboard objective first and then use that. There are no simple ways to do this.

The fastest way I can think of would be using an armorstand as a copy of the player, and teleport it around to figure out where it is using powers of 2: Check if x>256, increment score, teleport by -256, check if x>128, and so on...

That would require about 3×2log(Xmax-Xmin) command blocks for x, where Xmax and Xmin are the highest and lowest possible coordinates, and similar numbers for y and z. For a 256x256x256 cube, you are looking at (3×8)×3=72 command blocks.

To be multiplayer (or multi-entity)-friendly, you'll need to either perfectly identify every such armor stand to a player, or else do it sequentially for every player. Dealing with negative coordinates is another problem.