3

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?

3
  • 1
    What version of Minecraft are you using? There's a fairly easy way to do this in the latest snapshots.
    – SirBenet
    Commented Sep 28, 2015 at 18:01
  • Good for you for not wanting to use redstone. Having said that, depending on what you want to do, it may just be better to use scoreboards instead of stats, as suggested by @MrLemon. It's hard to tell what method will be the best for you without more information. It's best not to assume a solution, and instead just describe the actual solution.
    – MBraedley
    Commented Sep 29, 2015 at 1:37
  • Oops, I meant describe the problem. And in this instance a description of the problem you're having is really important. There are often multiple ways to solve a command blocking problem, but sometimes one solution has quantifiable benefits over others.
    – MBraedley
    Commented Sep 29, 2015 at 1:49

1 Answer 1

3

What you want is the stats command, with the SuccessCount stat.

The stats command

The command syntax for what you want to do is

stats block <x> <y> <z> set <stat> <selector> <objective>

<x> <y> <z> are the coordinates of the block running the command you want to get the result data for.

<stat> is one of AffectedBlocks, AffectedEntities, AffectedItems, QueryResult or SuccessCount, 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, running

stats block 1 2 3 set SuccessCount @e[type=ArmorStand,name=SCDummy] SCObjective

Afterwards, we can use

execute @e[type=ArmorStand,name=SCDummy,score_SCObjective_min=4] ~ ~ ~ <other command>

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 by execute.


There is an alternate version of the command for use with entities:

stats entity <selector2> set <stat> <selector> <objective>

This will return a <stat> for a command run by <selector2> (including when running execute off that entity).

3
  • What command would I use EXACTLY? Without a comparator?
    – Okx
    Commented Sep 28, 2015 at 15:47
  • 1
    @Okx that really depends on what your exact problem is. I added an example for SuccessCount, but depending on what you want to do, one of the AffectedXYZ stats might be better suited.
    – MrLemon
    Commented Sep 28, 2015 at 16:21
  • In 1.13, /stats was renamed to /execute store and the syntax was redone: /execute store result score @e[type=ArmorStand,name=SCDummy,limit=1] SCObjective run data get block 1 2 3 SuccessCount
    – pppery
    Commented Aug 18, 2018 at 18:34

You must log in to answer this question.

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