Minecraft – Copying & pasting multiple commands to Minecraft terminal

minecraft-commandsminecraft-java-edition

Update: Using this I created this tool for copy & pasting QR codes into Minecraft

I wanted to compose a bunch of commands in an external editor and then paste them all to execute in the Minecraft console (chat window).

But if you paste multiple lines, it seems to just ignore the line breaks. My next thought was to use a separator between commands, such as a semicolon, but after a bit of DuckDuckGoing I couldn't find any such separator.

This is for a realm, and I'm running the Java version.

Example

For example, I'd like to be able to do things like compose a little script like this in an external editor:

/setblock 0 0 0 air
/playsound block.bell.use master @p

Then copy it to clipboard, open Minecraft and press "t" to open the command line / chat. Then if I paste, unfortunately what I get is

/setblock 0 0 0 air/playsound block.bell.use master @p

What I'd like to happen is for it to run several commands.

Update I don't mean functions, as I want anyone to be able to paste in commands, not only realm admins but anyone with cheats on.

Best Answer

Before functions and structure blocks existed, the best way to send someone a command block contraption was a "one-command-creation", which summoned a falling command block riding a falling command block riding a falling command block …

Currently there is a bug that breaks these: https://bugs.mojang.com/browse/MC-145113
But you can work around it by using other entities in between that instantly die. So you can for example do it like this:

summon falling_block ~ ~2 ~ {Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"say 1"},Passengers:[{id:"armor_stand",Health:0,Passengers:[{id:"falling_block",Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"say 2"},Passengers:[{id:"armor_stand",Health:0,Passengers:[{id:"falling_block",Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"say 3"}}]}]}]}]}

This executes all three commands, say 1, say 2 and say 3, in that order. If you also want to clean up afterwards, you can simply add another command block that removes the tower:

summon falling_block ~ ~2 ~ {Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"say 1"},Passengers:[{id:"armor_stand",Health:0,Passengers:[{id:"falling_block",Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"say 2"},Passengers:[{id:"armor_stand",Health:0,Passengers:[{id:"falling_block",Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"say 3"},Passengers:[{id:"armor_stand",Health:0,Passengers:[{id:"falling_block",Time:1,BlockState:{Name:"command_block"},TileEntityData:{auto:1,Command:"fill ~ ~-3 ~ ~ ~ ~ air"}}]}]}]}]}]}]}


Michael Dibbets/Tschallacka has created a generator in 2020 for these combined commands: https://www.tschallacka.de/minecraft/multiple-commands-generator (mirror, archive)

Enter your commands in the text field above the red button, one per line, without slashes in front (so like a function) and press the button. The bottom text field will then contain the combined command.
The generator does not validate if the commands are valid and it does not ignore empty lines or lines starting with #, so you cannot simply copy-paste function files into it.

Licensing information on his profile (archive).