Minecraft Color Codes Problem (1.9)

minecraft-commandsminecraft-java-edition

Introduction to my problem

As most of you know, the section sign, aka ยง is used to add color formatting.
But the inconvenient thing is that you can't use the sign in command blocks, only in console commands. That really really is annoying, since it leaves out so many features in vanilla minecraft.

About my map, just if you wanna read 🙂

So what I need help with? I'm creating a prison escape map, not just parkour, instead with picklocks, guards, inmates, roll calls, reputation, metal detectors, custom resource packs, secret stashes and many escape possibilities. The part which I have a problem with? Custom-colored items.

I want to give items custom lores with colors (and not that ugly purple italics lore … eww). Red-colored (eg. knives, drugs, armor & guard keys) items would be contraband and result in solitary when found, orange-colored (eg. bobby pins, plastic knives & sticks) are also illegal, but won't be confiscated, since they are just not detected by guard dogs, guards or metal detectors. While it's illegal to own them, you can carry them without any sort of risk – and green-colored (eg. money, food & leather clothes) are completely legal to own and can be acquired legally.

So, what I need help with?

So, what I need? I need to be able to spawn colored items in the world. Most of the contraband can be traded from other inmates, but for example in the yard, random bobby pins and metal pieces will spawn, but I can't summon colored items (the summoned items have to be colored!).
I only found one solution by now, which is to pre-make chests in command block areas, putting an item given thru server console in them, then cloning random chests on top of the yard, breaking them a tick later so that the cloned items get dropped.
But that won't work in all areas, also would be really unconvinient if I want to give items to players, for example, for quest completion.

Any ideas? If you know how to help, please reply, it would REALLY help me!

Best Answer

Disclaimer

The section symbol is deprecated. You should avoid using it as much as possible and be aware that it will not work in the future. It is being replaced by the JSON text component, which is already supported by chat (accessible with /tellraw), book pages, sign text, and the /title command.

In-game with signs

Because sign text supports the text component, it also supports unicode characters (declared as \u####). The character for the section symbol is \u00A7.

You would use the sign to run a clickEvent that provides you with a command block that uses the section symbol at the appropriate location in its syntax. You'd then place the command block where needed.

Note that this will only work for signs because it's the sign running the command, rather than the player being forced the run the command in the chat like with /tellraw or book pages. The player would otherwise be kicked for trying to type the section symbol.

Example command:

/setblock ~ ~1 ~ minecraft:standing_sign 0 replace {Text1:"[\"\"]",Text2:"[\"\"]",Text3:"[\"\"]",Text4:"{\"text\":\"Click\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/give @p minecraft:command_block 1 0 {BlockEntityTag:{Command:/summon Item ~ ~1 ~ {Item:{id:\\\"minecraft:stone\\\",Count:1b,tag:{display:{Name:\\\"\u00A71Custom Name\\\"}}}}}}\"}}"}

Using loot tables

A custom loot table can be created to provide you with a command block containing the section symbol, which can be pasted into the JSON file directly.

For example, the following would provide the necessary command block that you'd place where desired:

{
    "pools": [
        {
            "rolls": 1,
            "entries": [
                {
                    "type": "item",
                    "name": "minecraft:command_block",
                    "weight": 1,
                    "functions": [
                        {
                            "function": "minecraft:set_nbt",
                            "tag": "{BlockEntityTag:{Command:/summon Item ~ ~1 ~ {Item:{id:\"minecraft:stone\",Count:1b,tag:{display:{Name:\"§1Custom Name\"}}}}}}"
                        }
                    ]
                }
            ]
        }
    ]
}

The command to place the chest containing the command block (assuming filepath world_name/data/loot_tables/custom/cmd.json):

/setblock ~ ~1 ~ minecraft:chest 0 replace {LootTable:"custom:cmd"}

Third-party tools (MCEdit, NBTExplorer)

You can modify the command block that contains the /summon command using either of these programs to contain the section symbol at the desired spot in its syntax.

Using MCEdit, you'd locate the command block, double-click it, and paste the section symbol and color code within the command itself.

MCEdit GUI

With NBTExplorer, you would need to locate the command block first by copy/pasting into the program's Search tool. You would then double-click the Command value and paste the section symbol at the appropriate location.

NBTExplorer GUI