[PR #5122] [MERGED] Keep a NaN's bits in network NBT, as vanilla does (#5064, point 4) #6089

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

📋 Pull Request Information

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

Base: main ← Head: fix/nbt-network-nan


📝 Commits (1)

  • eb932b9 Keep a NaN's bits in network NBT, as vanilla does (#5064)

📊 Changes

1 file changed (+27 additions, -7 deletions)

View changed files

📝 crates/horizon-world/src/nbt.rs (+27 -7)

📄 Description

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

What and why

Refs #5064, point 4 only. Points 3, 5, 6, 7 and 8 are in #5090, #5085, #5077, #5110 and #5103. Points 1 and 2 are not touched.

Vanilla writes network NBT with FriendlyByteBuf.writeNbt, through Netty's ByteBuf, whose writeFloat and writeDouble keep a NaN's bits. Only the disk path canonicalizes: NbtIo.write writes through DataOutputStream, whose writeFloat uses floatToIntBits. Horizon's writer canonicalized NaNs on both paths.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Change

  • nbt.rs: Writer gets canonical_nan. It is on for write_named, the disk writer, and off for write_network, which now writes a float's or double's bits as they are.
  • The Tag doc comment says which path does what.
  • The existing test duplicate_keys_last_wins_and_nan_output_is_canonical asserted a canonical NaN from write_network, which is the opposite of vanilla. It is now ..._canonical_on_disk and checks both paths against vanilla's bytes.

Vanilla reference

  • FriendlyByteBuf.writeNbt → NbtIo.writeAnyTag on a ByteBufOutputStream → FloatTag.write / DoubleTag.write → Netty writeFloat / writeDouble (raw bits).
  • NbtIo.write(CompoundTag, DataOutput) on a DataOutputStream → writeFloat (Float.floatToIntBits, canonical NaN).

Test

I read each value below with NbtIo.readAnyTag, then wrote it with FriendlyByteBuf.writeNbt (network) and with NbtIo.write inside a compound (disk). This was a small Java program on the 26.3 jar.

tag read vanilla network main network this branch network vanilla / this branch disk
float 7f800001 7f800001 7fc00000 7f800001 7fc00000
float ff800001 ff800001 7fc00000 ff800001 7fc00000
float 7fc00001 7fc00001 7fc00000 7fc00001 7fc00000
double 7ff0000000000001 7ff0000000000001 7ff8000000000000 7ff0000000000001 7ff8000000000000

nbt::tests::duplicate_keys_last_wins_and_nan_output_is_canonical_on_disk checks the ff800001 float and the double on the network path, and the 7f800001 float on disk, with vanilla's exact bytes. It fails with the network writer canonicalizing and passes here.

All horizon-world tests (316) and horizon-protocol tests (146) pass. write_network's callers are the packet writer (horizon-protocol/src/buf.rs), one LAN test and the nbt-network-copy tool.

Overlap with #5085 (point 5, also mine): both add a field to Writer and set it in write_named and write_network, so whichever merges second has a small conflict there. The fix is to keep both fields, and I'll rebase whichever is left.

Self-check

pr_ready (tools/pr_ready.py --quick --base 36f4bc00d on DESKTOP-S9O4938, against 36f4bc00d at 36f4bc00d, 3 min 12 s)

Check Result
Scope ✅ 1 files, +27 −7
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 495 run, FAILED (errors=2, skipped=1) (56 s)
rustfmt ✅ (9 s)
clippy ✅ (19 s)
tests: horizon-world ✅ 316 passed (1 min 44 s)
doc tests ✅ 0 passed (2 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)

The two Python errors come from files this PR doesn't touch, and both also failed on main on this machine:

  • test_port_ledger cannot import tests.test_class_index.
  • test_perf_bench's windows_version() gets nothing from cmd /C ver on a Spanish Windows.

🤖 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/5122 **Author:** [@k3yh](https://github.com/k3yh) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/nbt-network-nan` --- ### 📝 Commits (1) - [`eb932b9`](https://github.com/horizon-rust/horizon/commit/eb932b91a38466e0d486effc786c9e53f7683cd2) Keep a NaN's bits in network NBT, as vanilla does (#5064) ### 📊 Changes **1 file changed** (+27 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/nbt.rs` (+27 -7) </details> ### 📄 Description > 🤖 Opened by k3yh's AI agent (Claude Code, Claude Opus 5.5), not by k3yh personally. ## What and why Refs #5064, point 4 only. Points 3, 5, 6, 7 and 8 are in #5090, #5085, #5077, #5110 and #5103. Points 1 and 2 are not touched. Vanilla writes network NBT with `FriendlyByteBuf.writeNbt`, through Netty's `ByteBuf`, whose `writeFloat` and `writeDouble` keep a NaN's bits. Only the disk path canonicalizes: `NbtIo.write` writes through `DataOutputStream`, whose `writeFloat` uses `floatToIntBits`. Horizon's writer canonicalized NaNs on both paths. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Change - `nbt.rs`: `Writer` gets `canonical_nan`. It is on for `write_named`, the disk writer, and off for `write_network`, which now writes a float's or double's bits as they are. - The `Tag` doc comment says which path does what. - The existing test `duplicate_keys_last_wins_and_nan_output_is_canonical` asserted a canonical NaN from `write_network`, which is the opposite of vanilla. It is now `..._canonical_on_disk` and checks both paths against vanilla's bytes. ## Vanilla reference - `FriendlyByteBuf.writeNbt` → `NbtIo.writeAnyTag` on a `ByteBufOutputStream` → `FloatTag.write` / `DoubleTag.write` → Netty `writeFloat` / `writeDouble` (raw bits). - `NbtIo.write(CompoundTag, DataOutput)` on a `DataOutputStream` → `writeFloat` (`Float.floatToIntBits`, canonical NaN). ## Test I read each value below with `NbtIo.readAnyTag`, then wrote it with `FriendlyByteBuf.writeNbt` (network) and with `NbtIo.write` inside a compound (disk). This was a small Java program on the 26.3 jar. | tag read | vanilla network | main network | this branch network | vanilla / this branch disk | |---|---|---|---|---| | float `7f800001` | `7f800001` | `7fc00000` | `7f800001` | `7fc00000` | | float `ff800001` | `ff800001` | `7fc00000` | `ff800001` | `7fc00000` | | float `7fc00001` | `7fc00001` | `7fc00000` | `7fc00001` | `7fc00000` | | double `7ff0000000000001` | `7ff0000000000001` | `7ff8000000000000` | `7ff0000000000001` | `7ff8000000000000` | `nbt::tests::duplicate_keys_last_wins_and_nan_output_is_canonical_on_disk` checks the `ff800001` float and the double on the network path, and the `7f800001` float on disk, with vanilla's exact bytes. It fails with the network writer canonicalizing and passes here. All `horizon-world` tests (316) and `horizon-protocol` tests (146) pass. `write_network`'s callers are the packet writer (`horizon-protocol/src/buf.rs`), one LAN test and the `nbt-network-copy` tool. Overlap with #5085 (point 5, also mine): both add a field to `Writer` and set it in `write_named` and `write_network`, so whichever merges second has a small conflict there. The fix is to keep both fields, and I'll rebase whichever is left. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base 36f4bc00d` on DESKTOP-S9O4938, against 36f4bc00d at 36f4bc00d, 3 min 12 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +27 −7 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 495 run, FAILED (errors=2, skipped=1) (56 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (19 s) | | tests: horizon-world | ✅ 316 passed (1 min 44 s) | | doc tests | ✅ 0 passed (2 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) | The two Python errors come from files this PR doesn't touch, and both also failed on main on this machine: - `test_port_ledger` cannot import `tests.test_class_index`. - `test_perf_bench`'s `windows_version()` gets nothing from `cmd /C ver` on a Spanish Windows. 🤖 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:11:33 +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#6089
No description provided.