0

I made this Helmet via command blocks and I want to program a command block so that it always checks for if the player is wearing this Helmet, and if the player is wearing it, it replaces a the block on the coordinates 1 4 4 with a redstone block. I tried using the /execute command - my attempt was:

/execute as @p[nbt={Inventory:[{Slot:102b,tag:{Name:"{\"☀ Disco Helm ☀\"}"}}]}] run setblock 1 4 4 minecraft:redstone_block replace

Disco Helm is the name of the Helmet

This however didn't work and I'm thinking it's because of the fact that the name of the Helmet has a lot of different colors?

I'm an amateur to command blocks, so I would really appreciate if someone could fix my code, especially this part:

[nbt={Inventory:[{Slot:102b,tag:{Name:"{\"☀ Disco Helm ☀\"}"}}]}]

2
  • Hey there! Welcome to Arquade! – Eris Starmaster Dec 23 '20 at 12:37
  • Run the command data get entity @s Inventory[{Slot:103b}].tag while the helmet is on your head. The slot for the helmet is 103b and not 102b. I’m pretty sure you need to put the nbt Name in another tag named display. Once you’ve run the command, edit your answer to include the results of the data command. – randomuser922 Dec 23 '20 at 15:45
1

here is the working command. For an explaination, see below.

/execute as @s[nbt={Inventory:[{Slot:103b,id:"minecraft:leather_helmet",tag:{display:{Name:"{\"name\":\"☀ \",\"color\":\"gold\","italic":"false"},\"name\":\"D\",\"color\":\"dark_red\"},{\"name\":\"i\",\"color\":\"red\"},{\"name\":\"s\",\"color\":\"gold\"},{\"name\":\"c\",\"color\":\"yellow\"},{\"name\":\"o \",\"color\":\"green\"},{\"name\":\"H\",\"color\":\"aqua\"},{\"name\":\"e\",\"color\":\"blue\"},{\"name\":\"l\",\"color\":\"light_purple\"},{\"name\":\"m\",\"color\":\"purple\"},{\"name\":\" ☀\",\"color\":\"yellow\"}"}}}]}] run setblock 1 4 4 minecraft:redstone_block replace`

You need to specify the color for each change in color. That was the only error in your command. I have to admit, it is painstaking. If the above command doesn't work, please tell me what color you set the spaces to in the comments. (Yes, spaces have a color)

You're welcome, ShadeOfLight

0

I see a few problems, and I have one suggestion.

In order to spot the problems, let's expand your NBT into a layered structure:

0: nbt={
1:     Inventory:[
2:         {
3:             Slot:102b,
4:             tag:{
5:                 Name:"{\"☀ Disco Helm ☀\"}"
6:             }
7:         }
8:     ]
9: }

The problems:

  1. The item structure is different—the Name tag goes inside another tag named display.
    Wrong way:

    tag:{
        Name:'...'
    }
    

    Right way:

    tag:{
        display:{
            Name:'...'
        }
    }
    
  2. The raw text in the Name tag is malformed. When checking if the name matches, the system does a plain text check on the raw JSON source, and does not look at the final name after rendering. So hold the item in your main hand, and run the following command in your chat:

    /data get entity @s SelectedItem.tag.display.Name
    

    Look for the text in GREEN, that represents the raw JSON source of the name. In the original command, place the GREEN text into the Name tag. Make sure you escape double quotes where necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.