1

Check for item/block groups

BigBaby01 3/31/21 5:20 pm
1k
4/2/2021 8:04 am
Hey there!

I'm working on a datapack, and I need some help!

As you might know there are block and/or item groups in minecraft like #wool which contains all 16 types of wool, or #oak_logs which contains oak log, oak wood, stripped oak log and stripped oak wood.

And there is this command: /execute as @a[nbt={SelectedItem:{id:"minecraft:stone"}}] run... which executes as all players holding a stone in their mainhand.

So I wanna know if there is a possibility to do this with item groups like /execute as @a[nbt={SelectedItem:{id:"#minecraft:wool"}}] run... to do something like say "It's wool!" if you have some wool in your hand. And not to do 16 commands one for every wool colour.

It would be so nice and helpfull if someone can answer me my question!

Thanks
Posted by
BigBaby01
Level 31 : Artisan Unicorn
4

  Have something to say?

JoinSign in

6

craftykids
04/01/2021 5:26 pm
Level 53 : Grandmaster Pixel Painter
history
You can use a predicate (wiki article here). For instance, if you want to test for wool and are using the namespace "example", you could create a file at /data/example/predicates/holding_wool.json and put this in it:
{
"condition": "minecraft:entity_properties",
"entity":"this",
"predicate": {
"equipment": {
"mainhand": {
"tag": "minecraft:wool"
}
}
}
}

And then run a command like this:
/execute as @a[​predicate=example:holding_wool] run ...
3
BigBaby01
04/02/2021 8:04 am
Level 31 : Artisan Unicorn
Thank you I think this may help me! :D
1
HoboMaggot
04/01/2021 10:30 pm
Level 55 : Grandmaster Blob
Alternatively, if the condition "match_tool" equals to selectitem, you can do this instead
{
"condition": "minecraft:match_tool",
"predicate": {
"tag": "minecraft:wool"
}
} 

Thanks for reminding me about predicates
1
BigBaby01
04/02/2021 8:04 am
Level 31 : Artisan Unicorn
Also thanks to you ^^
1
HoboMaggot
04/01/2021 2:25 am
Level 55 : Grandmaster Blob
Pretty sure tags for block/entity nbt doesnt exist in general, as it has to be /data friendly.

For example, if you were to select the player with the item group "#minecraft:wool" in their hand, executing /data get entity <player> SelectedItem will get you: "SelectedItem:{id:"#minecraft:wool"}" which isnt helpful at all.
Additionally the different types of wool have their own ids e.g. orange wool = orange_wool.
1
BigBaby01
04/01/2021 3:40 pm
Level 31 : Artisan Unicorn
Thanks for your answer but sadly I dont really understand what you mean :/
I know that they all have their own id but I want to check if a player has any item of a group in his hand.
1

Welcome