How to testfor time with command block? [duplicate]

How to testfor time with command block? [duplicate] - Side view of young woman in hoodie sitting on floor near sofa and playing with obedient brown Labrador while resting during free time

How to /testfor time with command block in 1.8? Screenshots would be nice, if possible.



Best Answer

This can be achieved with /stats and /time.

First, you'll need to set up a scoreboard objective and an armor stand to store the time.

/scoreboard objectives add time dummy
/summon ArmorStand ~ ~ ~ {CustomName:"time",Marker:1b,Invisible:1b}
/scoreboard players set #MATH time 24000

The third command here simply stores a value of 24000 in a fake player called #MATH, which we'll need later.

Set up a clock, such as a fill clock, and have it run two commands:

/time query daytime
/scoreboard players operation @e[type=ArmorStand,name=time] time %= #MATH time

The second command makes it so that time resets to 0 after a full day, rather than keep going indefinitely.

Finally, stand on top of the /time command block and run

/stats block ~ ~-1 ~ set QueryResult @e[name=time,type=ArmorStand] time

You can now access the time in a target selector like any other scoreboard value, e.g.:

/testfor @e[type=ArmorStand,name=time,score_time=18000,score_time_min=18000]

to test for midnight.




Pictures about "How to testfor time with command block? [duplicate]"

How to testfor time with command block? [duplicate] - Unrecognizable ethnic man training purebred dog sitting on floor
How to testfor time with command block? [duplicate] - From below of aged metal clock tower located in city center with high towers
How to testfor time with command block? [duplicate] - Crop female in casual clothes sitting on floor and playing with adorable shetland sheepdog while spending time in modern gym





Scoreboard, Trigger, and Testfor! - 1.12 Beginner Command Block Tutorial Episode 2




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Ivan Babydov, Zen Chung, Samson Katt, Blue Bird