[PR #7715] Native hooks: living_death, living_conversion_pre, living_conversion_post #7781

Open
opened 2026-11-03 07:24:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7715
Author: @levzzz5154
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: native/living-death-conversion


📝 Commits (1)

  • ed024da Native hooks: living_death, living_conversion_pre, living_conversion_post

📊 Changes

10 files changed (+396 additions, -16 deletions)

View changed files

📝 crates/horizon-client/src/game/combat.rs (+6 -0)
📝 crates/horizon-client/src/game/creatures.rs (+52 -0)
📝 crates/horizon-client/src/game/dispenser.rs (+28 -14)
📝 crates/horizon-client/src/game/lan_actions.rs (+28 -0)
📝 crates/horizon-client/src/game/lightning.rs (+17 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+75 -0)
📝 crates/horizon-client/src/mod_api/generated.rs (+140 -0)
➕ tools/native-hook-fragments/living_conversion_post.json (+16 -0)
➕ tools/native-hook-fragments/living_conversion_pre.json (+17 -0)
➕ tools/native-hook-fragments/living_death.json (+17 -0)

📄 Description

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

Part of #4953: LivingDeathEvent, LivingConversionEvent.Pre, LivingConversionEvent.Post.

What it adds

All three run on the server.

  • living_death (LivingDeathEvent, cancellable): native_living_death(entity, kind, damage_type, attacker, cancel). Fires from Game::mob_died for every mob, and from guest_die for every server player, when health has run out and before loot, experience and the death message. damage_type is the last blow's id; attacker is the mob id that dealt it (a guest's entity id for a player's kill of a mob; 0 for none or when unknown). Cancel keeps the entity alive at 1 health: Horizon decides death from health, so there is no "alive at 0 health" state to keep. Armor stands, boats and other non-mob entities are not told. player_died (listen) and mob_killed (a player's blow) stay as they are.
  • living_conversion_pre (LivingConversionEvent.Pre, cancellable): native_living_conversion_pre(entity, kind, outcome, cancel). Fires before the shared convert_to (zombie to drowned, husk to zombie, piglin and hoglin to zombified, tadpole to frog), the dispenser's mooshroom shear (convert_mob), and lightning on a pig or villager. Cancel keeps the mob: the removal the mob's own tick already made is undone; a canceled mooshroom shear drops nothing (vanilla's drops are in convertTo's callback); a canceled lightning conversion falls to the normal lightning fire and damage, as super.thunderHit. A drowning zombie's timers are spent, so it counts up again while it stays in water.
  • living_conversion_post (LivingConversionEvent.Post, listen): native_living_conversion_post(entity, kind, converted, converted_kind), after the new mob joined. It fires beside the existing entity_transform (API 223) in convert_to and convert_mob. convert_mob did not tell entity_transform before; it does now, as vanilla's convertTo is the same call.

Not covered: a player shearing a mooshroom, a zombie turning a villager, a zombie villager's cure, and lightning conversions (they spawn through SpawnKind events, so no Post and no new id there; Pre is told). Also MobSplitEvent and BabyEntitySpawnEvent: left for another PR.

Fragments: tools/native-hook-fragments/living_{death,conversion_pre,conversion_post}.json. Without mods the death and conversion hooks cost an empty-slice check (mob_death_canceled, guest_die) or an empty dispatch; no random draws moved.

Proof

A throwaway hook body (removed before the commit) printed the call and forced cancel when TESTHOOK_CANCEL was set. Offscreen game on the server thread, scratch homes, difficulty normal, night:
summon zombie {DrownedConversionTime:20,InWaterTime:100} in a glass water box, summon villager then summon lightning_bolt, summon zombie/cow then kill, gamemode survival then kill @p.

No cancel:

TESTHOOK conv_pre 397 minecraft:zombie -> minecraft:drowned
TESTHOOK conv_post 397 minecraft:zombie -> 404 minecraft:drowned
TESTHOOK conv_pre 398 minecraft:villager -> minecraft:witch
TESTHOOK death 400 minecraft:zombie minecraft:generic attacker=0
TESTHOOK death 401 minecraft:cow minecraft:generic attacker=0
TESTHOOK death 1 minecraft:player minecraft:generic_kill attacker=0

Afterwards: a drowned and a witch exist, the zombie, villager and cow are gone, the player's Health is 0.

