4
Test if player is wearing specific items
I am working on an adventure map and I would like to make types of armour with certain properties. For example, I want to make it so when you wear a player head that looks like a spider head it would give you night vision. Is there some sort of command that tests if you're wearing a certain item or a certain item with a specific name?
Create an account or sign in to comment.
8
The only thing I achieved to work is that you get an effect when you hold a specific item in your hand, for example Hunger I for 10 seconds when you hold a zombie head:
/execute as @a if entity @p[nbt={SelectedItem:{id:"minecraft:zombie_head"}}] run effect give @p minecraft:hunger 10 1
The head item is saved in the player data in armor.head or the Inventory Slot 103 but I have no idea how the syntax has to be in order to test for a head item.
I tried
/execute as @a if entity @p[nbt={Inventory:[{Slot:103,Count:1,id:"minecraft:zombie_head"}]}] run effect give @p minecraft:hunger 10 1
and to me it looks as if it should work but it doesn't xD
/execute as @a if entity @p[nbt={SelectedItem:{id:"minecraft:zombie_head"}}] run effect give @p minecraft:hunger 10 1
The head item is saved in the player data in armor.head or the Inventory Slot 103 but I have no idea how the syntax has to be in order to test for a head item.
I tried
/execute as @a if entity @p[nbt={Inventory:[{Slot:103,Count:1,id:"minecraft:zombie_head"}]}] run effect give @p minecraft:hunger 10 1
and to me it looks as if it should work but it doesn't xD
I know that this is an old post, but I wanted to point out why the command to detect an item on the head isn't working as someone else could need help one day. To put things simply, "Slot" and "Count" are both bytes and must have a "b" specified after the number. Also, why make the command so complicated? /execute is not needed in this case.
Anyways, the following command should work.
~SUPERIONtheKnight
Anyways, the following command should work.
/effect give @a[nbt={Inventory:[{Slot:103b,Count:1b,id:"minecraft:zombie_head"}]}] minecraft:hunger 10 1
~SUPERIONtheKnight
Is there anyway I can make it so it only test for items with certain names, like say I made a it so only if you wear a zombie head named "test" I tried doing
/effect give @a[nbt={Inventory:[{Slot:103b,Count:1b,id:"minecraft:zombie_head",Count:1b,tag:{display:{Name:"{\"text\":\"Test\"}"}]}] minecraft:hunger 10 1
but I got an error
/effect give @a[nbt={Inventory:[{Slot:103b,Count:1b,id:"minecraft:zombie_head",Count:1b,tag:{display:{Name:"{\"text\":\"Test\"}"}]}] minecraft:hunger 10 1
but I got an error
Sorry for the late reply, haven't been very active on PMC lately(will change that soon if I can). Your {} are unbalanced, and that's why the command isn't working. Here's the fixed command:
~SUPERIONtheKnight
/effect give @a[nbt={Inventory:[{Slot:103b,Count:1b,id:"minecraft:zombie_head",Count:1b,tag:{display:{Name:"{\"text\":\"Test\"}"}}}]}] minecraft:hunger 10 1
~SUPERIONtheKnight
LOL, thank you so much!
I first tried your command and it worked. But what made me even happier was when I put a "b" behind the Slot and Count number my command worked, too!
So, I wasn't so far from the solution. But I still wonder why it needed the "b"s here because I never ever used the specifications like "b" or "f" and things worked just fine.
But yo, thanks for clearing this one up. Now I have some trust in my command skills again xD
I first tried your command and it worked. But what made me even happier was when I put a "b" behind the Slot and Count number my command worked, too!
So, I wasn't so far from the solution. But I still wonder why it needed the "b"s here because I never ever used the specifications like "b" or "f" and things worked just fine.
But yo, thanks for clearing this one up. Now I have some trust in my command skills again xD
Hmpt, well if there's no way to test for armour, another thing I could do if test if it's in your secondary hand. and I could make your secondary hand pretty much be a perk area or something, is there a command that tests for items in your secondary hand, or any part of your inventory other than mainhand.
Also for the selected item, is there a way to make certain named items only work. like for example a torch named like "Super Torch" would give night vision, but like a regular torch wouldn't work?
Also for the selected item, is there a way to make certain named items only work. like for example a torch named like "Super Torch" would give night vision, but like a regular torch wouldn't work?
Yep, the name condition also works:
/execute as @a if entity @p[nbt={SelectedItem:{Name:["ZOMBIE"]}}] run effect give @p minecraft:hunger 10 1
This way every item you hold and is named ZOMBIE gives you a Hunger I effect for 10 seconds.
It really doesn't matter which item you hold, it only has to be named ZOMBIE.
/execute as @a if entity @p[nbt={SelectedItem:{Name:["ZOMBIE"]}}] run effect give @p minecraft:hunger 10 1
This way every item you hold and is named ZOMBIE gives you a Hunger I effect for 10 seconds.
It really doesn't matter which item you hold, it only has to be named ZOMBIE.
Not that I'm aware of. Try looking on youtube for a tutorial (if it is even possible). Other than that, I don't know.