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
andslot
: 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
, andor slot
can be repeated within the same section. The system will takenot cause an error, however, only the lastlatter one that is specified (furthest to the right) as prioritywill be considered.