I need to make sure an entity has the same Y value as a player. Is there any way to do that?

I'm summoning the entity at ^ ^ ^3 relative to the player, and then I need it to teleport to the Y level of the player too, while conserving its X and Z. Is there any way to do that?

1 Answer 1


Since you only want to move non-player entities, you can simply copy your Y coordinate to theirs in NBT:

/execute store result entity @e[type=item,limit=1] Pos[1] double 1 run data get entity @s Pos[1]

But that rounds down to the bottom of the block you're in, so for example the entity would fall through slabs if you are standing on slabs. You can increase the accuracy by scaling up when reading from NBT and scaling down when writing into NBT. Currently (1.15.2) all block heights are in steps of 1/32 of a block (archive). And if you're not standing on a block, then rounding down 1/32 shouldn't matter anyway. Using 64 as a scale factor gives you even better accuracy:

/execute store result entity @e[type=item,limit=1] Pos[1] double .015625 run data get entity @s Pos[1] 64

You will also not get any overflow issues with this scale factor, because if you were above y=33554432 for some reason, you would get kicked anyway.


You must log in to answer this question.

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