Sleeping (or Sleep Mode) is a game mechanic which is able to be activated by the players under certain circumstances. Usually, sleeping in a bed will cause a player’s vision to fade to black, followed by them regaining consciousness at dawn.
You have to know that sleeping is only possible by meeting the following criteria:
- It must be either nighttime or during a thunderstorm in the daytime.
- The bed is only able to be in the overworld.
- There should be no hostile mobs nearby.
- All players within the Minecraft have to be lying in a bed too. If in a multiplayer situation, in order to skip to daytime.
- There are data packs which require only one player to sleep in a bed in order for the server to skip to the day.
- There is only one player who can sleep in each bed at a time.
By the way, can you sleep in the End? For your information, the End is an alternate dimension which is inhabited by Endermen and the Ender Dragon. To find out that information, just continue to read the following text.
Sleeping in a bed is possible only in the Overworld. Attempting to use a bed in the End and Nether causes it to explode and set fire to surrounding blocks. Also, a bed explodes if used in any nether biome. The explosion has power five which is stronger than TNT, but not as strong as a charged creeper or end crystal. The Villagers are able to sleep normally in any dimension. So, we are able to say that you cannot sleep in the End. If you try to sleep in the End or Nether, the bed will explodes. This is a reference to a line from Suicidal Thoughts Big.
As a player, you have to be close to the bed to sleep. If you are close enough to click on the bed, but not close enough to sleep in it, so you are going to get a message which say that you cannot rest now because the bed is too far away. While if you have not entered a bed for 3 in-game days, the phantoms can spawn unless the gamerule doInsomnia is set to false. Aside from that, you also cannot sleep in a bed occupied by another player. Also, you cannot sleep while on fire, while poisoned, or while starving.
However, you are able to sleep in a bed being used by a villager. You may first wake the villager (pressing use on the villager) and then quickly enter the bed before the villager is able to lie down again. The villager reclaims the bed after the player wakes. The villager is kicked out of its bed when a player attempts to sleep there.
When all players in a world are asleep, after 5 seconds, the time of day changes to sunrise. During this time, the chat window is focused, and you are able to leave the bed by clicking the Leave Bed button.