[PR #482] [MERGED] World Options: difficulty lock with its confirmation, and Restrictions #2598

Closed
opened 2026-11-02 15:57:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/world-options-buttons


📝 Commits (1)

  • e27e556 World Options: the difficulty lock (with its question) and Restrictions

📊 Changes

6 files changed (+417 additions, -29 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+4 -1)
📝 crates/horizon-client/src/game/lan.rs (+2 -2)
📝 crates/horizon-client/src/game/lan_screen.rs (+378 -22)
📝 crates/horizon-client/src/game/options.rs (+3 -1)
📝 crates/horizon-client/src/hud.rs (+20 -0)
📝 crates/horizon-client/src/save.rs (+10 -3)

📄 Description

Part of #464 (Lock and Restrictions; Edit Game Rules comes in its own PR)

What: the World Options screen's Lock and Restrictions buttons now work.

Vanilla 26.3:

  • Lock (WorldOptionsScreen.DifficultyButtons): the LockIconButton toggles wantedDifficultyLocked and shows it. It's active only when the level's difficulty is neither locked nor hardcore (updateDifficultyButtonsState), and so is the difficulty button. A changed lock counts as a change for Apply (hasSettingsChanges). Apply with a new lock opens a PopupScreen ("Lock World Difficulty" / difficulty.lock.question naming the wanted difficulty, Yes / No). Yes applies (ServerboundLockDifficultyPacket(true) → setDifficultyLocked) and returns to the pause menu; No and Escape return to the options with their choices kept (repositionElements doesn't rebuild them).
  • Restrictions (RestrictionsScreen with Minecraft.computeChatAbilities): in a world you host, the only restriction is the Chat option (HIDDEN → chat_and_commands_disabled_by_options, SYSTEM → chat_disabled_by_options), each with its "Go to the Chat Settings screen" action (ChatOptionsScreen whose Done returns to World Options). Then the four permission lines, green or red. Done / Escape return to World Options.

How:

  • save::Level.difficulty_locked reads and writes difficulty_settings.locked. Horizon previously kept whatever was there, but couldn't set it.
  • The LAN tick context now passes the real lock to guests' ChangeDifficulty instead of false.
  • WorldOptions gains the lock state and a View (options / lock question / Restrictions). PopupScreen and RestrictionsScreen are laid out like vanilla (Popup, Restrictions): the popup is 214 wide inside its 18-pixel popup/background border, with 104-wide buttons 6 apart and rows 12 apart, centred. Restrictions puts 250-wide text widgets padded by 4 under the header (+30), in a ScrollableLayout reserving 10 px each side, with a 200-wide Done in the footer.
  • HudBatch::fill_gradient draws Screen.extractTransparentBackground behind the popup.

Verified in game (Mac mini, offscreen, horizon-ctl, new survival world, 1280×720 at GUI scale 3):

  1. World Options: Lock and Restrictions are active. Clicking Lock shows the closed lock and enables Apply Changes.
  2. Apply → the popup appears over the darkened screen: "Lock World Difficulty", the question naming Normal, Yes / No.
  3. No → back to World Options; Difficulty still active, Apply still enabled. Apply → Yes → pause menu. Reopening: Difficulty and the lock are disabled (locked icon).
  4. Quit and relaunch the world: Difficulty still disabled. level.dat has difficulty_settings.locked = 1b.
  5. Restrictions with Chat: Shown lists the four green permissions. Escape returns to World Options.
  6. Chat set to Hidden: the bold red "Chat is restricted in client settings.", the "Go to the Chat Settings screen" button, and four red lines. The button opens Chat Settings, and Done returns to World Options.

Tests: the_lock_follows_the_level_and_counts_as_a_change (new); level_round_trips_through_the_vanilla_files now covers the lock.

Self-check: cargo fmt --check ok; cargo clippy -p horizon-client --all-targets -- -D warnings ok; cargo test -p horizon-client --bin horizon-client -- lan_screen 3 passed; save::tests::level_round_trips_through_the_vanilla_files passes. Workspace clippy, the full client tests and tools/parity.py --changed origin/main run on the combined branch of this batch.

Not covered: tooltips (Horizon's World Options draws none yet). Restrictions doesn't scroll: a world you host has at most one restriction (about 100 px), well within the 174 px area at the smallest GUI height. LAN guests already in the world aren't sent the new lock until they rejoin; the hub sends ChangeDifficulty only at login, for the difficulty too.

🤖 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/482 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/world-options-buttons` --- ### 📝 Commits (1) - [`e27e556`](https://github.com/horizon-rust/horizon/commit/e27e556ab27994d0d397cf8cbf0a03abd423ebc6) World Options: the difficulty lock (with its question) and Restrictions ### 📊 Changes **6 files changed** (+417 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+4 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+2 -2) 📝 `crates/horizon-client/src/game/lan_screen.rs` (+378 -22) 📝 `crates/horizon-client/src/game/options.rs` (+3 -1) 📝 `crates/horizon-client/src/hud.rs` (+20 -0) 📝 `crates/horizon-client/src/save.rs` (+10 -3) </details> ### 📄 Description Part of #464 (Lock and Restrictions; Edit Game Rules comes in its own PR) **What:** the World Options screen's Lock and Restrictions buttons now work. **Vanilla 26.3:** - **Lock** (`WorldOptionsScreen.DifficultyButtons`): the `LockIconButton` toggles `wantedDifficultyLocked` and shows it. It's active only when the level's difficulty is neither locked nor hardcore (`updateDifficultyButtonsState`), and so is the difficulty button. A changed lock counts as a change for Apply (`hasSettingsChanges`). Apply with a new lock opens a `PopupScreen` ("Lock World Difficulty" / `difficulty.lock.question` naming the wanted difficulty, Yes / No). **Yes** applies (`ServerboundLockDifficultyPacket(true)` → `setDifficultyLocked`) and returns to the pause menu; **No** and Escape return to the options with their choices kept (`repositionElements` doesn't rebuild them). - **Restrictions** (`RestrictionsScreen` with `Minecraft.computeChatAbilities`): in a world you host, the only restriction is the Chat option (`HIDDEN` → `chat_and_commands_disabled_by_options`, `SYSTEM` → `chat_disabled_by_options`), each with its "Go to the Chat Settings screen" action (`ChatOptionsScreen` whose Done returns to World Options). Then the four permission lines, green or red. Done / Escape return to World Options. **How:** - `save::Level.difficulty_locked` reads and writes `difficulty_settings.locked`. Horizon previously kept whatever was there, but couldn't set it. - The LAN tick context now passes the real lock to guests' `ChangeDifficulty` instead of `false`. - `WorldOptions` gains the lock state and a `View` (options / lock question / Restrictions). PopupScreen and RestrictionsScreen are laid out like vanilla (`Popup`, `Restrictions`): the popup is 214 wide inside its 18-pixel `popup/background` border, with 104-wide buttons 6 apart and rows 12 apart, centred. Restrictions puts 250-wide text widgets padded by 4 under the header (+30), in a ScrollableLayout reserving 10 px each side, with a 200-wide Done in the footer. - `HudBatch::fill_gradient` draws `Screen.extractTransparentBackground` behind the popup. **Verified in game** (Mac mini, offscreen, `horizon-ctl`, new survival world, 1280×720 at GUI scale 3): 1. World Options: Lock and Restrictions are active. Clicking Lock shows the closed lock and enables Apply Changes. 2. Apply → the popup appears over the darkened screen: "Lock World Difficulty", the question naming Normal, Yes / No. 3. No → back to World Options; Difficulty still active, Apply still enabled. Apply → Yes → pause menu. Reopening: Difficulty and the lock are disabled (locked icon). 4. Quit and relaunch the world: Difficulty still disabled. `level.dat` has `difficulty_settings.locked = 1b`. 5. Restrictions with Chat: Shown lists the four green permissions. Escape returns to World Options. 6. Chat set to Hidden: the bold red "Chat is restricted in client settings.", the "Go to the Chat Settings screen" button, and four red lines. The button opens Chat Settings, and Done returns to World Options. **Tests:** `the_lock_follows_the_level_and_counts_as_a_change` (new); `level_round_trips_through_the_vanilla_files` now covers the lock. **Self-check:** `cargo fmt --check` ok; `cargo clippy -p horizon-client --all-targets -- -D warnings` ok; `cargo test -p horizon-client --bin horizon-client -- lan_screen` 3 passed; `save::tests::level_round_trips_through_the_vanilla_files` passes. Workspace clippy, the full client tests and `tools/parity.py --changed origin/main` run on the combined branch of this batch. **Not covered:** tooltips (Horizon's World Options draws none yet). Restrictions doesn't scroll: a world you host has at most one restriction (about 100 px), well within the 174 px area at the smallest GUI height. LAN guests already in the world aren't sent the new lock until they rejoin; the hub sends `ChangeDifficulty` only at login, for the difficulty too. 🤖 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-02 15:57:30 +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#2598
No description provided.