Minecraft – How to detect for player with custom head

minecraft-commandsminecraft-java-edition

I'm working on an adventure map with quests etc, and need to testfor a player with a certain item in their inventory.
The item in question is a custom head with a few attributes–here's the /give command I used for it:

/give @p skull 1 3 {LeafyHeaddress:1b,display:{Name:"Leafy Headdress",Lore:["[Rare] [Quest Item]","Some irritating thorns poke out of it."]},SkullOwner:{Id:"8dc9da4f-e33d-2a9b-fd5f-39628f3c4bb4",Properties:{textures:[{Value:"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDNkYjgxNDRhMjNjYzU4NTkzMTU2M2VkNDMzMGE5ODYyYjhkNzk4ZWE0YjE1ZTNlMzE4YWM2NDk0Mzg0MSJ9fX0="}]}},AttributeModifiers:[{AttributeName:"generic.movementSpeed",Name:"generic.movementSpeed",Amount:0.15,Operation:1,UUIDMost:10481,UUIDLeast:32056}],ench:[{id:7,lvl:1}]}

I saw in another post that I could detect it with a custom tag, which I tried to use above ^ (LeafyHeaddress)

The command I'm using to test for it is:
/testfor @a {Inventory:[{tag:{LeafyHeaddress:1b}}]}
Problem is, the command block outputs nothing when a player has the item. The error simply says that the player in question did not "match the required data structure" (which I take to mean it didn't detect the item)

So, how can I fix this?

Best Answer

Create scoreboard wSkull: scoreboard objectives add wSkull dummy

[1]Repeating command block: scoreboard players set @a wSkull 1 {Inventory:[{Slot:103b,id:"minecraft:skull",tag:{display:{Name:"Leafy Headdress",Lore:["[Rare] [Quest Item]","Some irritating thorns poke out of it."]}}}]}

[2]Repeating command block: execute @a[score_wSkull_min=1] ~ ~ ~ [command you want to happen when the custom head was worn]

At [2]Repeating command block, you can do multiple of these if you want alot of things to happen whoever wears your head.

Slot:103b locates where the helmet should be put when you want to wear it inside your inventory.