Skip to content

Instantly share code, notes, and snippets.

@towerofnix
Created April 27, 2017 12:47
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/eb21f09462c3e2f3d358785e7668a337 to your computer and use it in GitHub Desktop.
Save towerofnix/eb21f09462c3e2f3d358785e7668a337 to your computer and use it in GitHub Desktop.
I will not be impressed if you steal this.

A command to remotely power a command block chain and wait for it to finish, in a single tick

Disclaimer: this suggestion is based around the updates recently made in the 1.12 snapshots that make command block loops and if/else-style conditionals possible. You'll probably want to know a bit about those updates to better understand this suggestion (the tl;dr is that you can now change the direction a chain is going while it's running, and you can run individual command blocks more than once in a single tick). Also, being a programmer would be useful, since I can't guarantee I'm very good at explaining things, especially without any Big and Programming Jargon words!

Essentially I'm suggesting a command – we'll call it /activate – that does the following:

  1. Activates an impulse command block at the given position. This impulse block would run immediately – as soon as the /activate command is executed.

  2. Waits for any chain blocks following that impulse block to be complete.

  3. Proceeds with the rest of the command block chain /activate is part of (if any).

The most important thing is that this would all run without costing any ticks at all. Currently, there's two ways of remotely activating a command block:

  • Use /setblock to place a block of redstone next to the impulse command block.

  • Use /blockdata to change the impulse command block to be {auto: 1b} – that is, so that it runs without needing redstone. The impulse command block changes itself to require redstone (/blockdata ~ ~ ~ {auto: 0b}) so that it can run again later.

The trouble is, both of these only permit the command block to be run next tick. The command block won't run immediately, which will thus enforce a delay in your code – often a delay that's too costly to make these ways of remotely powering command blocks usable.


But what's the point? What does this make possible?

Most simply, it would let you write the code you do for things often just once.

For example, you could make a "procedure" (most programming languages call these "functions") that adds a tag to every player with at least 30 zombie kills, 10 skeleton kills, and 40 spider kills. Then you could use /activate to run the command blocks that make up that procedure. That would make the procedure run, and after, you could use that tag for any purpose you like, such as such as /telling them that they've finished the quest. Later on you could use /activate to activate that procedure again, but this time you could do something else with the tagged players – like giving those tagged players items as rewards for the quest, or marking off an advancement.

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