[PR #6298] [MERGED] Native mods: a mob's equipment changing, LivingEquipmentChangeEvent #6780

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

📋 Pull Request Information

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

Base: main ← Head: mods/living-equipment


📝 Commits (3)

  • 096802e Native mods: equipment changes of mobs (LivingEquipmentChangeEvent)
  • f9ef840 Native mods: read mobs' equipment only while a mod listens (native_living_equipment_listened)
  • 783f2d3 Merge remote-tracking branch 'hr/main' into mods/living-equipment

📊 Changes

8 files changed (+226 additions, -46 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/enchant_effects.rs (+23 -0)
📝 crates/horizon-client/src/game/lan.rs (+3 -46)
📝 crates/horizon-client/src/game/native_hooks.rs (+30 -0)
📝 crates/horizon-client/src/game/native_mobs.rs (+47 -0)
📝 crates/horizon-client/src/mobs.rs (+60 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+43 -0)
➕ tools/native-hook-fragments/living_equipment_change.json (+19 -0)

📄 Description

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

What and why

Fixes #6242, part of #4953 ("Living: breathing, and equipment changes of mobs (a player's are heard by on_equip)"), the equipment half. A mod that reacts to what a mob wears or holds (a mod armour set's bonus on a zombie, a mob picking up a mod item) had no hook; native_on_equip is for players.

One server hook point, API from a fragment (tools/native-hook-fragments/living_equipment_change.json):

  • native_living_equipment_change(entity, kind, slot, from, to) (LivingEquipmentChangeEvent): entity is the entity's ID and kind its type; slot is the EquipmentSlot name (mainhand, offhand, feet, legs, chest, head, body, saddle); from and to are the stacks (none for empty). It only hears.

How: each tick, after tick_creatures, native_mobs_equipment (game/native_mobs.rs) reads every ticking mob's equipment with the new Mob::equipment_stacks() and compares it with what the mods last heard (Extra::equipment_heard, empty at first as vanilla's lastEquipmentItems, kept with the mob), telling each slot that differs. mob_equipment, which builds the equipment a mob is sent to clients, now reads the same function instead of its own copy of the slot rules. For armor stands the comparison already existed for their location-based enchantments (armor_stand_location_effects, enchantment_equipment); the hook is told there from the same diff.

Choices a reviewer may want to look at:

  • Compared as stacks, like ItemStack.matches: a worn piece losing durability counts as a change, so a zombie burning in daylight tells its helmet (it does in vanilla too).
  • A mob new to the level counts from empty on its first tick, as in vanilla; a mob that comes back with its chunk does too (equipment_heard is not saved).
  • Only mobs in entity-ticking chunks are told, as only those tick.
  • Players keep native_on_equip (it also hears /item and the paths that never reach a tick). Not fired on a client of a server.

Kind

  • feature: something new for players (mod authors)

Vanilla reference

LivingEntity.tick calls detectEquipmentUpdates on the server every tick, which runs collectEquipmentChanges: each EquipmentSlot is compared with lastEquipmentItems by ItemStack.matches (the map starts empty). NeoForge's LivingEntity patch posts LivingEquipmentChangeEvent(entity, slot, previous, current) inside that loop for each changed slot. It cannot be cancelled.

Other projects' code

None. Names and contracts only from NeoForge's public LivingEquipmentChangeEvent.

Proof in the real game

Engine from this branch with a throwaway eprintln! in the hook body (not in this PR). A creative player on a platform; /summon and /item replace entity.

Server thread (horizon-ctl launch --world L --creative --offscreen):

summon minecraft:zombie 3 100 3 {NoAI:1b,PersistenceRequired:1b,equipment:{mainhand:{id:"minecraft:iron_sword",count:1},feet:{id:"minecraft:iron_boots",count:1}}}
TESTHOOK equip 452 minecraft:zombie mainhand None -> Some("minecraft:iron_sword")
TESTHOOK equip 452 minecraft:zombie feet None -> Some("minecraft:iron_boots")
item replace entity @e[type=minecraft:zombie,limit=1,sort=nearest] armor.head with minecraft:diamond_helmet
TESTHOOK equip 452 minecraft:zombie head None -> Some("minecraft:diamond_helmet")
item replace entity @e[type=minecraft:zombie,limit=1,sort=nearest] weapon.mainhand with minecraft:air
TESTHOOK equip 452 minecraft:zombie mainhand Some("minecraft:iron_sword") -> None
summon minecraft:armor_stand -3 100 3
item replace entity @e[type=minecraft:armor_stand,limit=1,sort=nearest] armor.chest with minecraft:iron_chestplate
TESTHOOK equip 514 minecraft:armor_stand chest None -> Some("minecraft:iron_chestplate")

Between those, the zombie in daylight told head Some("minecraft:diamond_helmet") -> Some("minecraft:diamond_helmet") now and then (the helmet's durability changing; the line prints item names only), and the natural skeletons told mainhand None -> Some("minecraft:bow") when they came into the level.

Dedicated server, a client connected as Alex (horizon-ctl connect), the same commands, and a saddled horse:

TESTHOOK equip 199 minecraft:zombie mainhand None -> Some("minecraft:iron_sword")
TESTHOOK equip 199 minecraft:zombie feet None -> Some("minecraft:iron_boots")
TESTHOOK equip 199 minecraft:zombie head None -> Some("minecraft:diamond_helmet")
TESTHOOK equip 199 minecraft:zombie mainhand Some("minecraft:iron_sword") -> None
TESTHOOK equip 201 minecraft:armor_stand chest None -> Some("minecraft:iron_chestplate")
TESTHOOK equip 202 minecraft:horse saddle None -> Some("minecraft:saddle")

The connected client printed nothing. Not run: a horse's armour in the body slot, a mob picking up an item, a hand swap of a mob.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at 455b6916b, 2 min 45 s)

Check Result
Scope ✅ 8 files, +203 −46
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (32 s)
rustfmt ✅ (9 s)
clippy ✅ (58 s)
tests: horizon-client ✅ 1806 passed (1 min 4 s)
doc tests ✅ 0 passed (1 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 ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 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/6298 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/living-equipment` --- ### 📝 Commits (3) - [`096802e`](https://github.com/horizon-rust/horizon/commit/096802ee36d86b25643c1ce51aaf9299abd05fbe) Native mods: equipment changes of mobs (LivingEquipmentChangeEvent) - [`f9ef840`](https://github.com/horizon-rust/horizon/commit/f9ef840898a74cce367d53277992eb68a0f38499) Native mods: read mobs' equipment only while a mod listens (native_living_equipment_listened) - [`783f2d3`](https://github.com/horizon-rust/horizon/commit/783f2d31ca7cd464bffe40b67c83a786b3103df9) Merge remote-tracking branch 'hr/main' into mods/living-equipment ### 📊 Changes **8 files changed** (+226 additions, -46 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/enchant_effects.rs` (+23 -0) 📝 `crates/horizon-client/src/game/lan.rs` (+3 -46) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+30 -0) 📝 `crates/horizon-client/src/game/native_mobs.rs` (+47 -0) 📝 `crates/horizon-client/src/mobs.rs` (+60 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+43 -0) ➕ `tools/native-hook-fragments/living_equipment_change.json` (+19 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. ## What and why Fixes #6242, part of #4953 ("Living: breathing, and equipment changes of mobs (a player's are heard by `on_equip`)"), the equipment half. A mod that reacts to what a mob wears or holds (a mod armour set's bonus on a zombie, a mob picking up a mod item) had no hook; `native_on_equip` is for players. One server hook point, API from a fragment (`tools/native-hook-fragments/living_equipment_change.json`): - `native_living_equipment_change(entity, kind, slot, from, to)` (`LivingEquipmentChangeEvent`): `entity` is the entity's ID and `kind` its type; `slot` is the `EquipmentSlot` name (`mainhand`, `offhand`, `feet`, `legs`, `chest`, `head`, `body`, `saddle`); `from` and `to` are the stacks (none for empty). It only hears. How: each tick, after `tick_creatures`, `native_mobs_equipment` (`game/native_mobs.rs`) reads every ticking mob's equipment with the new `Mob::equipment_stacks()` and compares it with what the mods last heard (`Extra::equipment_heard`, empty at first as vanilla's `lastEquipmentItems`, kept with the mob), telling each slot that differs. `mob_equipment`, which builds the equipment a mob is sent to clients, now reads the same function instead of its own copy of the slot rules. For armor stands the comparison already existed for their location-based enchantments (`armor_stand_location_effects`, `enchantment_equipment`); the hook is told there from the same diff. Choices a reviewer may want to look at: - Compared as stacks, like `ItemStack.matches`: a worn piece losing durability counts as a change, so a zombie burning in daylight tells its helmet (it does in vanilla too). - A mob new to the level counts from empty on its first tick, as in vanilla; a mob that comes back with its chunk does too (`equipment_heard` is not saved). - Only mobs in entity-ticking chunks are told, as only those tick. - Players keep `native_on_equip` (it also hears `/item` and the paths that never reach a tick). Not fired on a client of a server. ## Kind - [x] feature: something new for players (mod authors) ## Vanilla reference `LivingEntity.tick` calls `detectEquipmentUpdates` on the server every tick, which runs `collectEquipmentChanges`: each `EquipmentSlot` is compared with `lastEquipmentItems` by `ItemStack.matches` (the map starts empty). NeoForge's `LivingEntity` patch posts `LivingEquipmentChangeEvent(entity, slot, previous, current)` inside that loop for each changed slot. It cannot be cancelled. ## Other projects' code None. Names and contracts only from NeoForge's public `LivingEquipmentChangeEvent`. ## Proof in the real game Engine from this branch with a throwaway `eprintln!` in the hook body (not in this PR). A creative player on a platform; `/summon` and `/item replace entity`. Server thread (`horizon-ctl launch --world L --creative --offscreen`): ``` summon minecraft:zombie 3 100 3 {NoAI:1b,PersistenceRequired:1b,equipment:{mainhand:{id:"minecraft:iron_sword",count:1},feet:{id:"minecraft:iron_boots",count:1}}} TESTHOOK equip 452 minecraft:zombie mainhand None -> Some("minecraft:iron_sword") TESTHOOK equip 452 minecraft:zombie feet None -> Some("minecraft:iron_boots") item replace entity @e[type=minecraft:zombie,limit=1,sort=nearest] armor.head with minecraft:diamond_helmet TESTHOOK equip 452 minecraft:zombie head None -> Some("minecraft:diamond_helmet") item replace entity @e[type=minecraft:zombie,limit=1,sort=nearest] weapon.mainhand with minecraft:air TESTHOOK equip 452 minecraft:zombie mainhand Some("minecraft:iron_sword") -> None summon minecraft:armor_stand -3 100 3 item replace entity @e[type=minecraft:armor_stand,limit=1,sort=nearest] armor.chest with minecraft:iron_chestplate TESTHOOK equip 514 minecraft:armor_stand chest None -> Some("minecraft:iron_chestplate") ``` Between those, the zombie in daylight told `head Some("minecraft:diamond_helmet") -> Some("minecraft:diamond_helmet")` now and then (the helmet's durability changing; the line prints item names only), and the natural skeletons told `mainhand None -> Some("minecraft:bow")` when they came into the level. Dedicated server, a client connected as Alex (`horizon-ctl connect`), the same commands, and a saddled horse: ``` TESTHOOK equip 199 minecraft:zombie mainhand None -> Some("minecraft:iron_sword") TESTHOOK equip 199 minecraft:zombie feet None -> Some("minecraft:iron_boots") TESTHOOK equip 199 minecraft:zombie head None -> Some("minecraft:diamond_helmet") TESTHOOK equip 199 minecraft:zombie mainhand Some("minecraft:iron_sword") -> None TESTHOOK equip 201 minecraft:armor_stand chest None -> Some("minecraft:iron_chestplate") TESTHOOK equip 202 minecraft:horse saddle None -> Some("minecraft:saddle") ``` The connected client printed nothing. Not run: a horse's armour in the `body` slot, a mob picking up an item, a hand swap of a mob. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at 455b6916b, 2 min 45 s) | Check | Result | | --- | --- | | Scope | ✅ 8 files, +203 −46 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (32 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (58 s) | | tests: horizon-client | ✅ 1806 passed (1 min 4 s) | | doc tests | ✅ 0 passed (1 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 | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 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 06:26:29 +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#6780
No description provided.