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.

  • Those quotation marks would not work anyway. – Fabian Röling Sep 8 at 14:11
2

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:{}}] ~ ~ ~
  • Ohhh thats a clever way to do it. I dont even think about that. Thanks bro! – Bluecap MC Sep 8 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.