TransWikia.com

How to tell if a certain item is in a player inventory?

Arqade Asked by Samuel may on November 17, 2020

I am trying to create a challenge world where a certain item (e.g. a Netherite Sword) must be collected. How can I check automatically if a player has it (using commands), and then congratulate the winner?

This question is specific to Bedrock Edition 1.16. I have tried other solutions so many times and they don’t seem to work.

One Answer

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.

* I'm not sure if a sword has any data values (e.g. for durability) so just match all data values instead of 0 just in case.

Correct answer by cherryblossom on November 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP