[PR #4862] [MERGED] Hash block predicates with nbt or partial predicates and books with filtered text #5898

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

📋 Pull Request Information

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

Base: main ← Head: parity/K3-hash


📝 Commits (2)

  • d7ff063 Hash block predicates with nbt or partial predicates, and books with filtered text, as vanilla does
  • 7bcd15e Merge remote-tracking branch 'hr/main' into parity/K3-hash

📊 Changes

9 files changed (+514 additions, -222 deletions)

View changed files

📝 crates/horizon-client-core/src/snbt.rs (+2 -173)
📝 crates/horizon-client/src/item_sync.rs (+1 -1)
📝 crates/horizon-client/src/lan/guest.rs (+5 -1)
📝 crates/horizon-protocol/src/item.rs (+73 -29)
📝 crates/horizon-protocol/src/item/hash.rs (+30 -8)
📝 crates/horizon-protocol/src/item/hash/gameplay.rs (+70 -10)
📝 crates/horizon-protocol/src/item/hash/raw.rs (+155 -0)
📝 crates/horizon-world/src/lib.rs (+1 -0)
➕ crates/horizon-world/src/snbt_text.rs (+177 -0)

📄 Description

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

Part of #3520

What and why

Sixth PR on the hashed container-click components (#4738, #4742, #4764, #4772, #4782). It closes two of the three cases #4782 left unhashed, and answers the third.

Rows

  • HashedPatchMap.create: can_place_on / can_break with a block entity nbt now hash (NbtPredicate.CODEC is TagParser.LENIENT_CODEC, which encodes with its flattened codec: the tag's toString SNBT string), and so do partial predicates (DataComponentPredicate.CODEC, a Codec.dispatchedMap of type name to predicate). A partial predicate travels as the NBT its codec encodes; it is hashed as that tree, with the codecs' Codec.BOOL fields (has_twinkle, has_trail, resolved, ambient, visible, and the text component's) as booleans. The type is a predicate type or, for AnyValue, a component type.
  • HashedStack.create: writable_book_content and written_book_content with filtered text now hash. Component keeps Filterable.filtered of the pages and the title (it read and dropped them), writes them back, and hashes the Filterable record with its filtered field. The book screen reads only the raw text, as before.
  • Moved StringTagVisitor (to_snbt, quote_and_escape, java_float, java_double) from horizon-client-core to horizon-world::snbt_text so the protocol can use it; horizon_client::snbt re-exports it unchanged.

What stays unhashed (the rows stay partial)

  • A container / bundle_contents partial predicate whose item predicate has exact components: their values are component codec NBT whose booleans (and other byte-typed fields) cannot be told from plain bytes without every component's NBT codec. Rare; hashed as before (left out).
  • Registry ids with no name: not a gap. Vanilla's client always knows every name: built-in registries are in its own registry, and every data-driven one the hash code reads (the 33 SYNCHRONIZED_REGISTRIES) is sent in full (Horizon's client answers SelectKnownPacks with no packs, net.rs), over registries.json which the game refuses to start without (remote.rs:428). All registry strings in the hash code were checked against both lists. An id outside a registry fails to decode in vanilla (the connection drops), so leaving it unhashed is the right outcome there. Nothing to change at the source.
  • Never hashable, as vanilla's own client would throw: creative_slot_lock, map_post_processing, additional_trade_cost, a direct painting/variant or jukebox_playable.

Kind

  • parity: Horizon now does what vanilla 26.3 does

Vanilla reference

TypedDataComponent.encodeValue, HashedPatchMap.create, BlockPredicate, NbtPredicate, TagParser.LENIENT_CODEC / FLATTENED_CODEC, StringTagVisitor, DataComponentMatchers, DataComponentPredicate (CODEC, STREAM_CODEC, Type), DataComponentPredicates, the predicate codecs under core/component/predicates, Filterable, WritableBookContent, WrittenBookContent.

Tests

cargo test -p horizon-protocol --lib item::: predicates_and_filtered_books_hash_as_vanilla_does pins 21 cases whose stream bytes and hashes vanilla 26.3 printed itself (a throwaway Java driver on the real jars: SNBT through the component's codec, STREAM_CODEC.encode, encodeValue through HashOps.CRC32C_INSTANCE): nbt with every tag type, each predicate type, AnyValue, booleans, a multi-entry map, filtered and unfiltered books, and the exact-components case that stays unhashed. filtered_book_pages_are_read_and_kept and the stack round trip cover the filtered variants going back out. fmt and clippy -D warnings on horizon-protocol, horizon-world, horizon-client-core, horizon-client.

🤖 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/4862 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `parity/K3-hash` --- ### 📝 Commits (2) - [`d7ff063`](https://github.com/horizon-rust/horizon/commit/d7ff06303546d0eba6b94adc26822bb38b965065) Hash block predicates with nbt or partial predicates, and books with filtered text, as vanilla does - [`7bcd15e`](https://github.com/horizon-rust/horizon/commit/7bcd15e22df70c56a5b48fbb2600440d48fd936c) Merge remote-tracking branch 'hr/main' into parity/K3-hash ### 📊 Changes **9 files changed** (+514 additions, -222 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-core/src/snbt.rs` (+2 -173) 📝 `crates/horizon-client/src/item_sync.rs` (+1 -1) 📝 `crates/horizon-client/src/lan/guest.rs` (+5 -1) 📝 `crates/horizon-protocol/src/item.rs` (+73 -29) 📝 `crates/horizon-protocol/src/item/hash.rs` (+30 -8) 📝 `crates/horizon-protocol/src/item/hash/gameplay.rs` (+70 -10) 📝 `crates/horizon-protocol/src/item/hash/raw.rs` (+155 -0) 📝 `crates/horizon-world/src/lib.rs` (+1 -0) ➕ `crates/horizon-world/src/snbt_text.rs` (+177 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #3520 ## What and why Sixth PR on the hashed container-click components (#4738, #4742, #4764, #4772, #4782). It closes two of the three cases #4782 left unhashed, and answers the third. ## Rows - `HashedPatchMap.create`: `can_place_on` / `can_break` with a block entity `nbt` now hash (`NbtPredicate.CODEC` is `TagParser.LENIENT_CODEC`, which encodes with its flattened codec: the tag's `toString` SNBT string), and so do partial `predicates` (`DataComponentPredicate.CODEC`, a `Codec.dispatchedMap` of type name to predicate). A partial predicate travels as the NBT its codec encodes; it is hashed as that tree, with the codecs' `Codec.BOOL` fields (`has_twinkle`, `has_trail`, `resolved`, `ambient`, `visible`, and the text component's) as booleans. The type is a predicate type or, for `AnyValue`, a component type. - `HashedStack.create`: `writable_book_content` and `written_book_content` with filtered text now hash. `Component` keeps `Filterable.filtered` of the pages and the title (it read and dropped them), writes them back, and hashes the `Filterable` record with its `filtered` field. The book screen reads only the raw text, as before. - Moved `StringTagVisitor` (`to_snbt`, `quote_and_escape`, `java_float`, `java_double`) from `horizon-client-core` to `horizon-world::snbt_text` so the protocol can use it; `horizon_client::snbt` re-exports it unchanged. ## What stays unhashed (the rows stay partial) - A `container` / `bundle_contents` partial predicate whose item predicate has exact `components`: their values are component codec NBT whose booleans (and other byte-typed fields) cannot be told from plain bytes without every component's NBT codec. Rare; hashed as before (left out). - Registry ids with no name: not a gap. Vanilla's client always knows every name: built-in registries are in its own registry, and every data-driven one the hash code reads (the 33 `SYNCHRONIZED_REGISTRIES`) is sent in full (Horizon's client answers `SelectKnownPacks` with no packs, `net.rs`), over `registries.json` which the game refuses to start without (`remote.rs:428`). All registry strings in the hash code were checked against both lists. An id outside a registry fails to decode in vanilla (the connection drops), so leaving it unhashed is the right outcome there. Nothing to change at the source. - Never hashable, as vanilla's own client would throw: `creative_slot_lock`, `map_post_processing`, `additional_trade_cost`, a direct `painting/variant` or `jukebox_playable`. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does ## Vanilla reference `TypedDataComponent.encodeValue`, `HashedPatchMap.create`, `BlockPredicate`, `NbtPredicate`, `TagParser.LENIENT_CODEC` / `FLATTENED_CODEC`, `StringTagVisitor`, `DataComponentMatchers`, `DataComponentPredicate` (`CODEC`, `STREAM_CODEC`, `Type`), `DataComponentPredicates`, the predicate codecs under `core/component/predicates`, `Filterable`, `WritableBookContent`, `WrittenBookContent`. ## Tests `cargo test -p horizon-protocol --lib item::`: `predicates_and_filtered_books_hash_as_vanilla_does` pins 21 cases whose stream bytes and hashes vanilla 26.3 printed itself (a throwaway Java driver on the real jars: SNBT through the component's codec, `STREAM_CODEC.encode`, `encodeValue` through `HashOps.CRC32C_INSTANCE`): nbt with every tag type, each predicate type, `AnyValue`, booleans, a multi-entry map, filtered and unfiltered books, and the exact-components case that stays unhashed. `filtered_book_pages_are_read_and_kept` and the stack round trip cover the filtered variants going back out. `fmt` and `clippy -D warnings` on `horizon-protocol`, `horizon-world`, `horizon-client-core`, `horizon-client`. 🤖 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 05:15:46 +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#5898
No description provided.