TransWikia.com

How can I make a command have escape codes inside a command with escape codes?

Arqade Asked on June 7, 2021

So basically I am trying to make a one-command-creation, which is where you have an entire project inside one long command.

I already asked a question on here which explains how the one command works, so you can have a look at my previous question to see that.

My long command makes a box, in which tons of command blocks go, which in turn makes everything work. One of my command blocks in there has a specific bit that needs either single quotes (‘example’) or double quotes with escape codes ("example").

The problem is, the long command needs it to be double quotes, nothing else. If I use double quotes, the long command works but the command block in the box doesn’t, and vice versa.

The last thing I have tried to do is put the escape codes (the backslashes), which, in theory, would make it work, but, in practice, the long command treats it as escape code for itself rather than for the command block.

So I’d appreciate if someone could tell me how I can use escape codes and make it use them in the command block (hopefully you know what I mean), or come up with a solution to the original problem, or just give me an entirelly different way to get around it.

Here’s the entire command:

summon falling_block ~ ~1 ~ {Time:1,BlockState:{Name:redstone_block},Passengers:[{id:armor_stand,Health:0,Passengers:[{id:falling_block,Time:1,BlockState:{Name:activator_rail},Passengers:[{id:command_block_minecart,Command:'gamerule commandBlockOutput false'},{id:command_block_minecart,Command:'data merge block ~ ~-2 ~ {auto:0}'},{id:command_block_minecart,Command:'fill ~3 ~-1 ~2 ~8 ~6 ~-2 gray_stained_glass hollow'},{id:command_block_minecart,Command:'fill ~3 ~-1 ~2 ~8 ~-1 ~-2 smooth_stone_slab[type=top]'},{id:command_block_minecart,Command:'playsound block.piston.extend ambient @a'},{id:command_block_minecart,Command:'fill ~3 ~6 ~2 ~8 ~6 ~-2 smooth_stone_slab[type=bottom]'},{id:command_block_minecart,Command:'setblock ~4 ~ ~-1 repeating_command_block[facing=east]{Command:"tag @e[nbt={OnGround:1b,Item:{id:"iron_block",Count:4b}}] add irondoor1"}'},{id:command_block_minecart,Command:'data merge block ~4 ~ ~-1 {auto:1b}'},{id:command_block_minecart,Command:'setblock ~5 ~ ~-1 chain_command_block[facing=east]{Command:"tag @e[nbt={OnGround:1b,Item:{id:"sticky_piston",Count:2b}}] add irondoor2"}'},{id:command_block_minecart,Command:'data merge block ~5 ~ ~-1 {auto:1b}'},{id:command_block_minecart,Command:'setblock ~6 ~ ~-1 chain_command_block[facing=east]{Command:"execute at @e[tag=irondoor1] as @e[tag=irondoor2,distance=..1] run summon item ~ ~ ~ {Tags:["itemkill1","IronDoorSpawn"],PickupDelay:20,Item:{id:"minecraft:stray_spawn_egg",Count:1b,tag:{display:{Name:"{"text":"2 x 2 Iron Door"}"},HideFlags:1,EntityTag:{id:"minecraft:silverfish",NoAI:1b,NoGravity:1b,PersistenceRequired:1b,Silent:1b,Health:0}}}}"}'},{id:command_block_minecart,Command:'data merge block ~6 ~ ~-1 {auto:1b}'},{id:command_block_minecart,Command:'setblock ~ ~1 ~ command_block{auto:1,Command:"fill ~ ~ ~ ~ ~-2 ~ air"}'},{id:command_block_minecart,Command:'kill @e[type=command_block_minecart,distance=..1]'}]}]}]}

but this part is all you need to work it out:

{id:command_block_minecart,Command:'setblock ~6 ~ ~-1 chain_command_block[facing=east]{Command:"execute at @e[tag=irondoor1] as @e[tag=irondoor2,distance=..1] run summon item ~ ~ ~ {Tags:["itemkill1","IronDoorSpawn"],PickupDelay:20,Item:{id:"minecraft:stray_spawn_egg",Count:1b,tag:{display:{Name:"{"text":"2 x 2 Iron Door"}"},HideFlags:1,EntityTag:{id:"minecraft:silverfish",NoAI:1b,NoGravity:1b,PersistenceRequired:1b,Silent:1b,Health:0}}}}"}'}

Thanks in advance.

One Answer

Again, let's work backwards from the innermost later:

{"text":"Test"}

You then want to put it inside a double-quoted string, so I've placed a in front of each " in the bold area:

execute at @e[tag=irondoor1] as @e[tag=irondoor2,distance=..1] run summon item ~ ~ ~ {Tags:["itemkill1","IronDoorSpawn"],PickupDelay:20,Item:{id:"minecraft:stray_spawn_egg",Count:1b,tag:{display:{Name:"{"text":"2 x 2 Iron Door"}"},HideFlags:1,EntityTag:{id:"minecraft:silverfish",NoAI:1b,NoGravity:1b,PersistenceRequired:1b,Silent:1b,Health:0}}}}

You then want to put all of that inside another double-quoted string. The bold section below is the entire above command. To insert it into this, you replace all with and all " with ":

setblock ~6 ~ ~-1 chain_command_block[facing=east]{Command:"execute at @e[tag=irondoor1] as @e[tag=irondoor2,distance=..1] run summon item ~ ~ ~ {Tags:["itemkill1","IronDoorSpawn"],PickupDelay:20,Item:{id:"minecraft:stray_spawn_egg",Count:1b,tag:{display:{Name:"{"text":"2 x 2 Iron Door"}"},HideFlags:1,EntityTag:{id:"minecraft:silverfish",NoAI:1b,NoGravity:1b,PersistenceRequired:1b,Silent:1b,Health:0}}}}"}

Finally, you want to place all of that inside a single-quoted string. This means you still need to replace all with and all ' with ', but luckily you don't have any single quotes so far. The bold section below is your entire code, with the above part inserted in bold:

{id:command_block_minecart,Command:'setblock ~6 ~ ~-1 chain_command_block[facing=east]{Command:"execute at @e[tag=irondoor1] as @e[tag=irondoor2,distance=..1] run summon item ~ ~ ~ {Tags:["itemkill1","IronDoorSpawn"],PickupDelay:20,Item:{id:"minecraft:stray_spawn_egg",Count:1b,tag:{display:{Name:"{\"text\":\"2 x 2 Iron Door\"}"},HideFlags:1,EntityTag:{id:"minecraft:silverfish",NoAI:1b,NoGravity:1b,PersistenceRequired:1b,Silent:1b,Health:0}}}}"}'}

If my calculations are correct, you need six backslashes on your JSON text indeed.

(By the way, if you want that 2x2 thing to have the actual multiplication sign(2×2), you can replace it with \\\u00d7. But that's another story.

If something is wrong, you can look through my workings above to find errors if needed

Correct answer by ExpertCoder14 on June 7, 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