[PR #398] [MERGED] Pick Block picks from the inventory in survival #2535

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

📋 Pull Request Information

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

Base: main ← Head: fix/pick-block


📝 Commits (1)

  • 9e2d46d Pick Block picks from the inventory in survival, as vanilla does

📊 Changes

3 files changed (+145 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+12 -3)
📝 crates/horizon-client/src/lib.rs (+1 -0)
➕ crates/horizon-client/src/pick_item.rs (+132 -0)

📄 Description

Pick Block (middle click) now works in survival in singleplayer. Fixes #367 (reported by tydragon on Discord).

What was wrong

Locally the middle button did nothing outside creative. In creative it overwrote the selected hotbar slot with the block. Servers already received PickItemFromBlock and handled it themselves.

Now

The middle button runs vanilla's server-side handlePickItemFromBlock → tryPickItem (pick_item::pick):

  • a stack of the block's item already in the hotbar is selected;
  • one in the main inventory is swapped into getSuitableHotbarSlot (the first empty hotbar slot from the selected one, else the first without enchantments, else the selected slot);
  • only in creative, when there is none, the item is added (addAndPickItem: what that hotbar slot held moves to the first free slot).

Not covered here: Ctrl + Pick Block's block data in creative (includeData) and picking entities.

How tested

  • Unit tests for each branch: hotbar select, swap from the main inventory (an empty slot, and a full hotbar), survival without the item, creative add (with a free slot, and a full hotbar).
  • In game (offscreen): in survival, with stone only in main slot 20, middle-clicking a stone block moves the 7 stone into the first empty hotbar slot and selects it. On oak planks with none owned, nothing happens. In creative, middle-clicking the planks adds one to the next empty hotbar slot.

Self-check:

cargo fmt --all --check                                   ok
cargo clippy --workspace --all-targets -- -D warnings     ok
cargo test -p horizon-client                              ok (681 + 44 + 15 + 2 + 2 + 2)
tools/parity.py --changed origin/main                     80 passed, 0 failed (56 min), one run over an integration commit of all the inventory PRs (this one included)

Independent of the other inventory PRs (based on main).

🤖 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/398 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/pick-block` --- ### 📝 Commits (1) - [`9e2d46d`](https://github.com/horizon-rust/horizon/commit/9e2d46d54eadf2b2dafb335d38b11941ac58ad0c) Pick Block picks from the inventory in survival, as vanilla does ### 📊 Changes **3 files changed** (+145 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+12 -3) 📝 `crates/horizon-client/src/lib.rs` (+1 -0) ➕ `crates/horizon-client/src/pick_item.rs` (+132 -0) </details> ### 📄 Description Pick Block (middle click) now works in survival in singleplayer. Fixes #367 (reported by tydragon on Discord). ## What was wrong Locally the middle button did nothing outside creative. In creative it overwrote the selected hotbar slot with the block. Servers already received `PickItemFromBlock` and handled it themselves. ## Now The middle button runs vanilla's server-side `handlePickItemFromBlock` → `tryPickItem` (`pick_item::pick`): - a stack of the block's item already in the hotbar is selected; - one in the main inventory is swapped into `getSuitableHotbarSlot` (the first empty hotbar slot from the selected one, else the first without enchantments, else the selected slot); - only in creative, when there is none, the item is added (`addAndPickItem`: what that hotbar slot held moves to the first free slot). Not covered here: Ctrl + Pick Block's block data in creative (`includeData`) and picking entities. ## How tested - Unit tests for each branch: hotbar select, swap from the main inventory (an empty slot, and a full hotbar), survival without the item, creative add (with a free slot, and a full hotbar). - In game (offscreen): in survival, with stone only in main slot 20, middle-clicking a stone block moves the 7 stone into the first empty hotbar slot and selects it. On oak planks with none owned, nothing happens. In creative, middle-clicking the planks adds one to the next empty hotbar slot. Self-check: ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client ok (681 + 44 + 15 + 2 + 2 + 2) tools/parity.py --changed origin/main 80 passed, 0 failed (56 min), one run over an integration commit of all the inventory PRs (this one included) ``` Independent of the other inventory PRs (based on main). 🤖 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:56:59 +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#2535
No description provided.