4

Test if player is wearing specific items

Swanlet's Avatar Swanlet4/8/19 8:21 am
4 emeralds 17.3k 8
5/21/2019 10:50 pm
SUPERIONtheKnight's Avatar SUPERIONtheKnight
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?
Posted by Swanlet's Avatar
Swanlet
Level 39 : Artisan Miner
11

Create an account or sign in to comment.

8

Captain_JEK
04/08/2019 10:00 am
Level 87 : Elite Deity
Captain_JEK's Avatar
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
1
SUPERIONtheKnight
05/02/2019 11:24 pm
Level 29 : Expert Engineer
SUPERIONtheKnight's Avatar
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.
/effect give @a[nbt={Inventory:[{Slot:103b,Count:1b,id:"minecraft:zombie_head"}]}] minecraft:hunger 10 1
~SUPERIONtheKnight
2
Swanlet
05/13/2019 12:11 pm
Level 39 : Artisan Miner
Swanlet's Avatar
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
1
SUPERIONtheKnight
05/21/2019 10:50 pm
Level 29 : Expert Engineer
SUPERIONtheKnight's Avatar
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:
/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
1
Captain_JEK
05/03/2019 5:44 pm
Level 87 : Elite Deity
Captain_JEK's Avatar
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
2
Swanlet
04/08/2019 10:31 am
Level 39 : Artisan Miner
Swanlet's Avatar
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?
1
Captain_JEK
04/08/2019 12:06 pm
Level 87 : Elite Deity
Captain_JEK's Avatar
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.
1
ItsDaCreeperOfficial
04/08/2019 8:26 am
Level 26 : Expert Creeper
ItsDaCreeperOfficial's Avatar
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.
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome