2

I'm doing a lot of Big Commands in this map of mine and I was thinking that maybe, like chat Command Blocks might have a character limit.

Does anyone know the limit or if there isn't one?

  • 1
    Why the down vote? – FireStrike289 Nov 14 '14 at 23:46
  • Maybe because the answer is easily found on the wiki. And you can find the page on first position on google by typing "minecraft command block character limit". Just a guess ^_^ – Ealhad Jul 7 '15 at 7:46
5

According to the Minecraft Wiki, there is a limit, but it's a very large one.

See the Command Block page on the Minecraft Wiki:

The text limit for commands in a command block is 32,767 characters, but the text pane can only show a small portion of this amount at a time.

2

With client (32,500)

As of 1.9, the character limit when using the command block's interface has been reduced to 32,500 (down from 32,767). This change was to help circumvent crashes when exceeding the packet limit of 32,767 bytes, as more information than just the command is sent to the server when confirming changes (including the various options in the interface).

With server (2^31-1 or 65,535)

The command is stored by the server as an NBT string. Technically the character limit is as much as can fit in Java's String type, being Integer.MAX_VALUE (2^31-1).

However, when saving the string to, for example, a chunk file, a new character limit comes from Java's DataOutput.writeUTF() method:

If this number is larger than 65535, then a UTFDataFormatException is thrown.

If UTFDataFormatException is thrown, the chunk will fail to save. Therefore for map distribution, the character limit is 65,535. Since the client can only send 32,500 characters of a command, it will not be possible to modify the command block via the interface without trimming the command.

Example

One method to obtain a command block on a vanilla server that reaches the 65,535 limit is to use a loot table. Loot tables can create a command block item containing a preset command, which is all handled server-side (thus no client limit of 32,500).

With the following loot table located at WORLD/data/loot_tables/custom/limit.json: http://pastebin.com/8tmeeU4M

And the following command to create a chest containing the relevant command block:

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

Placing and activating the command block will run a 65,535-character-long /say command, and you will see the final character of "1" in the chat (indicating the command was not trimmed). You can then exit the world and re-enter, and the command will still function.

Attempting to add more characters will still allow it to work while the chunk is loaded, but once you exit the world or otherwise unload the chunk, the chunk will fail to save with the following error:

[STDERR]: java.io.UTFDataFormatException: encoded string too long

  • I just want to say that if you try this very thing on singleplayer with a datapack, but instead use /loot give @p loot minecraft:custom/limit, you will receive a command block with the command, but the limit will still be in effect. I was really looking forward to using this is a singleplayer world. – Diriector_Doc Jul 19 '19 at 5:14
  • @Diriector_Doc That's only the case if you edit the command block after placing it, which is the client interacting with the server (and is thus being limited to 32,500 characters). This still works as long as you don't edit the command block. – Skylinerw Jul 19 '19 at 6:43
-2

Yes there is a character limit. You don't have to worry about it unless you are doing a one command creation. Also if it is in 1.9+ there is no character limit. Mojang got rid of it while developing 1.9

  • 3
    That's not correct. There will always be a character limit, it's just how it works. – Skylinerw Feb 6 '17 at 0:54

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.