How can I join two lines of conditional chain command blocks without resorting to redstone?
Solution 1:
You can use CommandStats to simulate an OR gate while reducing the amount of required command blocks (since you'd essentially be running two commands for the price of one).
Prerequisites
Objective to hold the CommandStats result.
/scoreboard objectives add Condition dummy
Single armor stand to summon, which could also be used for other chains that needs it (as its score is to be reset at the beginning of the chains). This will be the entity subject to CommandStats.
/summon ArmorStand ~ ~ ~ {Tags:["conditional"]}
Mechanism
Example mechanism (you can swap out the impulse for a repeating block):
Command blocks 2 and 3 will be the initial conditional blocks, where if either are successful you would run more commands. Place a temporary command block above each of them, place the following command inside it, and activate it (you would otherwise just run the command yourself, but the character limit was exceeded):
/stats block ~ ~-1 ~ set SuccessCount @e[type=ArmorStand,tag=conditional,score_Condition=0] Condition
Now if either of those two commands run, the armor stand will have their "Condition" score set equal to the number of successful iterations of the command.
However, it will only target the armor stand if it has a "Condition" score of 0. This means that if either of them are successful, the score will be 1 and will remain at 1 even if the next command block is unsuccessful.
Commands
The following are the commands for the example mechanism above.
-
Set the armor stand's "Condition" score to 0. This is needed so it can be targeted by this chain again.
/scoreboard players set @e[type=ArmorStand,tag=conditional] Condition 0
-
One of the conditionals to check. The success of this command will trigger its stored CommandStats.
/scoreboard players test #DAYTIME daytime 0 1000
-
The second conditional to check.
/scoreboard players test #DAYTIME daytime 12000 13000
-
After the conditionals have finished, the armor stand will have a score of 1 if either of them were successful. You can then detect this armor stand with a score of 1.
/testfor @e[type=ArmorStand,tag=conditional,score_Condition_min=1,c=1]
-
Command(s) to run if either of the conditionals were successful.
/say The time is either 0-1000 or 12000-13000.
Solution 2:
One way is to create an old-fashioned /setblock
clock to trigger a new line of command blocks.
We need 4 lines of command blocks for this:
- Two (or more) for checking conditions
- One for running our commands
- One line for the reset
In the following, X Y Z
are the coordinates of a block next to the main command line's first command block.
The reset line is just a single repeating1 command block that is always on, running
/setblock X Y Z minecraft:stone
The conditional lines are using a repeat and a chain command block each. The repeating blocks are used to run your conditions. The chain command block is set to conditional and runs:
/setblock X Y Z minecraft:redstone_block
(replace the first command with your condition).
The main line starts with an impulse command block, set to require redstone. The redstone block will be set and replaced every tick by the other command blocks, so there's no need to use a repeating command block here (shouldn't matter, actually). Every other command you want to run is chained from this one.
1 If you want this to only run once, you can replace all repeating command blocks by impulse ones.
Solution 3:
You can store the result of your conditionals using a scoreboard tag
Create a single line of command blocks, starting with a repeating (or impulse) command block, followed by chain command blocks. We'll be using the fact that unconditional chain command blocks execute even when conditional command blocks earlier in the line aren't run because their condition wasn't met.
Start the line by untagging the player(s):
/scoreboard players tag @a[tag=conditionTrue] remove conditionTrue
Now, for each condition, place two chain command blocks. The first one is unconditional and runs your condition. Set the second one to conditional and put
/scoreboard players tag @a[tag=!conditionTrue] add conditionTrue
After placing down all your conditions, put one more unconditional chain block, running
/testfor @a[tag=conditionTrue]
followed by your commands, which are all run by conditional chain blocks.