[PR #4519] [MERGED] Native mods: the acting player's plain items for server mods (API 9) #5672

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

📋 Pull Request Information

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

Base: main ← Head: feat/smp-item-helpers


📝 Commits (4)

  • 076c41f Native mods: server commands and players (API 8)
  • 768d20d Native mods: a server player's game mode
  • b070f41 Native mods: the acting player's plain items for server mods (API 9)
  • 396f456 Native mods: the items test follows getFreeSlot's empty off hand

📊 Changes

9 files changed (+810 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/lan.rs (+5 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+19 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+32 -2)
➕ crates/horizon-client/src/game/native_server.rs (+697 -0)
📝 crates/horizon-client/src/lan/commands.rs (+5 -0)
📝 crates/horizon-client/src/lan/hub.rs (+5 -0)
📝 docs/native-mods.md (+36 -0)
📝 native-hooks.json (+10 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Stacked on #4514 (API 8): review only the last two commits.

What and why

The acting player's items for server mods (API 9): what a server shop needs, used by the official server's SMP market (docs/smp.md, #4494; the mod is horizon-rust/horizon-mods#56). General: any server mod that sells, buys, rewards or charges items can use them.

Helpers in game/native_server.rs, for the player whose command a hook hears (inside native_perform_command, their state swapped in):

  • native_held(): the main hand's item id, count, and whether it is plain;
  • native_count_items(item), native_carried_items();
  • native_take_items(item, count): the main hand first, then Inventory.add's slot order; returns what it took;
  • native_room_for(item), native_give_items(item, count): only where it fits (nothing is dropped), onto matching stacks first (getSlotWithRemainingSpace, the off hand's included), then empty inventory slots (getFreeSlot, never an empty off hand); returns what it gave.

They look at the 36 inventory slots and the off hand, never the armour, and only at plain stacks (no damage, no component), so a shop never prices a worn or enchanted item as a new one. Changes reach the player's screen through the inventory's usual sync. Unit tests cover the slot order, the plain-only rule and the fit.

NATIVE_HOOKS_API 8 → 9; docs/native-mods.md.

Kind

  • extra: Horizon-only, off by default

Vanilla reference

Inventory.add → getSlotWithRemainingSpace (selected, off hand, 0..36) and getFreeSlot (0..36). Nothing calls these helpers in Horizon itself.

Proof

native/tools/native.py proof smp on this branch (b070f41): a dedicated server built with the SMP mod (economy + market) and two real clients. Steve, in survival, was given 3 diamonds and 20 wheat from the console, then ran /sell wheat ("Sold 20 wheat for 20 coins."), /sell hand ("Sold 3 diamond for 300 coins.") and /buy torch 5. His own client's inventory then showed {"minecraft:torch": 5}: the diamonds and wheat were gone, the torches there. A creative Alex was refused /sell all. economy.json and audit.log matched after a clean stop, and the balance was the same after a restart.

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at f6a757ac2, 5 min 21 s)

Check Result
Scope ⚠️ 9 files, +810 −4; 778 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅ (1 s)
Python tests ✅ 481 passed (1 min 31 s)
rustfmt ✅ (4 s)
clippy ✅ (7 s)
tests: horizon-client ✅ 1069 passed (3 min 3 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 ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The scope counts #4514's commits too (stacked); this PR's own commits are ~270 lines.

🤖 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/4519 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/smp-item-helpers` --- ### 📝 Commits (4) - [`076c41f`](https://github.com/horizon-rust/horizon/commit/076c41fc27336c8ba886471bf3a1ced1b76c9b3d) Native mods: server commands and players (API 8) - [`768d20d`](https://github.com/horizon-rust/horizon/commit/768d20d9980c2e04cc76951d18ec6c72ccef0176) Native mods: a server player's game mode - [`b070f41`](https://github.com/horizon-rust/horizon/commit/b070f41ddae470df36694dff7f176bdda2a3ad90) Native mods: the acting player's plain items for server mods (API 9) - [`396f456`](https://github.com/horizon-rust/horizon/commit/396f456556dd423454fc93cca65463716e1e1976) Native mods: the items test follows getFreeSlot's empty off hand ### 📊 Changes **9 files changed** (+810 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+5 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+19 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+32 -2) ➕ `crates/horizon-client/src/game/native_server.rs` (+697 -0) 📝 `crates/horizon-client/src/lan/commands.rs` (+5 -0) 📝 `crates/horizon-client/src/lan/hub.rs` (+5 -0) 📝 `docs/native-mods.md` (+36 -0) 📝 `native-hooks.json` (+10 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Stacked on #4514 (API 8): review only the last two commits.** ## What and why The acting player's items for server mods (API 9): what a server shop needs, used by the official server's SMP market ([docs/smp.md](https://github.com/horizon-rust/horizon/blob/feat/smp-design/docs/smp.md), #4494; the mod is horizon-rust/horizon-mods#56). General: any server mod that sells, buys, rewards or charges items can use them. Helpers in `game/native_server.rs`, for the player whose command a hook hears (inside `native_perform_command`, their state swapped in): - `native_held()`: the main hand's item id, count, and whether it is plain; - `native_count_items(item)`, `native_carried_items()`; - `native_take_items(item, count)`: the main hand first, then `Inventory.add`'s slot order; returns what it took; - `native_room_for(item)`, `native_give_items(item, count)`: only where it fits (nothing is dropped), onto matching stacks first (`getSlotWithRemainingSpace`, the off hand's included), then empty inventory slots (`getFreeSlot`, never an empty off hand); returns what it gave. They look at the 36 inventory slots and the off hand, never the armour, and only at **plain** stacks (no damage, no component), so a shop never prices a worn or enchanted item as a new one. Changes reach the player's screen through the inventory's usual sync. Unit tests cover the slot order, the plain-only rule and the fit. `NATIVE_HOOKS_API` 8 → 9; docs/native-mods.md. ## Kind - [x] extra: Horizon-only, off by default ## Vanilla reference `Inventory.add` → `getSlotWithRemainingSpace` (selected, off hand, 0..36) and `getFreeSlot` (0..36). Nothing calls these helpers in Horizon itself. ## Proof `native/tools/native.py proof smp` on this branch (b070f41): a dedicated server built with the SMP mod (economy + market) and two real clients. Steve, in survival, was given 3 diamonds and 20 wheat from the console, then ran `/sell wheat` ("Sold 20 wheat for 20 coins."), `/sell hand` ("Sold 3 diamond for 300 coins.") and `/buy torch 5`. His own client's `inventory` then showed `{"minecraft:torch": 5}`: the diamonds and wheat were gone, the torches there. A creative Alex was refused `/sell all`. `economy.json` and `audit.log` matched after a clean stop, and the balance was the same after a restart. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at f6a757ac2, 5 min 21 s) | Check | Result | | --- | --- | | Scope | ⚠️ 9 files, +810 −4; 778 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ (1 s) | | Python tests | ✅ 481 passed (1 min 31 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (7 s) | | tests: horizon-client | ✅ 1069 passed (3 min 3 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 | ➖ 33 affected, to run in CI (--quick): block_removal, command_exec, composter, crafter, cursor_death, dedicated_server, dispenser, forced_end, friends_integration, hardcore_respawn, lan_integration, locator_bar and 21 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The scope counts #4514's commits too (stacked); this PR's own commits are ~270 lines. 🤖 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:14:14 +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#5672
No description provided.