Minecraft – How to test for time of day with command block in Minecraft

minecraft-commandsminecraft-java-edition

I'm trying to setup something similar to the MindCrack team's current server set up for my single player world so that the world border expands slowly as I play the game. I already know how to work the worldborder command, I just want it to happen at the exact same time every game day.

I know that you can query for the time with time query daytime which gives you the time of the day in ticks. I would set up a comparator to test the output. I just can't seem to get the testfor command to work with this. I figure I'm doing something wrong. I would guess the code would be something like this testfor [time query daytime = 1000] but of course that was wrong.

Anyone know if what I want to do is even possible?

Best Answer

You're along the right path with /time query daytime.

First of all, create an objective. In these examples I'll use "TimeObjective" although you can call it whatever you want:

/scoreboard objectives add TimeObjective dummy

Next, put /time query daytime into a command block. Then stand ontop of the command block and type this. Again, "TimePlayer" is just a fake player name, it can be anything so long as it's consistent:

/stats block ~ ~-1 ~ set QueryResult TimePlayer TimeObjective

Now, whenever the command block is activated, the current time will be stored in TimePlayer's TimeObjective score. Set that block on a clock. To test the score of a player that doesn't actually exist, you need to use this command rather than /testfor:

/scoreboard players test <PLAYER> <OBJECTIVE> <MIN> <MAX>

So for this case:

/scoreboard players test TimePlayer TimeObjective 0 1000