2

I'm trying to make a manhunt compass using lodestone NBT, avoiding /setworldspawn issues, but I'm having trouble copying the runner’s position array data to the compass' LodestonePos NBT tag, considering they are in different formats, and this information will be constantly changing and being updated every tick.

Runner’s Position Format (Doubles): Pos{0.0d, 0.0d, 0.0d}

Compass's Lodestone Position Format (Must be integers.): LodestonePos{X: 0, Y: 0, Z: 0}

I've tried using item modifiers, /item modify, /execute store result storage, /data modify storage, to no avail. There doesn't seem to be a way to select array positions in paths, and simply setting the value from the player's position won’t work because they are in different formats.

1 Answer 1

2

Copying the item into the player's inventory

A great post has already been made regarding this: How can I modify an item while it is inside the player's inventory?

Setting the lodestone position

These should suffice:

execute store result block <shucker box coords> Items[0].tag.LodestonePos.X int 1 run data get entity @p[<however you’re selecting the runner>] Pos[0]

execute store result block <shucker box coords> Items[0].tag.LodestonePos.Y int 1 run data get entity @p[<however you’re selecting the runner>] Pos[1]

execute store result block <shucker box coords> Items[0].tag.LodestonePos.Z int 1 run data get entity @p[<however you’re selecting the runner>] Pos[2]

Now, why does this work?

The player's Pos attribute is an array of doubles (high-precision decimal values), whereas the compass's LodestonePos is an Object with attributes X, Y, and Z, which are all ints (whole numbers between -231 and 231-1).
Why the developers decided to have different implementations of coordinates is beyond me, but what this means for us is that we have to make three seperate assignments; one for each axis.

First, we get the player's position

Let's use @p for simplicity

data get @p Pos

this will return something like [0d, 3.14d, 12345.678d], which is an array of the X, Y, and Z coordinates respectively.

data get @p Pos[0]

This is just the X coordinate

Now let's store a value into an item

Let's use 0 0 0 as the location of a shulker box with a single compass in it

execute store result block 0 0 0 Items[0].LodestonePos.X ...

This is accessing the X coordinate of the LodestonePos attribute of the first item in a shulker box at 0 0 0, presuming one exists.

breaking down the execute command

Now we have

execute store result block <shucker box coords> Items[0].tag.LodestonePos.X int 1 run data get entity @p[<however you’re selecting the runner>] Pos[0]

which will store the player's x position into the lodestone compass's X attribute.

Let's look at it piece by piece

# using the 'store' directive indicates you want to put a value somewhere
execute store 

# you want to store the value you get, not just whether-or-not it succeeds
result 

# you want to put the result into a TileEntity (aka Block Entity) like a chest or shulker box
block

#the location of the tile entity
0 0 0

# the NBT path of the tile entity you want to edit
Items[0].tag.LodestonePos.X

# indicates the resulting value should be converted to type `int`
int

# the scale of the resulting value (just multiplication)
1

# you want to run a command to get a value
run

# the command that should return the desired value
data get entity @p[<however you’re selecting the runner>] 

Making it work for X, Y, and Z

This is relatively simple. Just replace Pos[0] with Pos[1] for the Y-coodinate, or Pos[2] for the Z-coordinate. Then Replace LodestonePos.X with LodestonePos.Y and LodestonePos.Z, and there you have the 3 different commands

4
  • 1
    Could you explain how these commands solve the problem of changing the compass NBT? Why do they work the way they do? Sep 1 at 5:20
  • Nice juicy explanations and markdown for you viewing pleasure ;)
    – Jam
    Sep 1 at 5:59
  • 1
    This worked, thanks, but “Items.[0].LodestonePos.Coord” was missing “.tag.” and should be written as “Items.[0].tag.LodestonePos.Coord” for it to work.
    – HyperBlend
    Sep 1 at 22:42
  • @HyperBlend fixed. I wasn't able to test it myself so I'm not surprised I missed something :p
    – Jam
    Sep 2 at 1:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .