I want to record a timelapse with a villager, but I want to skip the time that he's asleep. What commands chain do I need to do? Please
1 Answer
Setup:
Summon the villager:
/summon minecraft:villager ~ ~ ~ {CustomName:"{\"text\":\"Josh\"}"}
Then I set up a scoreboard to keep track of his sleep:
/scoreboard objectives add Josh dummy
Commands:
I will place this command in a stand-alone repeating command block:
execute as @e[nbt={CustomName:"{\"text\":\"Josh\"}"}] store result score @s Josh run data get entity @s Brain.memories.minecraft:last_slept.value 1
This will grab his last_slept
data, I don't actually know what it means but every time he jumps into the bed it is set to a number.
The next command in a repeating command block will then set the time right before dawn:
execute if score @e[nbt={CustomName:"{\"text\":\"Josh\"}"},limit=1] Josh matches 1.. run time set 23970t
You could also set it to 24000t
but then Josh would just jump out of bed right away.
This next command will be placed in a chain command block and reset his last_slept
value:
execute as @e[nbt={CustomName:"{\"text\":\"Josh\"}"}] if score @s Josh matches 1.. run data modify entity @s Brain.memories.minecraft:last_slept.value set value 0
Additional:
If you wouldn't like to skip the night that fast you could set up a scoreboard that starts increasing when Josh gets in bed. Then set up commands that track the scoreboard in intervals so you could speed thru the night instead of just skipping it.
Something like this:
Repeating command block
execute if score @e[nbt={CustomName:"{\"text\":\"Josh\"}"}] Josh matches 1.. run scoreboard players add <Name> <Score> 1
You could use any player name or entity, like Josh himself, or set a fake player by just entering anything for the <Name>
.
Then set up a few commands to add time in intervals:
execute if score <Name> <Score> matches 100..100 run time add 1000t
This would add 1000 to the time when the score has reached 100. In a repeating command block that would be after 5 seconds. And then add however many you'd like depending on how fast/smooth you'd like it to be.
You would then also change the previous command in the chain command block to execute whenever the new <Score>
have reached the highest number, which you would choose, so it would properly reset the data of Josh:
execute if score <Name> <Score> matches num..num run data modify entity @e[nbt={CustomName:"{\"text\":\"Josh\"}"},limit=1] Brain.memories.minecraft:last_slept.value set value 0
Then you'd also need to reset your increasing score with a similar command, but make sure to do that after you set Josh's data to 0, otherwise it might increase a bit until Josh's data has been reset.
Could be placed in a chain command block after the last command:
execute if score <Name> <Score> matches num..num run scoreboard players set <Name> <Score> 0
And because Josh's data value got set to 0 the score won't start increasing until he goes to bed.