1

I have 6 command blocks lined up, and I want them all to do something, but only when all 6 of them are triggered. Is there anyway I can do this? (1.20.1) Here's the image

6
  • Maybe separate the conditional logic (all 6 receiving a redstone signal at the same time) from the actual command execution? So, make a series of AND gates using redstone, in between where the signals originate and where the wires connect to the command blocks. Then, have a single wire after all the logic circuits which branches into 6 and connects to each command block. If all conditions are met -- ((A && B) && (C && D)) && (E && F) -- then the signal will be transmitted to all 6 command blocks; otherwise, none will receive a signal. Commented Jul 2 at 21:33
  • I have a working mechanism which operates on this principle: if signal 1, signal 2, and signal 3 are each between two numerical values (which are different for each signal), then activate a command block which teleports the player. Commented Jul 2 at 21:34
  • 1
    Could I possibly have a visual example of that mechanism? Commented Jul 2 at 22:44
  • Sure! I’ll get a screenshot tonight Commented Jul 2 at 23:21
  • Appreciate it man! Commented Jul 2 at 23:42

1 Answer 1

2

To execute a command conditionally based on whether or not a redstone signal is received, it can be easier to accomplish by moving the conditional logic to the redstone circuit itself.

In your specific case, you want each command block to run if and only if it and all of the others are triggered at the same time. Designating your 6 command blocks as A, B, C, D, E and F, the condition for running their commands can be expressed as: ((A && B) && (C && D)) && (E && F). Note that the "and" operator is associative, meaning any pairs of command blocks, or pairs of pairs of command blocks, can be grouped together in any order, as long as all pairwise tests are performed.

So, the redstone signals which you want to activate your command blocks are filtered by the AND gates, then sent to a single "output" wire which branches into 6, with a branch connecting to each command block. This way, either all command blocks are activated together if the result of all tests is true, or none of the command blocks are activated if any of the tests is false.

Since this is very abstract, it can help to have a diagram for reference. The images below show this principle being applied to construct a 3-digit passcode using chiseled bookshelves: the command block teleports the player if and only if all 3 "input" bookshelves have books placed in the correct slot. (A chiseled bookshelf outputs a signal equal to the slot number of the last book to be placed or removed).

I've indicated which numbers the inputs 'want,' as well as the numbers of the active slots in each of the non-input bookshelves, in the first image. All three images show the same mechanism: the second is just a different perspective, and the third is the same view as the second, but after the mechanism has been activated and the command has run.

Image 1: enter image description here

Image 2: enter image description here

Image 3: enter image description here

The idea is the same for each comparison: for each user-input bookshelf, test whether the signal number is greater than or equal to the desired value, and whether the desired value is greater than or equal to the input signal. The only time both comparisons will be true is when the input signal exactly equals the desired value. So, the correct passcode (3 - 6 - 5) can be expressed in the form: ((S >= 3) && (3 >= S)) && (S >= 6) && ((S >= 5) && (5 >= S)).

The same principle of pairwise comparisons implemented using redstone circuits with comparators can be applied to your situation -- although given you have 6 sets of conditions instead of 3, your mechanism may end up being more complex!

1
  • Note that there is no need to test for 6 >= S with the middle input bookshelf, since 6 is the maximum signal value that can be produced by a bookshelf. Commented Jul 3 at 3:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .