Event Detectors

I used the Flower Dropping and Picking up system that I also used in the video tutorial. Commands can of course be modified, more about that at the bottom of the page. 

 

It works by checking if a situation went from true to false or from false to true in a certain tick. Because minecraft does every action per tick, we can check if a contradiction occurs when we check a situation twice, one before, and once after the situation has happened. (situation can imply anything that you want to check for)


After the event happened - add the default tag (nr 2)

   :> scoreboard players tag @a add flowerChecker_2


After the event happened - remove tag if the situation is still the same (nr 2)

   :> scoreboard players tag @a remove flowerChecker_2 {Inventory:[{id:minecraft:yellow_flower,Count:1b}]}


Output 1 - when nr 1 is false, but nr 2 is true. This detects if the flower has been picked up. The change was from false to true.

   :> execute @a[tag=flowerChecker_1] ~ ~ ~ execute @p[r=0,tag=!flowerChecker_2] ~ ~ ~ say This flower deserves better soil


Output 2 - when nr 1 is true, but nr 2 is false. This detects if the flower has been dropped or placed. The change was from true to false.

    :> execute @a[tag=!flowerChecker_1] ~ ~ ~ execute @p[r=0,tag=flowerChecker_2] ~ ~ ~ say That looks a lot better!


We start the mental "loop" here. By starting here, commands will make more sense.

Before the event happened - add the default tag (nr 1)

   :> scoreboard players tag @a add flowerChecker_1


Before the event happened - add the default tag (nr 2)

  :> scoreboard players tag @a remove flowerChecker_1 {Inventory:[{id:minecraft:yellow_flower,Count:1b}]}


By modifying the command that remove the tags, you can change what event you want to detect.

 

For example, using a command like this one:

   :> execute @e[name=Henry] ~ ~ ~ scoreboard players tag @a remove henryChecker_1

Will remove the tag (nr 1 in this case) when an entity with the name Henry is in the world (in loaded chucks to be more specific). This can detect if an entity is killed or moved into unloaded chunks.

 

The following command

  :> execute @a ~ ~ ~ detect 0 4 18 spruce_door 3 scoreboard players tag @a remove doorChecker_1

Will detect a spruce door on the coordinates 0 4 18, with a data value of 3 (which is a closed door facing north). This can detect a door that has been opened or closed.