How to /testfor
time with command block in 1.8? Screenshots would be nice, if possible.
-
1Have you made any attempts to do this yourself? Is a daylight sensor not viable for your specific problem? Why (i.e. describe what you want to achieve)? We are not a "build-your-command"-website, and we like to see people put effort into a question before putting effort into answers.– MrLemonCommented Feb 10, 2016 at 9:06
1 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.
-
1The target for
/stats
can only resolve to 1 target, thus cannot be@a
for a multiplayer environment. You could instead have it target a fake player (such as/stats X Y Z set QueryResult #NAME time
) and use/scoreboard players test #NAME time 18000 18000
to check the score. Alternatively, it could be set to a dummy entity like an armor stand, allowing you to use/execute
and other commands off of it. Commented Feb 10, 2016 at 15:47 -
@Skylinerw Thanks, didn't know that. I changed it to use an invisible armor stand instead.– MrLemonCommented Feb 10, 2016 at 18:20
-