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

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?


Solution 1:

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

Solution 2:

The following steps apply to the 1.13.1 version of Minecraft:

  1. Create a dummy scoreboard. Type the following command into chat;

    /scoreboard objectives add timeOfDay dummy "Time of Day (in ticks)"

  2. Show the scoreboard for testing. Use the command below;

    /scoreboard objectives setdisplay sidebar timeOfDay

  3. Summon an Armor Stand and name it "timeOfDay". You could use this command;

    /summon armor_stand ~ ~1 ~ {NoGravity:1,CustomName:"{\"text\":\"timeOfDayArmorStand\"}",CustomNameVisible:1b}

  4. Set the value of the time of day (in ticks) as the timeOfDay scoreboard value for the timeOfDayArmorStand. Paste the command in an active repeating command block;

    /execute store result score @e[type=armor_stand,name=timeOfDayArmorStand] timeOfDay run time query daytime

    To remove the timeOfDay scoreboard in the right side of the screen, type this;

    /scoreboard objectives setdisplay sidebar