[PR #6897] [MERGED] Native mods: the time players wake at after sleeping (SleepFinishedTimeEvent) #7178

Closed
opened 2026-11-03 06:35:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6897
Author: @levzzz5154
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: native/sleep-finished-time


📝 Commits (3)

  • a97ef0a Native mods: the time players wake at after sleeping (native_sleep_finished_time)
  • 52a4b74 Native sleep hook: document the after-all-mods check and the weather reset
  • 0c646c7 Merge branch 'main' into native/sleep-finished-time

📊 Changes

5 files changed (+95 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+8 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+23 -0)
📝 crates/horizon-client/src/mod_api/generated.rs (+42 -0)
📝 docs/native-mods.md (+6 -0)
➕ tools/native-hook-fragments/sleep_finished_time.json (+16 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally.

Part of #4953: NeoForge's SleepFinishedTimeEvent.

What

New native hook native_sleep_finished_time(dimension, current, new_time: &mut i64), side server, contract listen.

When enough players have slept and the advance_time rule is on, tick_sleep (vanilla ServerLevel.tick, which moves the clock to wake_up_from_sleep) calls the hook with new_time set to the next morning. A mod may set another time, and everyone wakes at that time. As with NeoForge's setTimeAddition, a time before current is refused and the morning stays. The hook runs before the existing native_time_skip, which hears the jump to the chosen time and can still cancel it. Players wake and the weather resets as usual in every case.

Fires on the server thread (single player), the LAN host and the dedicated server, once per level that sleeps through the night.

Difference from NeoForge (documented): NeoForge refuses a bad value as soon as a mod sets it. Here the check runs once, after every mod, so a later mod sees the value an earlier mod left.

Files: game.rs (tick_sleep), game/native_hooks.rs, the fragment tools/native-hook-fragments/sleep_finished_time.json, the regenerated mod_api/generated.rs (cargo run -p xtask -- mod-api), docs/native-mods.md.

Tests

  • Real game, server thread and dedicated server, using a throwaway trait mod (not committed) driven by horizon-ctl in a private nested KWin. On the first sleep the mod set new_time = current + 1000. On the second sleep it set current - 100. Measured time_of_day values:
    • single player (server thread): before 13006, after the first sleep 14168 (the mod's 14106 plus the ticks until the read), after the second 62 (refused → next morning). PASS
    • dedicated server: 13005 → 14167 → 62. PASS
    • Hook log: sleep n=0 current=13106 offered=24000 set=14106, then time_skip from=13106 to=14106 cause=sleep. On the refused sleep: time_skip from=14268 to=24000.
  • python3 tools/pr_ready.py --quick --base hr/main: rustfmt, clippy, 2030 horizon-client/-lib tests and the mod API check all pass. Python tests had one failure, test_world_input_capture, which fails on main too and is fixed in #6894.
  • Independent Opus review found no blocking problems. Its three low-severity notes (the after-all-mods check, weather wording, the "Bundles need" docs line) are fixed in the second commit.

Not run: parity harnesses (--quick; CI's parity job picks the affected ones).

🤖 Generated with Claude Code


🔄 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/6897 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `native/sleep-finished-time` --- ### 📝 Commits (3) - [`a97ef0a`](https://github.com/horizon-rust/horizon/commit/a97ef0aaa458fb8dfffb6fb020c9b243242f467b) Native mods: the time players wake at after sleeping (native_sleep_finished_time) - [`52a4b74`](https://github.com/horizon-rust/horizon/commit/52a4b747f5803c1689a03c87343df8c8d88255ce) Native sleep hook: document the after-all-mods check and the weather reset - [`0c646c7`](https://github.com/horizon-rust/horizon/commit/0c646c7f8ea909ecb2e8c52134541496513b4105) Merge branch 'main' into native/sleep-finished-time ### 📊 Changes **5 files changed** (+95 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+8 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+23 -0) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+42 -0) 📝 `docs/native-mods.md` (+6 -0) ➕ `tools/native-hook-fragments/sleep_finished_time.json` (+16 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Opus 5.5), not by levzzz5154 personally. Part of #4953: NeoForge's `SleepFinishedTimeEvent`. ## What New native hook `native_sleep_finished_time(dimension, current, new_time: &mut i64)`, side server, contract `listen`. When enough players have slept and the `advance_time` rule is on, `tick_sleep` (vanilla `ServerLevel.tick`, which moves the clock to `wake_up_from_sleep`) calls the hook with `new_time` set to the next morning. A mod may set another time, and everyone wakes at that time. As with NeoForge's `setTimeAddition`, a time before `current` is refused and the morning stays. The hook runs before the existing `native_time_skip`, which hears the jump to the chosen time and can still cancel it. Players wake and the weather resets as usual in every case. Fires on the server thread (single player), the LAN host and the dedicated server, once per level that sleeps through the night. Difference from NeoForge (documented): NeoForge refuses a bad value as soon as a mod sets it. Here the check runs once, after every mod, so a later mod sees the value an earlier mod left. Files: `game.rs` (`tick_sleep`), `game/native_hooks.rs`, the fragment `tools/native-hook-fragments/sleep_finished_time.json`, the regenerated `mod_api/generated.rs` (`cargo run -p xtask -- mod-api`), `docs/native-mods.md`. ## Tests - **Real game, server thread and dedicated server**, using a throwaway trait mod (not committed) driven by horizon-ctl in a private nested KWin. On the first sleep the mod set `new_time = current + 1000`. On the second sleep it set `current - 100`. Measured `time_of_day` values: - single player (server thread): before 13006, after the first sleep **14168** (the mod's 14106 plus the ticks until the read), after the second **62** (refused → next morning). PASS - dedicated server: 13005 → **14167** → **62**. PASS - Hook log: `sleep n=0 current=13106 offered=24000 set=14106`, then `time_skip from=13106 to=14106 cause=sleep`. On the refused sleep: `time_skip from=14268 to=24000`. - `python3 tools/pr_ready.py --quick --base hr/main`: rustfmt, clippy, 2030 horizon-client/-lib tests and the mod API check all pass. Python tests had one failure, `test_world_input_capture`, which fails on main too and is fixed in #6894. - Independent Opus review found no blocking problems. Its three low-severity notes (the after-all-mods check, weather wording, the "Bundles need" docs line) are fixed in the second commit. Not run: parity harnesses (`--quick`; CI's parity job picks the affected ones). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:35:18 +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#7178
No description provided.