Skip to content

Instantly share code, notes, and snippets.

@towerofnix
Created April 21, 2017 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towerofnix/6e571437d6b86e6ef71f12aaf6855e73 to your computer and use it in GitHub Desktop.
Save towerofnix/6e571437d6b86e6ef71f12aaf6855e73 to your computer and use it in GitHub Desktop.
Minecraft 1.12 Loops

Minecraft 1.12 Loops

A single chain block cannot be run more than once per tick. But we want to run the chain block more than once per tick. The solution is to clone the chain block, in its original place, so that we really have a new chain block that we can use to run the same command again, all during the one tick.

The simplest example of this would be this:

After pressing the button, the lime (impulse) command block will run immediately. It acts as the signal for starting the loop; there doesn't actually need to be a command in it.

The impulse command block then immediately runs the chain block after it (the yellow one, just above it). This chain block clones itself and the following chain block in the same position (clone <positions> replace move). The newly cloned blocks may be run in the same tick.

Then the following chain block (the white one) runs. This chain block may contain any command; it is the "body" of the loop. Most importantly, it must run back into the yellow command block (the "clone" one), so that the loop runs again.

Thus, the loop (consisting of the yellow and white chain command blocks) will run forever, all during one tick.

Actually, the chain won't run so that it lasts for more than whatever the value of the gamerule maxCommandChainLength is (which defaults to 65536).

After the tick has finished (due to the infinite loop hitting the maxCommandChainLength limit), the red command block will be run. For the demo, this block just prints a message to chat, to demonstrate the amount of real-world time the single tick will last.

Later...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment