Somnia

Somnia completely changes how sleeping works in Minecraft. It has been included in YogBox (with permission) and mentioned in PCGamer, which is pretty sweet.
Updated version: http://www.minecraftforum.net/topic/1938500-164forgesmp-somnia-simulating-the-world-while-you-sleep
Changelog:
* v24 [1.2.5] - Released Apr 15, 2012
** Added configuration option that controls which difficulties prevent you from sleeping in armor.
* v23 [1.2.5] - Released Apr 03, 2012
** Updated for Client 1.2.5.
** Adjusted hunger while sleeping so saturation is taken into account.
** Added configuration option that controls which world IDs allow sleep. (Doesn't work. Sorry!)
* v22 [1.2.4] - Released Mar 26, 2012
** Updated for Client 1.2.4.
** Added support for Zombe's mod pack. (Please report any problems.)
** Fixed flashing heart sprites when first sleeping.
* v21 [1.2.3] - Released Mar 10, 2012
** Move player outside of the Bed block on waking.
** Display health and food bars while sleeping.
** On Hard difficulty, you can't sleep in armor.
* v20 [1.2.3] - Download (adfly) - Released Mar 04, 2012
** Updated for Client 1.2.3.
** Added configuration options which control visibility of "Reset Spawn" button and its default value.
* v19 [1.1.0] - Download - Released Feb 05, 2012
** Fixed an issue where blocks that broke while asleep accumulated particles and caused lag after waking.
** Optimizations for slightly faster simulation.
** Corrected calculation of speed multiplier. Note: the simulation is not any slower than before (in fact it's a bit faster), but you will see your multiplier drop because it was calculated incorrectly.
* v18 [1.1.0] - Released Jan 14, 2012
** Updated for Client 1.1.0.
** Added an estimate of how much real-world time is left in the simulation.
** Combined ModLoader and Minecraft Forge versions into a single ZIP. The only difference is how they are installed.
* v17 [1.0.0]
** ModLoader version - Released Nov 26, 2011
** Minecraft Forge version - Released Dec 01, 2011
** Changes:
*** Updated for Client 1.0.0.
* v16 [b1.9pre5]
** ModLoader version - Released Nov 05, 2011
** Changes:
*** Updated for Client Beta 1.9 prerelease 5.
* v15 [b1.8.1]
** ModLoader version - Released Oct 04, 2011
** Minecraft Forge version - Released Oct 04, 2011
** Changes:
*** When sleeping with a clock in-hand, hovering over the buttons displays the exact time.
*** Added Minecraft Forge support (a separate download) for easier installation and improved compatibility.
*** Dropped support for TFC Mod Manager.
* v14 [b1.8.1] - Released Sep 18, 2011
** Updated for Client Beta 1.8.1. (Note: Performance across the board took a huge hit in Minecraft 1.8, and the simulation speed suffers as a result.)
** You grow hungry when sleeping. The rate varies based on the difficulty and whether or not you are at full health.
** Increased healing rates while sleeping to account for the new hunger mechanics. Delete your .minecraft/config/Somnia.cfg file to reset to the new defaults.
** Displays simulation speed while sleeping.
* v13 [b1.7.3] - Released Aug 21, 2011
** No more crashes when using Dynamic Lights. Really!
** If you are using The Seasons Mod, seasons will advance while you sleep.
** Lots of other small fixes and prep work for using Minecraft Forge.
* v12 [b1.7.3] - Released Aug 05, 2011
** Healing rates are now customizable per difficulty. See the Configuration section.
* v11 [b1.7.3] - Released Jul 09, 2011
** Updated for Client Beta 1.7.3.
* v10 [b1.7.2] - Released Jul 07, 2011
** Updated for Client Beta 1.7.2.
** Now compatible with Dynamic Lights. I am a dirty liar. See v13.
** Difficulty setting affects healing rate:
*** Easy - heals half a heart per "hour"
*** Normal - heals half a heart per 2 "hours"
*** Hard - no healing
** Improved performance by disabling auto-save while sleeping.
* v9 [b1.6.6] - Download - Released May 31, 2011
** Updated for Client Beta 1.6.6.
* v8 [b1.6.5] - Download - Released May 30, 2011
** Updated for Client Beta 1.6.5.
* v7 [b1.5_01] - Download - Released May 10, 2011
** Fixed an issue with non-solid items (e.g. torches) above the head of the bed preventing sleep.
* v6 [b1.5_01] - Download - Released Apr 30, 2011
** Updated for Client Beta 1.5_01.
** Optionally set spawn point.
** Clock item must be in-hand (not just in your hotbar) to get advanced sleep options.
** Minor UI adjustments and fixes.
* v5 [b1.4] - Download - Released Apr 03, 2011
** Updated for Client Beta 1.4. (Also works in Client Beta 1.4_01.)
** Synergizes with Clock item. Try sleeping with a Clock in your hotbar to have more control over when you wake.
* v4 [b1.3_01] - Download - Released Mar 23, 2011
** Fixed a bug where people were falling through the floor and/or getting stuck inside blocks when being moved onto the bed.
** Fixed a bug where removing blocks under the bed allowed people who fell through to sleep under the bed.
** Fixed a bug where hurt/death sounds did not play for damage taken while sleeping.
** Only sets spawn point if there is room above the bed to spawn. Warns if spawn point was not set.
** Adjusted dawn/dusk times so you wake during the transition.
* v3 [b1.3_01] - Download - Released Mar 21, 2011
** Sleeping sets your spawn point to the bed. (Already planned for Client Beta 1.4, but it's nice to have it early.)
** Player is moved to bed while sleeping.
** Compatible with TFC Mod Manager.
** Simultaneously compatible with ModLoader 1.3_01v4 and 1.3_01v5.
* v2 [b1.3_01] - Download - Released Mar 05, 2011
** Compatible with ModLoader 1.3_01v5 (but not 1.3_01v4).
* v1 [b1.3_01] - Download - Released Feb 28, 2011
** Updated for Client Beta 1.3_01.
** Removed custom bed block (id=100). Uses Minecraft's native bed. This should resolve most incompatibilities with other mods. Before upgrading, destroy all Somnia bed blocks using lava or by dropping them and letting them decay.
** Removed custom recipe. Uses Minecraft's native bed recipe.
* v0 [b1.2_01] (previously "v1.0") - Download - Released Feb 19, 2011
** Initial release.
Features:
Simulates the world: While you're sleeping, the world continues as if you are standing idle the whole time. Crops and trees will grow, smelting continues, weather progresses, mobs are active (even mobs added by other mods), and dropped items decay. You also heal an amount based on how long you've spent sleeping and the difficulty setting, but you'll also grow hungry. The simulation will take a few moments.
No sleep-triggered monster spawns: Monsters spawn normally and may still attack you in your sleep, but only if they can actually reach you. No more worrying if your bed is in an "unsafe" location. If you'd be safe while awake, you'll be safe while asleep.
Sleep/wake at any time: Sleep any time, day or night. Wake automatically at the next dawn/dusk or manually at any time. If you have a Clock item in your hand, you can choose when you wake from among 16 options throughout the day.
Control your spawn point: Before you sleep, you can choose whether or not sleeping will reset your spawn point.
Maximum compatibility: This mod doesn't add any new Block or Item IDs. It just changes the behavior of the native bed. It will not corrupt your save files, and it is compatible with most other mods. It also disables itself in multiplayer.
Configuration
The first time you run Minecraft with Somnia installed, a file called mod_Somnia.cfg will appear in your .minecraft/config directory. If you want to change any of the options, open this file in a text editor. I have described each property below. To reset to the defaults, make sure Minecraft is closed, delete the file, and restart Minecraft.
* heal.easy - The heal rate, in hearts-per-hour, while sleeping on Easy difficulty.
* heal.normal - The heal rate, in hearts-per-hour, while sleeping on Normal difficulty.
* heal.hard - The heal rate, in hearts-per-hour, while sleeping on Hard difficulty.
* hunger.easy - The hunger rate, in foods-per-hour, while sleeping on Easy difficulty.
* hunger.normal - The hunger rate, in foods-per-hour, while sleeping on Normal difficulty.
* hunger.hard - The hunger rate, in foods-per-hour, while sleeping on Hard difficulty.
* respawn.default - Controls the default value of the "Reset Spawn" button.
* respawn.visible - Controls whether the "Reset Spawn" button is visible.
* valid.worlds - Comma-separated list of world IDs that allow sleep. Normal = 0; Nether = -1; End = 1. (Doesn't work yet. Sorry!)
* armor.difficulty - Minimum difficulty where armor must be taken off to sleep. 0 = Peaceful, 1 = Easy, 2 = Normal, 3 = Hard, 4 = Hardcore, 5 = Disabled.
Mod Packs Featuring Somnia
The following mod compilations include Somnia (with permission). I won't allow any new mod packs to include Somnia--there are just too many--so please don't ask.
* 3CH0S_PACK
* AMCO
* Boyko's Basic Pack
* CharityCraft
* CinemaPack
* EpcPack
* Facepunch Compilation Pack
* HonorPack
* A Lazy Install
* MCMMP Mod Pack
* Modern Pack
* Mo'Fun Mod Pack
* NowCraft
* Technic Pack
* YogBox
* ZakPack
Mod Compatibility
This mod does not add any new block IDs, so you can safely begin using it in an existing world, and it will not corrupt your world if you remove it. If you are using ModLoader and install it into minecraft.jar, the only core file it changes is the Bed block, so it should be compatible with most other mods. If you are using Minecraft Forge, it should be compatible with any Forge mod.
Some compatibility questions involving specific mods have come up in the past, so I have addressed them here:
* Better Than Wolves: Sleeping while a machine destroyed blocks caused an accumulation of particles in v18 and earlier which lagged the game. This is fixed in v19 and later.
* Dynamic Lights: Sleeping while using Somnia v9 v12 and earlier will cause crashes, but I've fixed that in v10 v13 and later.
* HD Textures: As with many mods, it may be tricky to get Somnia working with HD textures, but it is possible.
* Millenaire: Does work with Somnia, despite some perceptions. The townsfolk don't build at night, but they do make babies.
** Sometimes the game freezes up while sleeping and displays the message "Saving chunks." A look at ModLoader.txt reveals a ConcurrentModificationException. Other players using Millenaire have had the same problem while awake, so it's not an issue with Somnia.
* MoreBeds+ (outdated): The creator of this mod was kind enough to modify it so it would be compatible with Somnia.
* The Seasons Mod: When using Somnia v12 and earlier, seasons did not correctly advance when you slept. This is fixed in v13 and later.
Known Issues
* Can take a rather long time to simulate, especially if you have a slow machine. This is likely why Mojang chose to implement sleep the way they did.
** Update: v10 (and higher) contains an optimization that improves performance. If you're recording with FRAPS, sleeping should be much faster.
** Update 2: This was adjusted further in v13. Autosave is completely disabled while sleeping.
** Update 3: Performance across the board took a huge hit in Minecraft 1.8, and the simulation speed suffers as a result.
** Update 4: Performance has improved in 1.9pre5, so I've removed the benchmarking poll for now. I will add it back later.
* Does not work with some parts of the Doggy Talents mod. Its developer has added a workaround, but we're working to find a better solution.
FAQ
Q: Why does the simulation take so long?
A: The simulation is a lot of number-crunching, so if you have a slow processor or are running intensive processes in the background (like frapps), it's going to take longer. There are also some design choices made by Minecraft's developers that make it impossible for me to optimize. Minecraft's code mixes graphics with logic in several places, so the simulation performs some unnecessary graphics-related operations that can't be skipped.
A number of users have reported a 10-20x speed decrease while running frapps. If you're recording a video, best to suspend recording before you sleep.
Q: Can you add a way to sleep "normally" where the simulation doesn't run?
A: This mod is more about realism than utility. An option for the "normal" bed behavior would defeat the purpose. If you want to disable the mod without uninstalling it, open .minecraft/config/ModLoader.cfg with a text editor and set mod_Somnia=off.
Q: How does Somnia work? If I'm a developer, how do I make sure my mod simulates correctly?
A: It's too complicated to explain in one or two paragraphs. Expand the spoiler for details.
Minecraft's world progresses using a series of ticks. There are 24,000 ticks in one Minecraft day. One day in Minecraft is also 10 real-world minutes. This means there are 2400 ticks per minute or 40 ticks per second.
During a tick, Minecraft does a number of things:
* Tracks player stats.
* Updates GUI overlay (scrolls chat text, animates health/hunger bars when low).
* Updates dynamic textures (like lava and water).
* Accepts and processes user input (mouse/keyboard).
* Updates the renderer (fog, lighting).
* Moves the clouds.
* Updates entities (furnaces, crops, mobs...)
* Progresses weather.
* Spawns mobs.
* Saves world data to disk (occasionally).
* Advance the world time.
* Update blocks (flowing lava/water, falling sand, hydrated soil).
* Creates particles (smoke, torch/furnace flames, redstone sparks).
* Animates and removes particles.
* Triggers tick behavior for ModLoader mods.
* Pauses until the next tick if all of the above takes less than 1/40 of a second. (Note: If it takes more time than that, you experience lag.)
Somnia works by doing some of these things (in blue above) while you sleep. It skips most of the graphics operations because you can't see anything while you're sleeping (and because they slow things down).
For developers, here's the breakdown:
 beforeSleep(); //Mutes sounds, turns down graphics settings, disables world auto-save.
 while (sleeping()) {
 if (ticksElapsed % 10 == 0) {
 mc.effectRenderer.clearEffects(); //Remove all particles to avoid accumulation.
 }
 mc.renderGlobal.updateClouds(); //Move the clouds.
 world.updateEntities(); //Update entities (furnaces, crops, mobs...)
 world.tick(); //Progress weather, spawn mobs, tick++, update blocks.
 ModLoader.OnTick(0, mc); //Update other ModLoader mods.
 resetDynamicLights(); //Special handler for compatibility with Dynamic Lights mod.
 }
 afterSleep(); //Restores sounds, restores graphics settings, enables world auto-save.
If you are adding new content, Somnia will simulate behavior in the following methods:
* Entity.onUpdate()
* Block.updateTick()
* Mod.OnTickInGame()
The following methods are not called during the simulation:
* Block.randomDisplayTick()
* EntityFX.onUpdate()
Q: How did you come up with the idea?
A: I was interested in creating a mod (my first), so I asked a friend of mine for ideas. This was back in Beta 1.2, before there were beds at all, and he wanted a way to skip the night so he could focus on building during the day. I wanted to make sure it didn't feel like cheating, which meant preserving the risk involved with sleeping in a world full of monsters. That's where I got the idea of just simulating the world. The monsters are active while you're asleep, so if they can get to you, they will attack you. That put a new emphasis on building a solid home base, which I thought was a cool idea. Simulating the world also meant that things like smelting would continue, which would save us more time. I used this tutorial as a jumping-off point. From there, I found out about MCP and ModLoader.
It wasn't a unique idea, of course. A lot of people had similar ideas, like in this thread. When Notch added beds and sleep in 1.3, I decided to continue developing the mod and to just repurpose his bed, which looked better anyway. (The first version of Somnia added its own bed block.) Most of people's complaints about Minecraft's native sleep are because it seems so artificial. There are these arbitrary rules that don't apply any other time, so it upsets our expectations. Somnia "fixes" these by acting the way real sleep acts -- you're idle and vulnerable for a long time, and the world continues.
For those who have wondered, I didn't really have complaints against native sleep in mind when I created Somnia because at the time, there was no sleep in Minecraft. I just brought forward my own implementation, which some people preferred over the native one.
Development Checklist
Spoiler (click to hide)
Key:
* Completed
* In progress
* Planned
* Tentatively planned
* Stuck/investigating
* Cancelled or removedChecklist:
* Add new bed block. (Replaced by native bed item.)
** Add new texture.
** Make head of bed determined by which block is laid first.
** Vary texture color based on wool color used in recipe. (Use MoreBeds+ - now compatible with Somnia)
* Allow player to interact with "Bed" block.
** Interaction requires two adjacent bed blocks.
** Present a confirmation dialog before putting the player to sleep.
*** Game is not paused when this dialog is visible.
*** Move player onto bed while sleeping, as native bed does.
*** Move player outside of bed block on waking, as native bed does.
*** Can't sleep in armor in Hard difficulty.
**** Configuration option to control this limitation.
*** Configuration option to control what worlds the player can sleep in.
** GUI while sleeping.
*** Blank background.
*** Progress bar.
*** Mute sounds.
*** Disable/tick particle effects to avoid trails of particles on waking.
*** Clear particle effects periodically to avoid accumulation.
*** Allow player to wake voluntarily.
*** Display a speed multiplier so people know how much time they're saving.
*** Display a real-time estimate of how long it will take to simulate the world.
*** Display health/hunger bars.
**** Hide these in Creative mode. - PLANNED
** Time advances up to half a day, to the next dawn/dusk.
** Player heals depending on amount of time spent sleeping.
*** Adjust healing rate based on difficulty setting.
*** Allow player to adjust healing rates in a config file.
** Player grows hungry depending on amount of time spent sleeping.
*** Adjust hunger rate based on difficulty setting.
*** Allow player to adjust hunger rates in a config file.
*** Simulate hunger with higher fidelity to base game.
** The world remains active during sleep.
*** Monsters move and attack.
*** Crops grow.
*** Prevent player movement/actions. No sleepwalking!
*** Make world simulation optional. (Mod can be disabled in ModLoader.cfg file.)
** Sleeping resets spawn point. (Implemented in Beta 1.4)
*** Make resetting your spawn point optional.
*** Add configuration options which control visibility of "Reset Spawn" button and its default value.
*** Disable "Reset Spawn" button in Hardcore or when sleeping in a World that doesn't allow respawns.
*** (SP only) Also reset the world-level spawn point so your compass points to where you last slept. - PLANNED
** Synergize with Clock item.
*** Clock must be in hotbar the active item to work.
*** Display time while sleeping.
*** Operate as alarm clock, allowing more granular sleep duration settings. Add buttons/slider for selecting amount of time spent sleeping.
**** Display actual wake time when hovering over buttons.
*** Display graphical day/night indicator while sleeping (probably just the clock texture).
*** RVW mode - Custom sleep duration (measured in days). - PLANNED
** Take no falling damage if landing on a bed.
*** Bounce slightly if landing on a bed.
*** Jumping on a bed gradually increases jump height, up to a point.
** Optional screen fade effect when sleeping/waking. - PLANNED
** Prevent sleep spam.
** Wake player when a nearby Note block makes noise. (Will require changes to Note block.)
** Wake player when Bed receives Redstone signal.
** Wake player when damage taken.
** Wake player on death.
* Make sleeping more moddable using an event/listener model. (Patch submitted to MCF.)
* Work with ModLoader.
* Work with Minecraft Forge.
* Combine ML/MCF versions into a single distributable.
* Work with MC Patcher.
* Work with Dynamic Lights mod.
* Work with The Seasons Mod.
* Work with Zombe's modpack.
* Work with Doggy Talents mod. - NO
* Work with Xie's Hunger Mod so that you don't grow so hungry while sleeping. (Outdated.)
* Work with Flan's Moods Mod. (Flan's "Hunger" mood now ties directly to the hunger bar.)
* Work with TFC Mod Manager. (No longer supported.)
* Work with Minecraft Mod Manager. (Abandoned.)
* Host downloads on DropBox.
* Work in multiplayer. - NO
** Everyone must activate a bed before the "Yes" button is enabled.
*** Server option: Heal while waiting for other players.
** If any one player clicks "Yes," all players sleep and the server's time is advanced.
** If any one player clicks "Wake" or is damaged/killed, all players wake.
Category:Mods