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?
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?
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.
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).
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.
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
/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.
Commented
Jul 19, 2019 at 5:14
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