7

We want to check whether someone has wool in their Inventory. We can test if they have minecraft:white_wool or minecraft:pink_wool etc etc with :

/data get entity @s[nbt={Inventory:[{id:"minecraft:white_wool"}]}]

But there's supposed to be a built-in tag called wool that includes all the wools, so we tried things like:

/data get entity @s[nbt={Inventory:[{tag:{wool:1}}]}]
/data get entity @s[nbt={Inventory:[{tag:{"minecraft:wool":1}}]}]
/data get entity @s[nbt={Inventory:[{tag:{"#minecraft:wool":1}}]}]

but they got nothing. How can we select someone holding any kind of wool?

1

The reason that your NBT checks don't work is because the id tag stores only the exact ID. The NBT processor does not know or care about any item tags that the item may belong to, all it notices is that your provided string (#minecraft:wool) does not match the actual value that's there (minecraft:white_wool).

The NBT checks don't have access to data pack tags. This means that the only way to accomplish your task is to test for each individual ID, or use a predicate, which requires a data pack:

{
    "condition": "entity_properties",
    "entity": "this",
    "predicate": {
        "equipment": {
            "mainhand": {
                "tag": "minecraft:wool"
            }
        }
    }
}

As I always say, a data pack is not unusual. In fact, it is actually becoming a new normal for writing commands and other actions, and command blocks are dwindling in use. So you should really become used to creating data packs, because they are much wider in terms of what you can do.

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.