Forced cancel: the same hook lines appear (the villager is struck on each lightning tick, so conv_pre repeats, as vanilla's bolt hits an entity on each of its flash ticks). Afterwards the zombie, the water zombie, the villager and the cow are all still there, no drowned and no witch, and the player has Health 4.0 three seconds after /kill @p (1 health, then regeneration).

Mobs killed by mobs show damage_type=minecraft:mob_attack attacker=<mob id>, and /kill on a mob shows minecraft:generic.

Not run: the dispenser mooshroom shear in game (same function, convert_mob); a dedicated server; mod-side Hooks impls (the generated dispatch compiles and mod API up to date passes).

Check Result
Scope ✅ 10 files, +396 −16
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (38 s)
rustfmt ✅ (9 s)
clippy ✅ (1 min 20 s)
tests: horizon-client, horizon-client-lib ✅ 2175 passed (1 min 18 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ✅ (12 s)
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
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Known limits (lead review)

  • A cancelled mob death keeps the mob alive at 1 health, but what its tick already sent stays sent: the death sound, and for a mob with effects the on-death effects.
  • A frog's tongue still removes a mob whose death a mod cancelled, as eatEntity removes it after the bite.

🤖 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/7715 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `native/living-death-conversion` --- ### 📝 Commits (1) - [`ed024da`](https://github.com/horizon-rust/horizon/commit/ed024da92fafa8a52151715e2825d795ad8bfa3e) Native hooks: living_death, living_conversion_pre, living_conversion_post ### 📊 Changes **10 files changed** (+396 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/combat.rs` (+6 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+52 -0) 📝 `crates/horizon-client/src/game/dispenser.rs` (+28 -14) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+28 -0) 📝 `crates/horizon-client/src/game/lightning.rs` (+17 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+75 -0) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+140 -0) ➕ `tools/native-hook-fragments/living_conversion_post.json` (+16 -0) ➕ `tools/native-hook-fragments/living_conversion_pre.json` (+17 -0) ➕ `tools/native-hook-fragments/living_death.json` (+17 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #4953: `LivingDeathEvent`, `LivingConversionEvent.Pre`, `LivingConversionEvent.Post`. ## What it adds All three run on the server. - **`living_death`** (`LivingDeathEvent`, cancellable): `native_living_death(entity, kind, damage_type, attacker, cancel)`. Fires from `Game::mob_died` for every mob, and from `guest_die` for every server player, when health has run out and before loot, experience and the death message. `damage_type` is the last blow's id; `attacker` is the mob id that dealt it (a guest's entity id for a player's kill of a mob; 0 for none or when unknown). Cancel keeps the entity alive at 1 health: Horizon decides death from health, so there is no "alive at 0 health" state to keep. Armor stands, boats and other non-mob entities are not told. `player_died` (listen) and `mob_killed` (a player's blow) stay as they are. - **`living_conversion_pre`** (`LivingConversionEvent.Pre`, cancellable): `native_living_conversion_pre(entity, kind, outcome, cancel)`. Fires before the shared `convert_to` (zombie to drowned, husk to zombie, piglin and hoglin to zombified, tadpole to frog), the dispenser's mooshroom shear (`convert_mob`), and lightning on a pig or villager. Cancel keeps the mob: the removal the mob's own tick already made is undone; a canceled mooshroom shear drops nothing (vanilla's drops are in `convertTo`'s callback); a canceled lightning conversion falls to the normal lightning fire and damage, as `super.thunderHit`. A drowning zombie's timers are spent, so it counts up again while it stays in water. - **`living_conversion_post`** (`LivingConversionEvent.Post`, listen): `native_living_conversion_post(entity, kind, converted, converted_kind)`, after the new mob joined. It fires beside the existing `entity_transform` (API 223) in `convert_to` and `convert_mob`. `convert_mob` did not tell `entity_transform` before; it does now, as vanilla's `convertTo` is the same call. Not covered: a player shearing a mooshroom, a zombie turning a villager, a zombie villager's cure, and lightning conversions (they spawn through `SpawnKind` events, so no Post and no new id there; Pre is told). Also `MobSplitEvent` and `BabyEntitySpawnEvent`: left for another PR. Fragments: `tools/native-hook-fragments/living_{death,conversion_pre,conversion_post}.json`. Without mods the death and conversion hooks cost an empty-slice check (`mob_death_canceled`, `guest_die`) or an empty dispatch; no random draws moved. ## Proof A throwaway hook body (removed before the commit) printed the call and forced `cancel` when `TESTHOOK_CANCEL` was set. Offscreen game on the server thread, scratch homes, `difficulty normal`, night: `summon zombie {DrownedConversionTime:20,InWaterTime:100}` in a glass water box, `summon villager` then `summon lightning_bolt`, `summon zombie`/`cow` then `kill`, `gamemode survival` then `kill @p`. No cancel: ``` TESTHOOK conv_pre 397 minecraft:zombie -> minecraft:drowned TESTHOOK conv_post 397 minecraft:zombie -> 404 minecraft:drowned TESTHOOK conv_pre 398 minecraft:villager -> minecraft:witch TESTHOOK death 400 minecraft:zombie minecraft:generic attacker=0 TESTHOOK death 401 minecraft:cow minecraft:generic attacker=0 TESTHOOK death 1 minecraft:player minecraft:generic_kill attacker=0 ``` Afterwards: a drowned and a witch exist, the zombie, villager and cow are gone, the player's Health is 0. Forced cancel: the same hook lines appear (the villager is struck on each lightning tick, so `conv_pre` repeats, as vanilla's bolt hits an entity on each of its flash ticks). Afterwards the zombie, the water zombie, the villager and the cow are all still there, no drowned and no witch, and the player has Health 4.0 three seconds after `/kill @p` (1 health, then regeneration). Mobs killed by mobs show `damage_type=minecraft:mob_attack attacker=<mob id>`, and `/kill` on a mob shows `minecraft:generic`. Not run: the dispenser mooshroom shear in game (same function, `convert_mob`); a dedicated server; mod-side `Hooks` impls (the generated dispatch compiles and `mod API up to date` passes). | Check | Result | | --- | --- | | Scope | ✅ 10 files, +396 −16 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (38 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (1 min 20 s) | | tests: horizon-client, horizon-client-lib | ✅ 2175 passed (1 min 18 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (12 s) | | 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 | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Known limits (lead review) - A cancelled mob death keeps the mob alive at 1 health, but what its tick already sent stays sent: the death sound, and for a mob with effects the on-death effects. - A frog's tongue still removes a mob whose death a mod cancelled, as `eatEntity` removes it after the bite. 🤖 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>
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#7781
No description provided.