[PR #5588] [MERGED] Native mods: custom dispenser item behaviours #6371

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5588
Author: @Xmilon
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: native/dispenser-behaviour


📝 Commits (2)

  • d3ad6d7 feat(mods): add custom dispenser item behaviours
  • 15b7ff9 Dispenser hook: the answer carries its level event; API markers; stamp keeps side

📊 Changes

6 files changed (+127 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/dispenser.rs (+75 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+19 -0)
📝 tests/test_stamp_native_hooks.py (+12 -0)
📝 tools/native-hook-fragments/README.md (+3 -0)
➕ tools/native-hook-fragments/dispenser_behaviour.json (+14 -0)
📝 tools/stamp_native_hooks.py (+4 -1)

📄 Description

🤖 Opened by Xmilon's AI agent (Codex, GPT-6), not by Xmilon personally.

What and why

Fixes #5531. Part of #4953.

A native mod can choose what a dispenser does with any item, including a vanilla item it wants to override. The new dispense_item catalog hook receives the server dimension, dispenser position, facing and selected stack before the vanilla behavior runs.

  • Leave answer as None: run the existing behavior unchanged.
  • Some(None): handled, empty the selected slot.
  • Some(Some(stack)): handled, write exactly that remainder, without consuming an additional item. A zero-count remainder becomes an empty slot.
  • Some(self.native_dispense_default(dimension, pos, facing, stack.clone())): drop one item through the existing plain-drop path. For example, a mod can make a dispenser drop a TNT item instead of priming it.

Handled actions get the default click/smoke once. The helper only executes the plain drop; it does not play those events again. It keeps the input on clients, for a different dimension or an unloaded chunk. The hook only runs on authoritative servers; droppers keep their separate existing path.

Registration uses a pending fragment (dispenser_behaviour.json), not a handwritten API number or generated catalog edit. A mod registers its handler through the named hook and answers for the item IDs it owns/wants to replace.

Kind

  • feature: something new for players

Vanilla reference

Horizon-only native hook at the existing DispenserBlock.getDispenseMethod / DispenseItemBehavior.dispense dispatch. native_dispense_default reuses the port's DefaultDispenseItemBehavior.execute, including its position, velocity and random draws; no vanilla algorithm is rewritten. Existing dispenser parity covers that path. No prepared vanilla bytecode/resources in this worktree, so no real-game/server or local vanilla parity run was performed.

Other projects' code

None.

Self-check

Windows, RUST_MIN_STACK=33554432, -j1:

  • cargo fmt --all -- --check: pass.
  • cargo clippy -p horizon-client --lib --bins --tests -- -D warnings: pass.
  • Hook-fragment tool tests: 3 passed.
  • Added mod_dispenser_answers_preserve_fallback_and_own_consumption: no answer keeps vanilla, explicit consumption empties the slot, a handled remainder is preserved without another shrink, and zero count normalizes to empty. The client test target passed in upstream CI; it was not executed locally under this contributor's build constraints.
  • Upstream CI verify passed at d3ad6d73c, including workspace linting and tests: https://github.com/horizon-rust/horizon/actions/runs/41254869069. Launcher reported success with its checks skipped because this change does not affect launcher dependencies. Parity jobs were skipped.
  • No dependency, launcher UI, player data or installed-game changes.

🤖 Generated with Codex


🔄 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/5588 **Author:** [@Xmilon](https://github.com/Xmilon) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `native/dispenser-behaviour` --- ### 📝 Commits (2) - [`d3ad6d7`](https://github.com/horizon-rust/horizon/commit/d3ad6d73cd631aa4f1d0a1816b99d3e89b660c46) feat(mods): add custom dispenser item behaviours - [`15b7ff9`](https://github.com/horizon-rust/horizon/commit/15b7ff9a6907123d7aee5b6a4c99df633d5d4159) Dispenser hook: the answer carries its level event; API markers; stamp keeps side ### 📊 Changes **6 files changed** (+127 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/dispenser.rs` (+75 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+19 -0) 📝 `tests/test_stamp_native_hooks.py` (+12 -0) 📝 `tools/native-hook-fragments/README.md` (+3 -0) ➕ `tools/native-hook-fragments/dispenser_behaviour.json` (+14 -0) 📝 `tools/stamp_native_hooks.py` (+4 -1) </details> ### 📄 Description > 🤖 Opened by Xmilon's AI agent (Codex, GPT-6), not by Xmilon personally. ## What and why Fixes #5531. Part of #4953. A native mod can choose what a dispenser does with any item, including a vanilla item it wants to override. The new `dispense_item` catalog hook receives the server dimension, dispenser position, facing and selected stack before the vanilla behavior runs. - Leave `answer` as `None`: run the existing behavior unchanged. - `Some(None)`: handled, empty the selected slot. - `Some(Some(stack))`: handled, write exactly that remainder, without consuming an additional item. A zero-count remainder becomes an empty slot. - `Some(self.native_dispense_default(dimension, pos, facing, stack.clone()))`: drop one item through the existing plain-drop path. For example, a mod can make a dispenser drop a TNT item instead of priming it. Handled actions get the default click/smoke once. The helper only executes the plain drop; it does not play those events again. It keeps the input on clients, for a different dimension or an unloaded chunk. The hook only runs on authoritative servers; droppers keep their separate existing path. Registration uses a pending fragment (`dispenser_behaviour.json`), not a handwritten API number or generated catalog edit. A mod registers its handler through the named hook and answers for the item IDs it owns/wants to replace. ## Kind - [x] feature: something new for players ## Vanilla reference Horizon-only native hook at the existing DispenserBlock.getDispenseMethod / DispenseItemBehavior.dispense dispatch. `native_dispense_default` reuses the port's DefaultDispenseItemBehavior.execute, including its position, velocity and random draws; no vanilla algorithm is rewritten. Existing `dispenser` parity covers that path. No prepared vanilla bytecode/resources in this worktree, so no real-game/server or local vanilla parity run was performed. ## Other projects' code None. ## Self-check Windows, RUST_MIN_STACK=33554432, -j1: - cargo fmt --all -- --check: pass. - cargo clippy -p horizon-client --lib --bins --tests -- -D warnings: pass. - Hook-fragment tool tests: 3 passed. - Added `mod_dispenser_answers_preserve_fallback_and_own_consumption`: no answer keeps vanilla, explicit consumption empties the slot, a handled remainder is preserved without another shrink, and zero count normalizes to empty. The client test target passed in upstream CI; it was not executed locally under this contributor's build constraints. - Upstream CI verify passed at d3ad6d73c, including workspace linting and tests: https://github.com/horizon-rust/horizon/actions/runs/41254869069. Launcher reported success with its checks skipped because this change does not affect launcher dependencies. Parity jobs were skipped. - No dependency, launcher UI, player data or installed-game changes. 🤖 Generated with [Codex](https://openai.com/codex/) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:19:18 +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#6371
No description provided.