Do Command Blocks have character limits?

Do Command Blocks have character limits? - Young displeased man with piercing making face

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?



Best Answer

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




Pictures about "Do Command Blocks have character limits?"

Do Command Blocks have character limits? - Positive black kids pretending to be angel and devil in studio
Do Command Blocks have character limits? - Cute little black siblings in angels costumes playing on couch
Do Command Blocks have character limits? - Blue and White Cartoon Character



How do you type longer commands in Minecraft?

commands in chat are restricted to a certain length and therefor cannot run all commands through the chat if to long. Try giving yourself a command block by typing /give <name> minecraft:command_block then copy and paste the command you want to run.

What is the character limit in Minecraft?

There should be something like a 1024 character limit, if the message starts with a "/", but messages that don't start with a "/" should only have a limit of 256 as before.

Can command blocks do op?

Command Blocks will execute commands with an OP level 2 permissions. This means the following commands cannot be used with these blocks. /ban, /banlist, /ban-ip, /debug, /deop, /kick, /op, /pardon, /pardon-ip, /publish, /save-all, /save-off, /save-on, /stop, /whitelist.

What is the limit of the Fill command?

Fill command can't place blocks in the void or beyond the world limit. It can place up to 32,768 blocks at once.



Player made Command Block Creations are Next Level...




More answers regarding do Command Blocks have character limits?

Answer 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

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Andrea Piacquadio, Marta Wave, Marta Wave, RODNAE Productions