2

I'm trying to make a commands that give an arrow to the player that fired the arrow. The arrow object has Owner key that contains UUID of the player.

Is there a way to select a player with an UUID from an arrow object?

Give command:

/give @a[nbt={UUID:???}] arrow 1

Where ??? should be the value of

@e[type=arrow].Owner

1 Answer 1

1

This is a tricky thing. Simply due to the fact we cannot compare NBT tag values directly. However, if we store the first chunk UUID of a player in a scoreboard...

execute as @a[scores={uuid=0}] store result score @s uuid run data get entity @s UUID[0]

Then store the Owner UUID of the arrow...

execute as @e[type=arrow, tag=!returned, scores={uuid=0}] store result score @s uuid run data get entity @s Owner[0]

Then all you need to do is compare the scoreboard values to determine who shot the arrow and give the player the item

execute as @a if score @s uuid = @e[type=arrow, tag=!returned] uuid run give @s arrow

Finally, tag the arrow with returned so we don't have an infinite arrow glitch

execute as @e[type=arrow, tag=!returned] if score @s uuid = @a uuid run tag @s add returned

This works in 1.20.1 Java Edition. I didn't do any testing outside of that version because I use a modded client (for shaders, optimization, etc). The process should be functional in all versions of Minecraft with /data, /execute if, /execute store, and /scoreboard.

I should note that you cannot store the entire UUID of the player inside a scoreboard. This is because the entire UUID of the player uses 4 integers (128 bits) and scoreboard uses 1 integer (32 bits). In a nutshell, this means there is a chance a player shares this first UUID int and would randomly receive an arrow and the player who actually shot it will not. You can fix this by using more scoreboards and a larger execute if statement, tracking if a player shot an arrow, or just roll with it. The chance of this happening is astronomically low, but it is still possible and thankfully easy to fix.

You must log in to answer this question.

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