TransWikia.com

How do I code a command block so that it checks for if a player is wearing a specific Helmet called "☀ Disco Helm ☀"?

Arqade Asked by purpey on January 11, 2021

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 Answers

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

Answered by ShadeOfLight on January 11, 2021

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.

Answered by ExpertCoder14 on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP