2

Execute players holding renamed item

macandcheese271's Avatar macandcheese2719/15/19 2:25 pm history
2 emeralds 281 8
10/7/2019 6:45 pm
macandcheese271's Avatar macandcheese271
How do I execute players holding a renamed item? I've checked for hours and on other forums when people say it works for them, it seems to never work for me.

I'm trying to detect for a carrot on a stick with the name "USP". I'm doing /give @p carrot_on_a_stick{display:{Name:"\"USP\""}} to get it.

I've done things like
/execute if entity @s[{SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"USP"}}}}]
and
/execute if entity @s[nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"{\"text\":\"USP\"}"}}}}]
but nothing works.

You gotta help me, please. I'm desperate. C'mon, please.
Posted by macandcheese271's Avatar
macandcheese271
Level 1 : New Miner
0

Create an account or sign in to comment.

8

4
09/15/2019 4:05 pm
Level 87 : Elite Deity
Captain_JEK
Captain_JEK's Avatar
The second command works if you replace the s in @s with an a:

/execute if entity @a[nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"{\"text\":\"USP\"}"}}}}]

@s checks for the current entity. So, @s only works when you're executing this command yourself. I put it in a command block and therefore had to change @s to @a. This way it checks for every player if they hold a carrot on a stick named "USP".
2
09/16/2019 5:58 pm
Level 1 : New Miner
macandcheese271
macandcheese271's Avatar
I'm executing the command, but it still says "Test Failed" when I hold the carrot on a stick
Maybe I've been cursed? Who knows.
1
09/17/2019 10:24 am
Level 87 : Elite Deity
Captain_JEK
Captain_JEK's Avatar
Yes, the "test failed" message is the sign that the command was executed successfully xD
You have to put another command behind this first one that will be executed if the first command was successful.
But here there is no other command. It only checks if a player is holding a carrot on a stick named "USP".
2
09/17/2019 4:09 pm
Level 1 : New Miner
macandcheese271
macandcheese271's Avatar
But when I do that, the command behind it won't run.

Am I doing it wrong?
the command: /execute if entity @a[nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick",tag:{display:{Name:"{\"text\":\"USP\"}"}}}}] run say 1
1
09/18/2019 10:43 am
Level 87 : Elite Deity
Captain_JEK
Captain_JEK's Avatar
Yes, your command is correct. I just tried it myself and for whatever reason the command only says "1" if your carrot on a stick's name was changed to "USP" in an anvil.
It didn't work with the carrot on a stick I gave myself with a command even though the displayed name is "USP" as well.

No idea why that is, but your command works if you change the item's name in an anvil ^^
2
09/18/2019 9:57 pm
Level 1 : New Miner
macandcheese271
macandcheese271's Avatar
Ok. Any idea on how to make it work when given with commands?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome