Minecraft – Place the player’s coordinates in a scoreboard [1.15.2]

minecraft-commandsminecraft-java-edition

I'm attempting to track a player's Y value so that I have a "lowest" and "current" set in scoreboard to do things with. However, I can't find anything–elsewhere online or here in Arqade–that can help me. I know it requires use of /execute store and /data get, but I can't for the life of me figure the syntax. All I have right now is execute as @s at @s store result entity @s Pos[1] int, but that doesn't get my anywhere as it prompts me for some form of argument after “int“`, of which it refuses to actually tell me.

Everything I've found either only mention execute store and data get briefly, eg. here. It helps guide me, but because the question asks about 1.12, it doesn't help me much else past that basic knowledge.

Best Answer

Firstly, if you want to get the position into a scoreboard and not into NBT, then you don't need /execute store result entity, but /execute store result score. That also avoids this issue. Here is an explanation of the issue anyway:

The argument that the game expects is "scale", which allows you to multiply the return value of the /data get command by a number before storing it. You can also do this in /data get, see below.

It's really weird how the syntax help for that doesn't show up. It actually does appear once you start typing anything at that position, no matter if it's correct or not. I created a bug report about that: https://bugs.mojang.com/browse/MC-173701

Here are the commands you actually want, with scoreboards:

/execute store result score @s x run data get entity @s Pos[0]
/execute store result score @s y run data get entity @s Pos[1]
/execute store result score @s z run data get entity @s Pos[2]

You can add a factor at the end of each of these. For example if you multiply by 50 when reading from NBT and later with 0.02 when reading from the scoreboard, you get the coordinate precise to 20cm. But be careful when using scale factors above 71.58, because you might get overflow issues if the player coordinates are very high. Currently you don't need to worry about Y coordinates above 30 million, because the player gets kicked anyway.