[PR #2768] [MERGED] The world's difficulty follows the level data #4591

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2768
Author: @levzzz5154
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/28/2026
Merged by: @ludovic111

Base: main ← Head: fix/world-difficulty-survives-reopen


📝 Commits (3)

  • c734c72 The world's difficulty survives leaving and rejoining it
  • 618d20b The world's difficulty follows the level data
  • 35581f5 Keep the clippy rules happy in the difficulty test

📊 Changes

4 files changed (+52 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/game/chat.rs (+1 -4)
📝 crates/horizon-client/src/game/commands.rs (+3 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+3 -0)
📝 crates/horizon-client/src/save.rs (+45 -0)

📄 Description

🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself.

What and why

#2571: the world is set to hard, the player leaves and rejoins, and /difficulty answers normal. A downloaded world should also keep the difficulty it was made with.

In vanilla the difficulty is a property of the world: it lives in the level data, in Data.difficulty_settings (LevelSettings.DifficultySettings), and PrimaryLevelData.getDifficulty/setDifficulty read and write it, so it survives a restart.

Horizon read the difficulty from the level data when the world opened (load_world_state → self.level.difficulty), but the world only ever changed its own copy: /difficulty set self.ui.difficulty and left the level data alone, so the next save wrote the old value back and the world came back on normal. The same held for a guest asking the host to change the difficulty.

The level data is now the one place the difficulty lives: Level::set_difficulty (PrimaryLevelData.setDifficulty) and Level::difficulty_id (PrimaryLevelData.getDifficulty) are the two ends of it, the /difficulty command and the LAN host's difficulty change write through them, and the world reads the id back from the level data when it opens.

Fixes #2571

Vanilla reference

  • net.minecraft.world.level.storage.PrimaryLevelData.getDifficulty / setDifficulty — the level data holds the difficulty (this.settings.difficultySettings().difficulty()).
  • net.minecraft.world.level.LevelSettings.DifficultySettings — the difficulty, hardcore and locked fields of Data.difficulty_settings.
  • net.minecraft.world.level.storage.PrimaryLevelData — tag.store("difficulty_settings", LevelSettings.DifficultySettings.CODEC, this.settings.difficultySettings()) writes it into level.dat.
  • net.minecraft.server.commands.DifficultyCommand — the command sets the server's difficulty, which is the level data's.

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on cachyos-x8664, against upstream/main at 069a4f7f2, 3 min 46 s)

Check Result
Scope ✅ 4 files, +52 −4
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 331 passed (17 s)
rustfmt ✅ (4 s)
clippy ✅ (1 min 5 s)
tests: horizon-client ✅ 1330 passed (1 min 57 s)
doc tests ✅ 0 passed (17 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 ➖ 74 affected, to run in CI (--quick): arrow, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, breaking_model, cauldron, command_exec, composter, crafter and 62 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)
  • cargo test -p horizon-client --lib -- level_data_holds_the_difficulty
    → 1 passed; 0 failed (save::tests::the_level_data_holds_the_difficulty: the level data holds the difficulty, it survives the save, and a difficulty that is not one of ours is normal).
  • Before this pull request the same path read Data.Difficulty, a byte that 26.3 no longer has, so the world opened on normal: the test's read returned None instead of the world's difficulty.
  • cargo fmt -p horizon-client → clean.
  • python3 tools/check_public_tree.py → "Public tree check passed." (run by the commit hook).

🤖 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/2768 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/28/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/world-difficulty-survives-reopen` --- ### 📝 Commits (3) - [`c734c72`](https://github.com/horizon-rust/horizon/commit/c734c72fc9d92d56fc4ac306a180bd4f7df15260) The world's difficulty survives leaving and rejoining it - [`618d20b`](https://github.com/horizon-rust/horizon/commit/618d20bd0832dca02ba4e6b5ebf1a38d03f867ce) The world's difficulty follows the level data - [`35581f5`](https://github.com/horizon-rust/horizon/commit/35581f52e26b569fdf73bafd1976dee5fb710585) Keep the clippy rules happy in the difficulty test ### 📊 Changes **4 files changed** (+52 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/chat.rs` (+1 -4) 📝 `crates/horizon-client/src/game/commands.rs` (+3 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+3 -0) 📝 `crates/horizon-client/src/save.rs` (+45 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code), not by levzzz5154 himself. ## What and why #2571: the world is set to hard, the player leaves and rejoins, and `/difficulty` answers normal. A downloaded world should also keep the difficulty it was made with. In vanilla the difficulty is a property of the world: it lives in the level data, in `Data.difficulty_settings` (`LevelSettings.DifficultySettings`), and `PrimaryLevelData.getDifficulty`/`setDifficulty` read and write it, so it survives a restart. Horizon read the difficulty from the level data when the world opened (`load_world_state` → `self.level.difficulty`), but the world only ever *changed* its own copy: `/difficulty` set `self.ui.difficulty` and left the level data alone, so the next save wrote the old value back and the world came back on normal. The same held for a guest asking the host to change the difficulty. The level data is now the one place the difficulty lives: `Level::set_difficulty` (`PrimaryLevelData.setDifficulty`) and `Level::difficulty_id` (`PrimaryLevelData.getDifficulty`) are the two ends of it, the `/difficulty` command and the LAN host's difficulty change write through them, and the world reads the id back from the level data when it opens. Fixes #2571 ## Vanilla reference - `net.minecraft.world.level.storage.PrimaryLevelData.getDifficulty` / `setDifficulty` — the level data holds the difficulty (`this.settings.difficultySettings().difficulty()`). - `net.minecraft.world.level.LevelSettings.DifficultySettings` — the `difficulty`, `hardcore` and `locked` fields of `Data.difficulty_settings`. - `net.minecraft.world.level.storage.PrimaryLevelData` — `tag.store("difficulty_settings", LevelSettings.DifficultySettings.CODEC, this.settings.difficultySettings())` writes it into `level.dat`. - `net.minecraft.server.commands.DifficultyCommand` — the command sets the server's difficulty, which is the level data's. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on cachyos-x8664, against upstream/main at 069a4f7f2, 3 min 46 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +52 −4 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 331 passed (17 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (1 min 5 s) | | tests: horizon-client | ✅ 1330 passed (1 min 57 s) | | doc tests | ✅ 0 passed (17 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 | ➖ 74 affected, to run in CI (--quick): arrow, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, breaking_model, cauldron, command_exec, composter, crafter and 62 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | - `cargo test -p horizon-client --lib -- level_data_holds_the_difficulty` → `1 passed; 0 failed` (`save::tests::the_level_data_holds_the_difficulty`: the level data holds the difficulty, it survives the save, and a difficulty that is not one of ours is normal). - Before this pull request the same path read `Data.Difficulty`, a byte that 26.3 no longer has, so the world opened on normal: the test's read returned `None` instead of the world's difficulty. - `cargo fmt -p horizon-client` → clean. - `python3 tools/check_public_tree.py` → "Public tree check passed." (run by the commit hook). 🤖 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 04:18:20 +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#4591
No description provided.