4

So, in version 1.12 we can easily detect if a player has nothing selected in his hand by just using the nbt {SelectedItem:{}}.

I realise that it is no longer working in version 1.13 +. I tried to replace it with {nbt=SelectedItem:{id:“”}}, but it does not work. Does anyone know how to solve it? I'm currently working on an Antman function datapack, I really need that command to make it functionable.

1
  • Those quotation marks would not work anyway. Sep 8, 2019 at 14:11

1 Answer 1

4

You can use nbt in your target selector in 1.13+. The SelectedItem tag will not be present in a player who doesn't have a selected item.

This command would teleport every player holding an item to your position:

/tp @a[nbt={SelectedItem:{}}] ~ ~ ~

To teleport them to your position when they don't hold an item you can use a ! to negate the result, basically telling you if the player does not have a selected item:

/tp @a[nbt=!{SelectedItem:{}}] ~ ~ ~
1
  • Ohhh thats a clever way to do it. I dont even think about that. Thanks bro!
    – Bluecap MC
    Sep 8, 2019 at 11:48

You must log in to answer this question.

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