[PR #3722] [MERGED] fix: sleep only when it is dark outside, not whenever the thunder flag is set #5170

Closed
opened 2026-11-03 05:10:44 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3722
Author: @vvnikita74
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @ludovic111

Base: main ← Head: fix/no-day-sleep-thunder-flag


📝 Commits (1)

  • c5a734e fix: sleep only when it is dark outside, not whenever the thunder flag is set (#3709)

📊 Changes

2 files changed (+40 additions, -10 deletions)

View changed files

📝 crates/horizon-client-render/src/environment.rs (+33 -0)
📝 crates/horizon-client/src/game.rs (+7 -10)

📄 Description

Fixes #3709.

What was wrong

try_sleep allowed sleeping when (12542..23460).contains(&time) || self.world.weather.thundering. weather.thundering is the level's raw thunder flag: its timer runs in clear weather too (Weather::tick_timers), so whenever the flag was on, players could sleep through a sunny day.

Fix

Vanilla 26.3: the Overworld's bed_rule has can_sleep: when_dark, and BedRule.Rule.WHEN_DARK tests Level.isDarkOutside(), i.e. !hasFixedTime && skyDarken >= 4. skyDarken comes from the time of day and the rain and thunder levels (thunder scaled by rain), not from the flags.

  • horizon_client::environment::sky_darken(environment, day_time, rain, thunder): the existing Level.updateSkyBrightness computation from Game::sky_darken, moved into a function so it can be tested; Game::sky_darken calls it.
  • try_sleep: sleeping needs self.dim == Dim::Overworld && self.sky_darken() >= 4 (the Nether's and the End's beds explode before this point).

Testing

  • New unit test environment::tests::dark_outside_follows_time_and_weather_levels: clear and rainy noon are bright, a thunderstorm at noon and clear midnight are dark.
  • In game, survival, both single-player paths (server thread and --in-frame), driven with horizon-ctl: at clear noon the bed refuses; after /weather thunder (once the thunder level is up) and at midnight the player sleeps.

pr_ready

(Scope also counts two untracked local backup files; the PR itself is 2 files, +40 −10.)

pr_ready (tools/pr_ready.py --quick on nvonzhulov, against origin/main at 57d4801bf, 4 min 37 s)

Check Result
Scope ✅ 4 files, +257 −10
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 416 passed (32 s)
rustfmt ✅ (6 s)
clippy ✅ (43 s)
tests: horizon-client, horizon-client-render ✅ 1356 passed (2 min 31 s)
doc tests ✅ 0 passed (44 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3722 **Author:** [@vvnikita74](https://github.com/vvnikita74) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/no-day-sleep-thunder-flag` --- ### 📝 Commits (1) - [`c5a734e`](https://github.com/horizon-rust/horizon/commit/c5a734eace95988c892682cfddcc0ee7bf9ef1d1) fix: sleep only when it is dark outside, not whenever the thunder flag is set (#3709) ### 📊 Changes **2 files changed** (+40 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/environment.rs` (+33 -0) 📝 `crates/horizon-client/src/game.rs` (+7 -10) </details> ### 📄 Description Fixes #3709. ## What was wrong `try_sleep` allowed sleeping when `(12542..23460).contains(&time) || self.world.weather.thundering`. `weather.thundering` is the level's raw thunder flag: its timer runs in clear weather too (`Weather::tick_timers`), so whenever the flag was on, players could sleep through a sunny day. ## Fix Vanilla 26.3: the Overworld's `bed_rule` has `can_sleep: when_dark`, and `BedRule.Rule.WHEN_DARK` tests `Level.isDarkOutside()`, i.e. `!hasFixedTime && skyDarken >= 4`. `skyDarken` comes from the time of day and the rain and thunder *levels* (thunder scaled by rain), not from the flags. - `horizon_client::environment::sky_darken(environment, day_time, rain, thunder)`: the existing `Level.updateSkyBrightness` computation from `Game::sky_darken`, moved into a function so it can be tested; `Game::sky_darken` calls it. - `try_sleep`: sleeping needs `self.dim == Dim::Overworld && self.sky_darken() >= 4` (the Nether's and the End's beds explode before this point). ## Testing - New unit test `environment::tests::dark_outside_follows_time_and_weather_levels`: clear and rainy noon are bright, a thunderstorm at noon and clear midnight are dark. - In game, survival, both single-player paths (server thread and `--in-frame`), driven with `horizon-ctl`: at clear noon the bed refuses; after `/weather thunder` (once the thunder level is up) and at midnight the player sleeps. ## pr_ready (Scope also counts two untracked local backup files; the PR itself is 2 files, +40 −10.) **pr_ready** (`tools/pr_ready.py --quick` on nvonzhulov, against origin/main at 57d4801bf, 4 min 37 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +257 −10 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 416 passed (32 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (43 s) | | tests: horizon-client, horizon-client-render | ✅ 1356 passed (2 min 31 s) | | doc tests | ✅ 0 passed (44 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:10:44 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5170
No description provided.