how do I trigger a /setblock command without a /testfor?

In my map, the player goes to sleep, then wakes up and finds the windows are changed from regular panes to red ones stained with blood. But if I do /testfor
, it will trigger whenever the player passes by, so that is not useful in this circumstance. Is there a way to trigger a command block when you wake up?
Best Answer
You can still use testfor. Here's how it works - set up the device as you would with the testfor, but change the testfor to this command.
/testfor @a {Sleeping:1b}
Pictures about "how do I trigger a /setblock command without a /testfor?"



What is the command for Setblock in Minecraft?
How to Enter the CommandWhat replaced the Testfor command in Minecraft?
The /testfor command became obsolete in Minecraft 1.13, and has been replaced by the /execute command*. It will do the same as typing /testfor @e {SelectedItem:{id:"<item>"}} and then putting a comparator to the command block with the command, and then running the command which you wanna run.How do you activate a repeating command block?
To get a repeating command block, players must use the /give command like so: /give @p minecraft:repeating_command_block <amount> . Players can also change a normal command block into a repeating command block by selecting the option in the command block GUI.Minecraft Execute Command [1.19] Tutorial
More answers regarding how do I trigger a /setblock command without a /testfor?
Answer 2
You'll either have to trigger something with redstone or use the /testfor command.
I would recommend testing for the exact block the player stands on when they wake up, as well as the exact time Minecraft warps to when the player wakes up. Realistically that would only occur is if they sleep in the specified bed you want them to.
Another thing you could try is testing for whether the bed is occupied or not:
/testforblock <x> <y> <z> minecraft:bed -1 {occupied:true}
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Ivan Babydov, Ivan Babydov, Anete Lusina, Andrea Piacquadio