[PR #6534] [MERGED] Native mods: a player's item losing durability, changeable (native_item_damaged, part of #5816) #6940

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

📋 Pull Request Information

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

Base: main ← Head: feat-item-damaged-hook


📝 Commits (1)

  • e8b62ad Native mods: a player's item losing durability, changeable (native_item_damaged)

📊 Changes

4 files changed (+49 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/game/enchant_effects.rs (+11 -1)
📝 crates/horizon-client/src/game/native_hooks.rs (+21 -0)
📝 docs/native-mods.md (+5 -0)
➕ tools/native-hook-fragments/native_item_damaged.json (+12 -0)

📄 Description

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

What and why

Part of #5816 (hook points a survival server's native mods need). A mod could not see, change or refuse durability loss of a player's tools and armour.

  • New hook point native_item_damaged(player, name, item, amount, cancel) (fragment native_item_damaged.json, docs paragraph). Called from wear() (enchant_effects.rs) after Unbreaking, with the player's state swapped in. A mod can change amount or set cancel (no damage component is added).
  • Nothing changes when no mod hooks it.

Kind

  • feature (new native hook point)

Vanilla reference

ItemStack.hurtAndBreak; NeoForge/Bukkit equivalent: PlayerItemDamageEvent.

Other projects' code

none. (Tested with a throwaway horizon-mixins bundle, not part of this PR.)

Proof on a real dedicated server

Engine from the batch branch this commit comes from, plus a throwaway bundle; a bare protocol client wears an iron chestplate and holds a hoe and a fishing rod.

control (no action)                         -> no hook line
hit while wearing the chestplate            -> hook: item_damaged item=minecraft:iron_chestplate amount=1; damage 1
the mod sets amount 5                       -> armor damage 5
the mod cancelling                          -> no damage component
hoe and fishing rod                         -> same hook

Not covered: mob armour and dispenser tool wear, the LAN host as a player.

Self-check

pr_ready --quick --base upstream/main ran once on the whole branch that carries this and four other hook commits (11 files, +267 −3): Python tests 586 passed, rustfmt, clippy, horizon-client tests 1809 passed, doc tests pass; parity not run (--quick). This PR is that commit cherry-picked onto current main (4 files changed, 49 insertions(+), 1 deletion(-)): cargo test -p horizon-client native_hooks passes (21 passed).


🔄 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/6534 **Author:** [@Detimes](https://github.com/Detimes) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat-item-damaged-hook` --- ### 📝 Commits (1) - [`e8b62ad`](https://github.com/horizon-rust/horizon/commit/e8b62addbedb47899f3b3880f389ac5f0cd2850a) Native mods: a player's item losing durability, changeable (native_item_damaged) ### 📊 Changes **4 files changed** (+49 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/enchant_effects.rs` (+11 -1) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+21 -0) 📝 `docs/native-mods.md` (+5 -0) ➕ `tools/native-hook-fragments/native_item_damaged.json` (+12 -0) </details> ### 📄 Description > 🤖 Opened by Detimes' AI agent (Claude Code, Claude Sonnet 5.5), not by Detimes personally. ## What and why Part of #5816 (hook points a survival server's native mods need). A mod could not see, change or refuse durability loss of a player's tools and armour. - New hook point `native_item_damaged(player, name, item, amount, cancel)` (fragment `native_item_damaged.json`, docs paragraph). Called from `wear()` (`enchant_effects.rs`) after Unbreaking, with the player's state swapped in. A mod can change `amount` or set `cancel` (no damage component is added). - Nothing changes when no mod hooks it. ## Kind - [x] feature (new native hook point) ## Vanilla reference `ItemStack.hurtAndBreak`; NeoForge/Bukkit equivalent: `PlayerItemDamageEvent`. ## Other projects' code none. (Tested with a throwaway horizon-mixins bundle, not part of this PR.) ## Proof on a real dedicated server Engine from the batch branch this commit comes from, plus a throwaway bundle; a bare protocol client wears an iron chestplate and holds a hoe and a fishing rod. ``` control (no action) -> no hook line hit while wearing the chestplate -> hook: item_damaged item=minecraft:iron_chestplate amount=1; damage 1 the mod sets amount 5 -> armor damage 5 the mod cancelling -> no damage component hoe and fishing rod -> same hook ``` Not covered: mob armour and dispenser tool wear, the LAN host as a player. ## Self-check `pr_ready --quick --base upstream/main` ran once on the whole branch that carries this and four other hook commits (11 files, +267 −3): Python tests 586 passed, rustfmt, clippy, `horizon-client` tests 1809 passed, doc tests pass; parity not run (`--quick`). This PR is that commit cherry-picked onto current main (4 files changed, 49 insertions(+), 1 deletion(-)): `cargo test -p horizon-client native_hooks` passes (21 passed). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:29:42 +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#6940
No description provided.