I am trying to create a challenge world where a certain item (in my example, a Netherite Sword) must be collected. Using commands, how can I if a player has it, and then run a command, for example, congratulating the winner?

I am also looking for a way to detect these items in a specific item slot. For example, a pair of Netherite Boots should run some commands to give the player the Speed effect when worn.

Is this possible? This question is specific to Bedrock Edition 1.16.

See also: Testing for a certain dropped item

Browse more workarounds for getting/setting NBT in MCBE

  • @ExpertCoder14 you edited the question to specify that testing for items in a specific slot was possible, but then don't seem to have actually added an answer saying how to do it.
    – pppery
    Commented Feb 8, 2022 at 4:32
  • @pppery I did not have time to make that answer, so I just drafted up a starter so you get an idea of what the answer details. Of course this is only preliminary and I will update this to be more professional and thorough once more is discovered about this.
    – One 2 Many
    Commented Feb 8, 2022 at 6:15

2 Answers 2


Outdated: pre-v1.18.30 only

ExpertCoder14’s answer is better for v1.18.30 and up.

You can use /clear<player> netherite_sword -1 0. The -1 matches all data values and the 0 specifies the maximum number of items to clear (so none will be cleared). If the player has at least 1 netherite sword in their inventory, the command will output a success.

The success can be detected using a chain command block. Put the /clear any command block facing a conditional, always active, chain command block with the command that you want to execute if the player has a netherite sword.

  • 2
    fyi: Removed your assumption; it's correct.
    – aytimothy
    Commented Jan 28, 2022 at 4:36
  • 1
    Out of date! The /clear method has been superseded by hasitem=. It is more convenient than relying on command block output.
    – One 2 Many
    Commented Jun 23, 2022 at 4:12

Up-to-date answer

As of 1.18.30, the beta containing these features has been released.

The latest releases of Minecraft: Bedrock Edition have added a new target selector argument, hasitem=.

Syntax is as follows:

One item:

@a[hasitem={ item=<…>, count=<…>, data=<…>, location=<…>, slot=<…> }]

Multiple items:

@a[hasitem=[ { item=<…>, ……… }, { item=<…>, ……… } ]]

Fields are:

  • item: Test for which item ID?
  • count: Test for a certain count of this item. Can be a number or range (5..10)
  • data: Test for the item's data value.
  • location and slot: Only consider the slots specified to look for the item. location specifies the slot category, slot specifies the slot number.

If multiple sections are specified within [ {}, {} ], all must pass.

Repeating any of item, count, data, location, or slot within the same section will not cause an error, however, only the latter one that is specified (furthest to the right) will be considered.

You must log in to answer this question.

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