[PR #4969] [MERGED] Save a pufferfish's puff state and an enderman's carried block #5979

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4969
Author: @MSedgeMC
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/pufferfish-enderman-save-data


📝 Commits (2)

  • 026d3fa Save a pufferfish's puff state and an enderman's carried block
  • 0d476d3 Keep a template's carried block when there is no registry

📊 Changes

9 files changed (+246 additions, -76 deletions)

View changed files

📝 crates/horizon-client/examples/probe/mob_ai_probe.rs (+7 -3)
📝 crates/horizon-client/examples/probe/trading_fixture.rs (+3 -2)
📝 crates/horizon-client/src/entity_nbt.rs (+200 -30)
📝 crates/horizon-client/src/game/commands/data.rs (+7 -2)
📝 crates/horizon-client/src/game/persist.rs (+15 -31)
📝 crates/horizon-client/src/game/spawner.rs (+6 -1)
📝 crates/horizon-client/src/mobs/camel.rs (+2 -2)
📝 crates/horizon-client/src/mobs/rabbit.rs (+3 -3)
📝 crates/horizon-client/src/vanillagen/structure_mobs.rs (+3 -2)

📄 Description

Fixes the Pufferfish.readAdditionalSaveData and Enderman.addAdditionalSaveData/readAdditionalSaveData rows in the port ledger. (No issue.)

Two mob fields were never saved, which is one mistake twice:

  • PuffState — Pufferfish.addAdditionalSaveData writes it as an Int and readAdditionalSaveData reads getIntOr("PuffState", 0) clamped with Math.min(saved, 2). Horizon keeps the puff state in extra.size (the tick sets it, the renderer and shadows read it, the network path writes it) and no save code touched it, so a puffed pufferfish came back small after a reload.
  • carriedBlockState — Enderman.addAdditionalSaveData writes the carried state with BlockState.CODEC, only while it carries one (absent otherwise), and the read drops an air state. Horizon models it properly as extra.carried: Option<BlockStateId>, but never saved it, so an enderman forgot what it was holding.

BlockState.CODEC writes a bare block name for a default state and {id, properties} otherwise, which is what the save path's existing state_to_nbt/state_from_nbt already did for falling blocks and pistons — those move from game/persist.rs into entity_nbt.rs so both sides use one definition, and the codec's registry is threaded into mob_to_nbt/mob_from_nbt as Option<&BlockRegistry>. That is the one API change: Some(...) where the game has resources (save, load, /data, the spawner), None in unit tests and structure-template worldgen, where the loaded compound is preserved exactly as before and a carried block stays as the template had it.

Proven: on a build box cargo test -p horizon-client --lib mobs_keep_their_variant_puff_state_and_carried_block → 1 passed, covering: puff state 2 round-tripping, a missing PuffState reading 0, a PuffState of 5 reading 2 (vanilla's clamp), a carried grass block saved as a bare name, an oak_log[axis=x] saved as a compound and read back with its properties, no key at all when carrying nothing, and "minecraft:air" reading as no block.

Not proven: nothing in a game and no parity harness — save_roundtrip is the harness that would exercise the new keys end to end and it was not run here. The Option<&BlockRegistry> signature is the part a reviewer may want differently: the cheaper alternative keeps the signatures and resolves the state in persist.rs, at the cost of leaving the read outside mob_from_nbt and untestable in the lib. Say which you prefer and I will switch it.

Overlap: this touches entity_nbt.rs, as does my open #4515 (mooshroom stew effects); different functions, but whichever merges second will want a rebase.

One adjacent gap left alone deliberately: AbstractFish.addAdditionalSaveData also writes FromBucket, which Horizon has nowhere.


🔄 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/4969 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/pufferfish-enderman-save-data` --- ### 📝 Commits (2) - [`026d3fa`](https://github.com/horizon-rust/horizon/commit/026d3fa47a7bacb2deb58ebeabfccbecf23c58f7) Save a pufferfish's puff state and an enderman's carried block - [`0d476d3`](https://github.com/horizon-rust/horizon/commit/0d476d32e7fa05c56a3febb1cf9d2f3c9717d792) Keep a template's carried block when there is no registry ### 📊 Changes **9 files changed** (+246 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/probe/mob_ai_probe.rs` (+7 -3) 📝 `crates/horizon-client/examples/probe/trading_fixture.rs` (+3 -2) 📝 `crates/horizon-client/src/entity_nbt.rs` (+200 -30) 📝 `crates/horizon-client/src/game/commands/data.rs` (+7 -2) 📝 `crates/horizon-client/src/game/persist.rs` (+15 -31) 📝 `crates/horizon-client/src/game/spawner.rs` (+6 -1) 📝 `crates/horizon-client/src/mobs/camel.rs` (+2 -2) 📝 `crates/horizon-client/src/mobs/rabbit.rs` (+3 -3) 📝 `crates/horizon-client/src/vanillagen/structure_mobs.rs` (+3 -2) </details> ### 📄 Description Fixes the `Pufferfish.readAdditionalSaveData` and `Enderman.addAdditionalSaveData`/`readAdditionalSaveData` rows in the port ledger. (No issue.) Two mob fields were never saved, which is one mistake twice: - **`PuffState`** — `Pufferfish.addAdditionalSaveData` writes it as an Int and `readAdditionalSaveData` reads `getIntOr("PuffState", 0)` clamped with `Math.min(saved, 2)`. Horizon keeps the puff state in `extra.size` (the tick sets it, the renderer and shadows read it, the network path writes it) and no save code touched it, so a puffed pufferfish came back small after a reload. - **`carriedBlockState`** — `Enderman.addAdditionalSaveData` writes the carried state with `BlockState.CODEC`, **only while it carries one** (absent otherwise), and the read drops an air state. Horizon models it properly as `extra.carried: Option<BlockStateId>`, but never saved it, so an enderman forgot what it was holding. `BlockState.CODEC` writes a bare block name for a default state and `{id, properties}` otherwise, which is what the save path's existing `state_to_nbt`/`state_from_nbt` already did for falling blocks and pistons — those move from `game/persist.rs` into `entity_nbt.rs` so both sides use one definition, and the codec's registry is threaded into `mob_to_nbt`/`mob_from_nbt` as `Option<&BlockRegistry>`. That is the one API change: `Some(...)` where the game has resources (save, load, `/data`, the spawner), `None` in unit tests and structure-template worldgen, where the loaded compound is preserved exactly as before and a carried block stays as the template had it. **Proven:** on a build box `cargo test -p horizon-client --lib mobs_keep_their_variant_puff_state_and_carried_block` → 1 passed, covering: puff state 2 round-tripping, a missing `PuffState` reading 0, a `PuffState` of 5 reading 2 (vanilla's clamp), a carried grass block saved as a bare name, an `oak_log[axis=x]` saved as a compound and read back with its properties, no key at all when carrying nothing, and `"minecraft:air"` reading as no block. **Not proven:** nothing in a game and no parity harness — `save_roundtrip` is the harness that would exercise the new keys end to end and it was not run here. The `Option<&BlockRegistry>` signature is the part a reviewer may want differently: the cheaper alternative keeps the signatures and resolves the state in `persist.rs`, at the cost of leaving the read outside `mob_from_nbt` and untestable in the lib. Say which you prefer and I will switch it. **Overlap:** this touches `entity_nbt.rs`, as does my open #4515 (mooshroom stew effects); different functions, but whichever merges second will want a rebase. One adjacent gap left alone deliberately: `AbstractFish.addAdditionalSaveData` also writes `FromBucket`, which Horizon has nowhere. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:21 +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#5979
No description provided.