How to testfor time with command block? [duplicate]
How to /testfor
time with command block in 1.8? Screenshots would be nice, if possible.
Solution 1:
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.