[PR #479] [MERGED] Ctrl + Pick Block copies the block entity's data in creative #2595

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

📋 Pull Request Information

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

Base: main ← Head: fix/pick-block-data


📝 Commits (1)

  • bd42496 Ctrl + Pick Block copies the block entity's data in creative

📊 Changes

13 files changed (+925 additions, -73 deletions)

View changed files

➕ crates/horizon-client/examples/pick_block_data_fixture.rs (+96 -0)
➕ crates/horizon-client/src/block_entity_item.rs (+439 -0)
📝 crates/horizon-client/src/block_entity_nbt.rs (+1 -1)
📝 crates/horizon-client/src/game.rs (+20 -23)
📝 crates/horizon-client/src/game/banners.rs (+0 -14)
➕ crates/horizon-client/src/game/block_items.rs (+117 -0)
📝 crates/horizon-client/src/game/command_blocks.rs (+5 -4)
📝 crates/horizon-client/src/game/dispenser.rs (+1 -2)
📝 crates/horizon-client/src/game/remote.rs (+1 -1)
📝 crates/horizon-client/src/game/storage.rs (+0 -28)
📝 crates/horizon-client/src/lib.rs (+1 -0)
➕ mods/horizon/src/test/java/dev/horizonlab/parity/VanillaPickBlockDataOracle.java (+91 -0)
➕ tools/test_pick_block_data_parity.py (+153 -0)

📄 Description

Fixes #386.

What

In creative, Ctrl + Pick Block now gives the block's item with the block entity's data, and placing that item puts the data back, as vanilla 26.3 does. Ctrl+Pick a filled chest and you get a chest that holds the same items; Ctrl+Pick a written sign and the placed copy has the same text.

Vanilla references

  • Minecraft.pickBlockOrEntity: includeData = hasControlDown().
  • ServerGamePacketListenerImpl.handlePickItemFromBlock / addBlockDataToItem: only with infinite materials (creative). The steps are saveCustomOnly, then removeComponentsFromTag, then BlockItem.setBlockEntityData (no component when nothing is left; otherwise tagged with the type's id), then applyComponents(collectComponents()). What a type collects goes to components, not to block_entity_data:
    • containers: container, custom_name, lock, container_loot;
    • signs: sign_text_front / sign_text_back / waxed;
    • other types: banner patterns, bees, pot decorations, skull profile / note block sound, command block name.
  • On placement:
    • BlockItem.updateCustomBlockEntityTag runs TypedEntityData.loadInto (merge into saveCustomOnly, load if changed) only when the type matches and the type isn't op-only (BlockEntityTypes.OP_ONLY_CUSTOM_DATA: command blocks, lecterns, signs, spawners, trial spawners), or the player canUseGameMasterBlocks. A dispenser never can.
    • Then BlockEntity.applyComponentsFromItemStack (applyImplicitComponents of each type; the rest of the patch becomes the block entity's own components).
  • CommandBlock.setPlacedBy: a command block placed with data keeps its own auto and TrackOutput.
  • SignBlock.setPlacedBy: a waxed sign opens no editor.
  • AbstractBannerBlock.getCloneItemStack: a picked banner keeps its patterns and name, even without Ctrl.
  • BeehiveBlock.getCloneItemStack: with data, the item gets block_state{honey_level}.

How

  • horizon_client::block_entity_item: pick and place, which work on the block entity's canonical saved NBT (block_entity_nbt::canonical) and the item's component patch. One table lists, per type, which NBT key maps to which component.
  • game/block_items.rs: picked_stack (the Middle-click path) and apply_placed_item (used for player placement and dispensers). apply_placed_item replaces the old shulker-box, container-name and banner fill-ins, so placed chests, barrels, hoppers, furnaces and the rest now take their container contents, as vanilla does (before, only shulker boxes did).
  • Multiplayer: the client sends include_data on Ctrl.

Proof

tools/test_pick_block_data_parity.py (new harness: Java oracle VanillaPickBlockDataOracle + Rust example pick_block_data_fixture). Vanilla's real block entities are loaded with BlockEntity.loadStatic, picked, then the item is placed back with vanilla's own code. The cases cover 34 blocks: every container, signs, hanging signs, banners, pots, beehives, skulls, command blocks, spawners, trial spawners, vaults, lecterns, jukeboxes and more. They run with and without game-master rights, plus hand-written patches: data of another type, op-only data without permission, merges into a filled block entity, leftover components, !component removals and out-of-range slots.

148/148 cases match

In game on the Mac mini (creative): I Ctrl+Picked a chest filled with 5 diamonds and 2 apples, then placed it; /data get block shows the same Items and the opened chest shows them. A sign reading "hello / world" placed back with the same text (the editor opens on it, as in vanilla). A command block placed back with Command:"say picked" and its own auto:1b.

Self-check:

  • cargo fmt --all: clean
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo test -p horizon-client: 745 + 46 + 15 + 2 + 2 + 2 passed

Not covered (Horizon has no world state for them)

  • Pots, skulls, campfires, chiseled bookshelves, shelves and enchanting tables aren't block entities in world.block_entities. The conversion handles them and the harness checks them, but in game their pick has nothing to copy yet.
  • A container's lock and loot table, and a block entity's own leftover components, aren't kept in the world model either.

The diff is ~925 lines, about 340 of them the harness (oracle, probe, corpus).

PARITY_LOCAL_JOBS=3 tools/parity.py --changed origin/main on fix/block-entity-data-tooltips (#479 + #481 together): 84/84 harnesses pass (12 in a first run, 72 after a restart), pick_block_data included.

🤖 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/479 **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/pick-block-data` --- ### 📝 Commits (1) - [`bd42496`](https://github.com/horizon-rust/horizon/commit/bd42496af0941483477d733821655fcd87252643) Ctrl + Pick Block copies the block entity's data in creative ### 📊 Changes **13 files changed** (+925 additions, -73 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/pick_block_data_fixture.rs` (+96 -0) ➕ `crates/horizon-client/src/block_entity_item.rs` (+439 -0) 📝 `crates/horizon-client/src/block_entity_nbt.rs` (+1 -1) 📝 `crates/horizon-client/src/game.rs` (+20 -23) 📝 `crates/horizon-client/src/game/banners.rs` (+0 -14) ➕ `crates/horizon-client/src/game/block_items.rs` (+117 -0) 📝 `crates/horizon-client/src/game/command_blocks.rs` (+5 -4) 📝 `crates/horizon-client/src/game/dispenser.rs` (+1 -2) 📝 `crates/horizon-client/src/game/remote.rs` (+1 -1) 📝 `crates/horizon-client/src/game/storage.rs` (+0 -28) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) ➕ `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaPickBlockDataOracle.java` (+91 -0) ➕ `tools/test_pick_block_data_parity.py` (+153 -0) </details> ### 📄 Description Fixes #386. ## What In creative, **Ctrl + Pick Block** now gives the block's item with the block entity's data, and placing that item puts the data back, as vanilla 26.3 does. Ctrl+Pick a filled chest and you get a chest that holds the same items; Ctrl+Pick a written sign and the placed copy has the same text. ## Vanilla references - `Minecraft.pickBlockOrEntity`: `includeData = hasControlDown()`. - `ServerGamePacketListenerImpl.handlePickItemFromBlock` / `addBlockDataToItem`: only with infinite materials (creative). The steps are `saveCustomOnly`, then `removeComponentsFromTag`, then `BlockItem.setBlockEntityData` (no component when nothing is left; otherwise tagged with the type's `id`), then `applyComponents(collectComponents())`. What a type collects goes to components, not to `block_entity_data`: - containers: `container`, `custom_name`, `lock`, `container_loot`; - signs: `sign_text_front` / `sign_text_back` / `waxed`; - other types: banner patterns, bees, pot decorations, skull profile / note block sound, command block name. - On placement: - `BlockItem.updateCustomBlockEntityTag` runs `TypedEntityData.loadInto` (merge into `saveCustomOnly`, load if changed) only when the type matches and the type isn't op-only (`BlockEntityTypes.OP_ONLY_CUSTOM_DATA`: command blocks, lecterns, signs, spawners, trial spawners), or the player `canUseGameMasterBlocks`. A dispenser never can. - Then `BlockEntity.applyComponentsFromItemStack` (`applyImplicitComponents` of each type; the rest of the patch becomes the block entity's own components). - `CommandBlock.setPlacedBy`: a command block placed with data keeps its own `auto` and `TrackOutput`. - `SignBlock.setPlacedBy`: a waxed sign opens no editor. - `AbstractBannerBlock.getCloneItemStack`: a picked banner keeps its patterns and name, even without Ctrl. - `BeehiveBlock.getCloneItemStack`: with data, the item gets `block_state{honey_level}`. ## How - `horizon_client::block_entity_item`: `pick` and `place`, which work on the block entity's canonical saved NBT (`block_entity_nbt::canonical`) and the item's component patch. One table lists, per type, which NBT key maps to which component. - `game/block_items.rs`: `picked_stack` (the Middle-click path) and `apply_placed_item` (used for player placement and dispensers). `apply_placed_item` replaces the old shulker-box, container-name and banner fill-ins, so placed chests, barrels, hoppers, furnaces and the rest now take their `container` contents, as vanilla does (before, only shulker boxes did). - Multiplayer: the client sends `include_data` on Ctrl. ## Proof `tools/test_pick_block_data_parity.py` (new harness: Java oracle `VanillaPickBlockDataOracle` + Rust example `pick_block_data_fixture`). Vanilla's real block entities are loaded with `BlockEntity.loadStatic`, picked, then the item is placed back with vanilla's own code. The cases cover 34 blocks: every container, signs, hanging signs, banners, pots, beehives, skulls, command blocks, spawners, trial spawners, vaults, lecterns, jukeboxes and more. They run with and without game-master rights, plus hand-written patches: data of another type, op-only data without permission, merges into a filled block entity, leftover components, `!component` removals and out-of-range slots. ``` 148/148 cases match ``` In game on the Mac mini (creative): I Ctrl+Picked a chest filled with 5 diamonds and 2 apples, then placed it; `/data get block` shows the same `Items` and the opened chest shows them. A sign reading "hello / world" placed back with the same text (the editor opens on it, as in vanilla). A command block placed back with `Command:"say picked"` and its own `auto:1b`. Self-check: - `cargo fmt --all`: clean - `cargo clippy --workspace --all-targets -- -D warnings`: clean - `cargo test -p horizon-client`: 745 + 46 + 15 + 2 + 2 + 2 passed ## Not covered (Horizon has no world state for them) - Pots, skulls, campfires, chiseled bookshelves, shelves and enchanting tables aren't block entities in `world.block_entities`. The conversion handles them and the harness checks them, but in game their pick has nothing to copy yet. - A container's `lock` and loot table, and a block entity's own leftover `components`, aren't kept in the world model either. The diff is ~925 lines, about 340 of them the harness (oracle, probe, corpus). `PARITY_LOCAL_JOBS=3 tools/parity.py --changed origin/main` on fix/block-entity-data-tooltips (#479 + #481 together): **84/84 harnesses pass** (12 in a first run, 72 after a restart), `pick_block_data` included. 🤖 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:28 +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#2595
No description provided.