I want to make a pretty much redstone-less contraption, so I want to detect a command block's NBT data, so that when it gives out a comparator signal, another command block detects that and then does something. Any help?
Minecraft – How to detect if a command block is outputting a redstone comparator signal
minecraft-commandsminecraft-java-edition
Best Answer
What you want is the
stats
command, with theSuccessCount
stat.The
stats
commandThe command syntax for what you want to do is
<x> <y> <z>
are the coordinates of the block running the command you want to get the result data for.<stat>
is one ofAffectedBlocks
,AffectedEntities
,AffectedItems
,QueryResult
orSuccessCount
, depending on what you want to do (check the wiki for more information).SuccessCount
is typically the same as output redstone power, but isn't capped to 15 (IIRC, it does vary for some commands).<selector>
and<objective>
specify a target entity and a scoreboard objective in which to store the result. I suggest using either@a
(useful for executing directly on the players if a condition is met) or a named armor stand as the selector.Example
We have a command block running a
testfor
command (at coordinates 1 2 3), and we want to run another command if at least 4 entities (e.g. players) qualify*. We create a (dummy) scoreboard objective called "SCObjective" and summon in an (invisible, marker) armor stand called "SCDummy". We create another command block, runningAfterwards, we can use
to run our command based on the result of the testfor.
* This is one of the few cases where
testfor
is useful and can not easily be replaced byexecute
.There is an alternate version of the command for use with entities:
This will return a
<stat>
for a command run by<selector2>
(including when runningexecute
off that entity).