Minecraft: Execute at entity holding item with arbitrary tag
hopefully the last question for this map.
I'm trying to have a command check if the player is holding a compass with an arbitrary tag, using this command to give them the compass:
/give @p minecraft:compass{display:{Name:"{\"text\":\"Dungeon Compass\"}",Lore:["{\"text\":\"A compass. Holding this in your\"}","{\"text\":\"hand, you can see where the\"}","{\"text\":\"Triforce piece is!\"}","{\"text\":\"Legendary compasses were once\",\"color\":\"gold\"}","{\"text\":\"used to navigate the most \",\"color\":\"gold\"}","{\"text\":\"treacherous of dungeons. Now,\",\"color\":\"gold\"}","{\"text\":\"few of such items remain, lest\",\"color\":\"gold\"}","{\"text\":\"Ganon find one.\",\"color\":\"gold\"}"]},Tags:["navi:1"]} 1
and expanded:
/give @p minecraft:compass{
display:{
Name:"{\"text\":\"Dungeon Compass\"}",
Lore:[
"{\"text\":\"A compass. Holding this in your\"}",
"{\"text\":\"hand, you can see where the\"}",
"{\"text\":\"Triforce piece is!\"}",
"{\"text\":\"Legendary compasses were once\",\"color\":\"gold\"}",
"{\"text\":\"used to navigate the most \",\"color\":\"gold\"}",
"{\"text\":\"treacherous of dungeons. Now,\",\"color\":\"gold\"}",
"{\"text\":\"few of such items remain, lest\",\"color\":\"gold\"}",
"{\"text\":\"Ganon find one.\",\"color\":\"gold\"}"
]
},
Tags:[
"navi:1"
]
} 1
So what the idea is is that when a player is holding this item, it'll set their scoreboard at 1:
scoreboard players set @a navi1 0
scoreboard players set @a[nbt={SelectedItem:{tag:{Tags:"navi:1"}}}] navi1 1
Issue I'm running into is that the item simply is not getting detected. I'm guessing I've failed in my syntax around the detection of what tag is attached to it, but I've yet to be able to find any information about executing at a player holding an item with an arbitrary tag.
Thanks guys!
You forgot the square brackets:
scoreboard players set @a[nbt={SelectedItem:{tag:{Tags:["navi:1"]}}}] navi1 1
That said, this is more complicated than it needs to be. The "Tags
" tag for entities is a convenience, it gets converted to actually tags as soon as an entity is summoned. But you're not actually summoning an entity here, you're just changing an inventory slot. What actually happens is that you're using the feature of giving items arbitrary tags. You could just as well do /give @s stone{a:b}
and test for it with SelectedItem:{tag:{a:"b"}}
. You can also write lists and everything else into it, but since these have no meaning for the game, I recommend not doing that (in 99.999% of cases).
I also recommend not using colons in tag names or values if you can avoid it easily. It just causes confusion. There might also be cases where it breaks commands, but I don't know any.