The reason for not adding 1 in the last set is because each tick already adds 1 to time, so we need to remove one from the score, otherwise we will be going past 23459.
Now that should be everything to make this work perfectly. Of course, it won't be quite as instantaneous when you get into a bed, but it shouldn't take more than one second.
Thank you for your replies, I have already reverse-engineered this myself.
I'm using time add 200, and this doesn't seem to skip past sunrise much.
So my recipe (for the sake of those who will come to this thread later) is like this:
Preparation.
Create new scoreboard objective, not linked to any statistic (a dummy). I'll call mine Sleep, but you can change the name.
Command: /scoreboard objectives add Sleep dummy Disable command block output in chat, because it will be spammy: /gamerule commandBlockOutput false You also might want to disable it in the server logs: /gamerule logAdminCommands false
Choose a safe place, maybe somewhere in bedrock layer, and create a command block. Set it on Repeat, Unconditional, Always Active.
This command block will be increasing Sleep score by 1 every tick for all players(@a) in bed (have NBT tag Sleeping = 1).
Command for the command block: scoreboard players add @a Sleep 1 {Sleeping:1b}
Place another command block, so one from step 2 would be pointing into it (that's called chaining). Set it on Chain, Conditional, Always Active.
This command block will be checking if any player (@a) has Sleep score at least 120. Since 1 game tick is 1/20th of a second, player will reach Sleep score 120 after 6 seconds - while it takes only 5 seconds to sleep normally.
Command for the block: scoreboard players test @a Sleep 120
Chain another command block after the one from step 3. Set it on Chain, Conditional, Always Active.
This command block will be advancing server time every tick there is a player with sufficient Sleep score. If command from step 3 failed (no such player yet), it won't run. The more you add, the faster the time will advance. Once the sun rises, the game will kick you out of the bed.
Command for the block: time add 200
Normally, that would be enough, but there is another thing to consider: thunderstorms. You can sleep during thunderstorms, and advancing server time won't clear them out any quicker, potentially leading to server fastforwarding several in-game weeks.
So create another command block, chained after one from step 4: Chain, Unonditional, Always Active.
It will be similar to step 3, except you will need a larger Sleep score to test for. The bigger value you test for, the longer it will take for the contraption to register that player has stayed in bed for too long. As before, 1 second is 20 game ticks.
Command for the block: scoreboard players test @a Sleep 180
And another chained command block, set to Chain, Conditional, Always Active.
This one will set the weather to rain instead of thunderstorm, causing the game to kick you out of the bed. The rain duration is in seconds, however you can omit it to get random duration.
Command for the block: weather rain 30
Now, create a command block NOT chained to the previous ones. Set it to Repeat, Unconditional, Always Active.
This one will nullify Sleep score for any player(@a) NOT in bed (having NBT tag Sleeping = 0).
Command for the block: scoreboard players set @a Sleep 0 {Sleeping:0b} This one os the most spammy, as it will be running constantly when all players are ouf ot the bed, flooding the server log with messages.
As you can see, this one doesn't announce that a player is sleeping. It's kinda enough for me, but I guess it'd be possible with some additional circuitry.
My idea is following:
if you find a player with Sleep objective set exactly to 1 (by means of scoreboard players test @a Sleep 1 1), use /tellraw command to say that someone is sleeping. It will only match a player on the very first tick of the sleep, so the message won't be repeated until the player gets out of the bed and their Sleep score is nullified.
Alternatively, you can use /execute to make that player say they are sleeping.
Thank you for your replies, I have already reverse-engineered this myself.
I'm using time add 200, and this doesn't seem to skip past sunrise much.
So my recipe (for the sake of those who will come to this thread later) is like this:
Preparation.
Create new scoreboard objective, not linked to any statistic (a dummy). I'll call mine Sleep, but you can change the name.
Command: /scoreboard objectives add Sleep dummy Disable command block output in chat, because it will be spammy: /gamerule commandBlockOutput false You also might want to disable it in the server logs: /gamerule logAdminCommands false
Choose a safe place, maybe somewhere in bedrock layer, and create a command block. Set it on Repeat, Unconditional, Always Active.
This command block will be increasing Sleep score by 1 every tick for all players(@a) in bed (have NBT tag Sleeping = 1).
Command for the command block: scoreboard players add @a Sleep 1 {Sleeping:1b}
Place another command block, so one from step 2 would be pointing into it (that's called chaining). Set it on Chain, Conditional, Always Active.
This command block will be checking if any player (@a) has Sleep score at least 120. Since 1 game tick is 1/20th of a second, player will reach Sleep score 120 after 6 seconds - while it takes only 5 seconds to sleep normally.
Command for the block: scoreboard players test @a Sleep 120
Chain another command block after the one from step 3. Set it on Chain, Conditional, Always Active.
This command block will be advancing server time every tick there is a player with sufficient Sleep score. If command from step 3 failed (no such player yet), it won't run. The more you add, the faster the time will advance. Once the sun rises, the game will kick you out of the bed.
Command for the block: time add 200
Normally, that would be enough, but there is another thing to consider: thunderstorms. You can sleep during thunderstorms, and advancing server time won't clear them out any quicker, potentially leading to server fastforwarding several in-game weeks.
So create another command block, chained after one from step 4: Chain, Unonditional, Always Active.
It will be similar to step 3, except you will need a larger Sleep score to test for. The bigger value you test for, the longer it will take for the contraption to register that player has stayed in bed for too long. As before, 1 second is 20 game ticks.
Command for the block: scoreboard players test @a Sleep 180
And another chained command block, set to Chain, Conditional, Always Active.
This one will set the weather to rain instead of thunderstorm, causing the game to kick you out of the bed. The rain duration is in seconds, however you can omit it to get random duration.
Command for the block: weather rain 30
Now, create a command block NOT chained to the previous ones. Set it to Repeat, Unconditional, Always Active.
This one will nullify Sleep score for any player(@a) NOT in bed (having NBT tag Sleeping = 0).
Command for the block: scoreboard players set @a Sleep 0 {Sleeping:0b} This one os the most spammy, as it will be running constantly when all players are ouf ot the bed, flooding the server log with messages.
As you can see, this one doesn't announce that a player is sleeping. It's kinda enough for me, but I guess it'd be possible with some additional circuitry.
My idea is following:
if you find a player with Sleep objective set exactly to 1 (by means of scoreboard players test @a Sleep 1 1), use /tellraw command to say that someone is sleeping. It will only match a player on the very first tick of the sleep, so the message won't be repeated until the player gets out of the bed and their Sleep score is nullified.
Why does the command for step 7 need to be separate from the others? If it's unconditional it won't be affected by the other commands running.
Wow, ok, I only just saw this, and purely by coincidence, this was what I've been working on over the last three weeks or so. I don't know if anyone's still interested in it, but here's a link if you want to take a look.
It works pretty much exactly the same as others have described. Tests for sleeping players, waits for 105 ticks, calculates the time left in the day, and then all in one tick adds time until it's dawn of the next day.
Out of curiousity.. How did you manage to calculate a number like that within one tick?
Why does the command for step 7 need to be separate from the others? If it's unconditional it won't be affected by the other commands running.
Just putting a bit of emphasis on it. When I was building this contraption, I used pick block key on conditional block, and forgot to change it, leadign to a bit of wtf moment later.
So I'm just making sure. =D
In the one command it actually does both of these steps at once when it uses /setblock though:
/setblock x y z minecraft:chain_command_block [data value] replace {CommandStats:{QueryResultName:"<selector>",QueryResultObjective:"<objective>"},Command:time query daytime}
Not sure what you mean by round up to the next 24000. Isn't that what I explained in the post you quoted, or do you mean something else?
Now that's some voodoo here... what's with all the missing values? I mean, x y z are supposed to be coords, and data value is supposed to be a number, right? And then there is <selector> and <objective> which I have no idea about.
As for my second question, time goes past 24000 because now there is such thing as local difficulty that changes as days go by. As such, setting the time to value below 24000 means resetting the difficulty to the first day. Does /time query daytime give you the correct number (dawn of the next day, not the first day)?
/time query daytime is basically total time % 24000. Meaning if the time is 24000 it will return 0, if the time is less than 24000 it will return the time, and if it is greater than 24000 it will return the remainder of time / 24000. For example, time is 881280, that means 36 days have passed and the current time of the 37th day is 17280. /time query daytime will return 17280.
Xisuma posted a guide to make a rather advanced system for solo sleeping. Features include thunderstorm detection, player notification, and ability to kick players out of the bed if you want the night to stay.
Preparation commands (underscored are things you can rename to your liking):
block chain 1 counts ticks players in beds have been sleeping, and enabled the kick trigger if there is any such player.
block 2 creates notification for each player who has slept for exactly one tick (so it won't repeat). Notification has some additional JSON voodoo that lets players trigger a command by clicking it.
block chain 3 clears out sleep score for players who got out of bed and disables the kick trigger
block 4 fast-forwards the daytime if a player sleeps longer than it'd normally take
block 5 triggers if player has slept for way too long, indicating there is thunderstorm going on. It cuts the thunderstorm to one more second, letting weather engine come up with something else.
block chain 6 seeks for sleeping players that have the kick trigger active, and summons snowball above them. Snowball deals 0 damage, but it's still an attack, so players will get up. It then disables the kick trigger again.
How to set up one player sleeping in the 1.9 snapshots with only three command blocks.
youtube.com/mottbotminecraft
Is there a version that adds time instead of setting it?
It isn't that simple. If you go to bed right before the sun would be coming up, you wouldn't wake up until it's nearly night again.
You would need to use some math here.
First we will need to setup a scoreboard objective to hold the value of "/time query daytime", type this into chat:
/scoreboard objectives add dayTime dummy
Then we need a command block that will constantly assign the daytime to the scoreboard objective.
Make a repeating command block with this command:
/time query daytime
Then while standing on that command block type this command:
/stats block ~ ~-1 ~ set QueryResult @a dayTime
Now that we have that setup, we can start the real fun.
So lets see, you can start using a bed at 12541 and can no longer use a bed at 23459.
So when the time hits 23459 we will be forced out of bed, so let's setup a scoreboard for this.
Type this into chat:
/scoreboard objectives add wakeTime dummy
Now put this in a repeating command block:
/execute @a[score_Bed_min=0] ~ ~ ~ scoreboard players set @p wakeTime 23459
We are using the original Bed objective so that this command only gets triggered when a player is NOT in a bed.
Now we need to remove the current time from the wakeTime to figure out how much time we need to add. Put this into another repeating command block:
/execute @a[score_Bed_min=1,score_wakeTime_min=23459] ~ ~ ~ scoreboard players operation @p wakeTime -= @p dayTime
And finally we can use these following commands to increase time:
/execute @p[score_Bed_min=1,score_wakeTime_min=10000] ~ ~ ~ time add 10000
/execute @p[score_Bed_min=1,score_wakeTime_min=10000] ~ ~ ~ scoreboard players remove @a wakeTime 10000
/execute @p[score_Bed_min=1,score_wakeTime_min=1000] ~ ~ ~ time add 1000
/execute @p[score_Bed_min=1,score_wakeTime_min=1000] ~ ~ ~ scoreboard players remove @a wakeTime 1000
/execute @p[score_Bed_min=1,score_wakeTime_min=100] ~ ~ ~ time add 100
/execute @p[score_Bed_min=1,score_wakeTime_min=100] ~ ~ ~ scoreboard players remove @a wakeTime 100
/execute @p[score_Bed_min=1,score_wakeTime_min=10] ~ ~ ~ time add 10
/execute @p[score_Bed_min=1,score_wakeTime_min=10] ~ ~ ~ scoreboard players remove @a wakeTime 10
/execute @p[score_Bed_min=1,score_wakeTime_min=1] ~ ~ ~ scoreboard players remove @a wakeTime 1
/scoreboard players set @a[score_wakeTime=1] Bed 0
The reason for not adding 1 in the last set is because each tick already adds 1 to time, so we need to remove one from the score, otherwise we will be going past 23459.
Now that should be everything to make this work perfectly. Of course, it won't be quite as instantaneous when you get into a bed, but it shouldn't take more than one second.
Yea, time add is a good one to use because it doesn't reset local difficulty :-)
youtube.com/mottbotminecraft
Thank you for your replies, I have already reverse-engineered this myself.
I'm using time add 200, and this doesn't seem to skip past sunrise much.
So my recipe (for the sake of those who will come to this thread later) is like this:
Command: /scoreboard objectives add Sleep dummy
Disable command block output in chat, because it will be spammy: /gamerule commandBlockOutput false
You also might want to disable it in the server logs: /gamerule logAdminCommands false
Command for the command block: scoreboard players add @a Sleep 1 {Sleeping:1b}
Command for the block: scoreboard players test @a Sleep 120
Command for the block: time add 200
It will be similar to step 3, except you will need a larger Sleep score to test for. The bigger value you test for, the longer it will take for the contraption to register that player has stayed in bed for too long. As before, 1 second is 20 game ticks.
Command for the block: scoreboard players test @a Sleep 180
Command for the block: weather rain 30
Command for the block: scoreboard players set @a Sleep 0 {Sleeping:0b}
This one os the most spammy, as it will be running constantly when all players are ouf ot the bed, flooding the server log with messages.
As you can see, this one doesn't announce that a player is sleeping. It's kinda enough for me, but I guess it'd be possible with some additional circuitry.
My idea is following:
if you find a player with Sleep objective set exactly to 1 (by means of scoreboard players test @a Sleep 1 1), use /tellraw command to say that someone is sleeping. It will only match a player on the very first tick of the sleep, so the message won't be repeated until the player gets out of the bed and their Sleep score is nullified.
Alternatively, you can use /execute to make that player say they are sleeping.
Wow! Super detailed, well done!!
youtube.com/mottbotminecraft
Why does the command for step 7 need to be separate from the others? If it's unconditional it won't be affected by the other commands running.
Out of curiousity.. How did you manage to calculate a number like that within one tick?
Just putting a bit of emphasis on it. When I was building this contraption, I used pick block key on conditional block, and forgot to change it, leadign to a bit of wtf moment later.
So I'm just making sure. =D
How do you get current time, and how do you round it up to next 24000?
Now that's some voodoo here... what's with all the missing values? I mean, x y z are supposed to be coords, and data value is supposed to be a number, right? And then there is <selector> and <objective> which I have no idea about.
As for my second question, time goes past 24000 because now there is such thing as local difficulty that changes as days go by. As such, setting the time to value below 24000 means resetting the difficulty to the first day. Does /time query daytime give you the correct number (dawn of the next day, not the first day)?
/time query daytime is basically total time % 24000. Meaning if the time is 24000 it will return 0, if the time is less than 24000 it will return the time, and if it is greater than 24000 it will return the remainder of time / 24000. For example, time is 881280, that means 36 days have passed and the current time of the 37th day is 17280. /time query daytime will return 17280.
Xisuma posted a guide to make a rather advanced system for solo sleeping. Features include thunderstorm detection, player notification, and ability to kick players out of the bed if you want the night to stay.
Preparation commands (underscored are things you can rename to your liking):
/scoreboard objectives add sleep dummy
/scoreboard objectives add KickBed trigger
/gamerule commandBlockOutput false
/gamerule logAdminCommands false
Command blocks (unmarked ones and A blocks are repeat/unconditional/always active, B & C blocks are chain/conditional/always active):
1A) scoreboard players add @a sleep 1 {Sleeping:1b}
1B) scoreboard players enable @a KickBed
2) execute @a[score_sleep_min=1,score_sleep=1] ~ ~ ~ tellraw @a ["",{"selector":"@p"},{"text":" is now sleeping","color":"white","clickEvent":{"action":"run_command","value":"/trigger KickBed set 1"},"hoverEvent":{"action":"show_text","value":{"text":"","extra":[{"text":"Click to kick!","color":"red"}]}}}]
3A) scoreboard players set @a[score_sleep_min=1] sleep 0 {Sleeping:0b}
3B) execute @a[score_sleep_min=0] ~ ~ ~ /trigger KickBed set 0
4) execute @p[score_sleep_min=110] ~ ~ ~ /time add 100
5) execute @p[score_sleep_min=230] ~ ~ ~ /weather thunder 1
6A) execute @a[score_sleep_min=1] ~ ~ ~ testfor @a[score_KickBed_min=1]
6B) execute @a[score_sleep_min=1] ~ ~ ~ summon Snowball ~ ~2 ~
6C) scoreboard players set @a KickBed 0
Explanation: