[PR #5174] [MERGED] feat(mods): native mods give their mob effects behaviour #6120

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

📋 Pull Request Information

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

Base: main ← Head: feat/mod-mob-effect-hooks


📝 Commits (2)

  • e3308bf feat(mods): native mods give their mob effects behaviour
  • f67740a Merge remote-tracking branch 'origin/main' into sweep/5174-m3

📊 Changes

14 files changed (+244 additions, -24 deletions)

View changed files

📝 crates/horizon-client-core/src/potions.rs (+8 -0)
📝 crates/horizon-client-render/src/brewing.rs (+2 -1)
📝 crates/horizon-client-render/src/effects.rs (+39 -9)
📝 crates/horizon-client/examples/probe/mob_ai_probe.rs (+1 -0)
📝 crates/horizon-client/src/game/commands/effects.rs (+2 -0)
📝 crates/horizon-client/src/game/creatures.rs (+6 -0)
📝 crates/horizon-client/src/game/enchant_effects.rs (+2 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+54 -0)
📝 crates/horizon-client/src/game/potions.rs (+79 -9)
📝 crates/horizon-client/src/mobs.rs (+8 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+19 -5)
📝 crates/horizon-client/src/mobs/world.rs (+1 -0)
📝 crates/horizon-client/src/mobs/zombie_villager.rs (+1 -0)
➕ tools/native-hook-fragments/mob_effect_hooks.json (+22 -0)

📄 Description

What and why

#4840 lets a content mod declare its own mob effects, but they do nothing yet: they only count down and go

A native mod can now give them their behaviour, through four hook points
native_should_apply_effect_tick_this_tick(effect, tick_count, amplifier, apply) is shouldApplyEffectTickThisTick, and vanilla's base answer is no
native_apply_effect_tick(effect, dimension, entity, amplifier, keep) is applyEffectTick, and clearing keep ends the effect
native_on_effect_added(effect, entity, amplifier) is onEffectAdded, only when the entity didn't have the effect
native_mob_effect_added(effect, entity, amplifier) is onEffectStarted, every time the effect is given, new or not

I was going to use the vanilla name (MobEffect.onEffectStarted), but the docs (#4402) name a hook after its NeoForge event, so it's mob_effect_added
NeoForge's MobEffectEvent.Added can carry a previous instance, so I think it fires on every add, as onEffectStarted does
The other three keep vanilla's names, since NeoForge's mob effects docs have no event for them
Its effects override MobEffect's methods directly, and rule 1 says a hook with no counterpart keeps a Horizon name

The tick hooks run where vanilla runs them, in LivingEntity.tickEffects during the entity's baseTick, for players and mobs
For each effect the order is vanilla's MobEffectInstance.tickServer: the should-apply check, then apply, then the countdown, and a false from apply removes the effect before it counts down
An infinite effect gets the entity's tick count, as in vanilla, and one with no ticks left goes without asking
The add hooks run inside LivingEntity.addEffect, after the effect's attribute modifiers, in vanilla's order
A mob is its Entity.getId, a player None, with their state swapped in so native_acting_player names them

The two tick hooks take &self
A mob's effects tick inside its own tick, where the mob world borrows the game, so &mut self would alias that borrow
The ticking mobs are out of Game::mobs then, and a player's effects are out of the game while they tick
This is the one real difference from vanilla, whose applyEffectTick can change the entity, so a mod records what to do and acts from another hook
The add hooks take &mut self

Only content mods' effects reach the hooks
Vanilla's effects keep their own code
Server side only: the server thread, a LAN host and dedicated servers
A server's client never calls them, including for the mount it steers

Effects reach a mob through /effect give, a thrown potion or a tipped arrow, a creeper's lingering cloud, and an enchantment's apply_mob_effect, and each of those calls the add hooks
I think the other places that give mobs effects only use vanilla's
forceAddEffect calls neither hook, as in vanilla

In vanilla the effects tick in the order of a HashMap keyed by effect, which I think comes down to identity hashes, and Horizon ticks them in the order they were given

Without a mod nothing changes: in an optimized build no hook symbol is left, the add sites have no trace of the id check, and the player's effect tick keeps only the check on the effects it already asked about
A mob's tick gets one id check per effect that isn't poison, wither or regeneration, and an indirect call only for a content mod's effect

Adds the hook fragment tools/native-hook-fragments/mob_effect_hooks.json
The stamp sets the API number after merge

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

MobEffect.applyEffectTick, shouldApplyEffectTickThisTick, onEffectStarted, onEffectAdded (world/effect/MobEffect.java:82, :92, :96, :99)
MobEffectInstance.tickServer (world/effect/MobEffectInstance.java:224-241)
LivingEntity.baseTick calls tickEffects (world/entity/LivingEntity.java:513, :859-875)
LivingEntity.addEffect (world/entity/LivingEntity.java:1025-1043)
NeoForge's MobEffectEvent.Added and the overridden MobEffect methods: https://docs.neoforged.net/docs/items/mobeffects/ (Events)

Other projects' code

none

Self-check

The 7 failures are all in tests/lan_bot.rs (status_and_join, guests_see_each_other_and_the_world_entities and 5 more), they fail on main too with prepared data (b8f8c2515)
With --no-fail-fast the same tests give 2184 passed, and only these 7 fail

Check Result
Scope ✅ 14 files, +244 −24
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 499 passed (1 min 1 s)
rustfmt ✅ (8 s)
clippy ✅ (2 min 8 s)
tests: horizon-client, horizon-client-core, horizon-client-render ❌ 1394 passed, 7 failed (5 min 23 s)
doc tests ✅ 0 passed (3 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
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🔄 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/5174 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-mob-effect-hooks` --- ### 📝 Commits (2) - [`e3308bf`](https://github.com/horizon-rust/horizon/commit/e3308bf49863d25538ad6f05214bb10955f56205) feat(mods): native mods give their mob effects behaviour - [`f67740a`](https://github.com/horizon-rust/horizon/commit/f67740ab8d5980065fb53d97e900fb8506c87bef) Merge remote-tracking branch 'origin/main' into sweep/5174-m3 ### 📊 Changes **14 files changed** (+244 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-core/src/potions.rs` (+8 -0) 📝 `crates/horizon-client-render/src/brewing.rs` (+2 -1) 📝 `crates/horizon-client-render/src/effects.rs` (+39 -9) 📝 `crates/horizon-client/examples/probe/mob_ai_probe.rs` (+1 -0) 📝 `crates/horizon-client/src/game/commands/effects.rs` (+2 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+6 -0) 📝 `crates/horizon-client/src/game/enchant_effects.rs` (+2 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+54 -0) 📝 `crates/horizon-client/src/game/potions.rs` (+79 -9) 📝 `crates/horizon-client/src/mobs.rs` (+8 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+19 -5) 📝 `crates/horizon-client/src/mobs/world.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs/zombie_villager.rs` (+1 -0) ➕ `tools/native-hook-fragments/mob_effect_hooks.json` (+22 -0) </details> ### 📄 Description ## What and why #4840 lets a content mod declare its own mob effects, but they do nothing yet: they only count down and go A native mod can now give them their behaviour, through four hook points `native_should_apply_effect_tick_this_tick(effect, tick_count, amplifier, apply)` is `shouldApplyEffectTickThisTick`, and vanilla's base answer is no `native_apply_effect_tick(effect, dimension, entity, amplifier, keep)` is `applyEffectTick`, and clearing `keep` ends the effect `native_on_effect_added(effect, entity, amplifier)` is `onEffectAdded`, only when the entity didn't have the effect `native_mob_effect_added(effect, entity, amplifier)` is `onEffectStarted`, every time the effect is given, new or not I was going to use the vanilla name (`MobEffect.onEffectStarted`), but the docs (#4402) name a hook after its NeoForge event, so it's `mob_effect_added` NeoForge's `MobEffectEvent.Added` can carry a previous instance, so I think it fires on every add, as `onEffectStarted` does The other three keep vanilla's names, since NeoForge's mob effects docs have no event for them Its effects override `MobEffect`'s methods directly, and rule 1 says a hook with no counterpart keeps a Horizon name The tick hooks run where vanilla runs them, in `LivingEntity.tickEffects` during the entity's `baseTick`, for players and mobs For each effect the order is vanilla's `MobEffectInstance.tickServer`: the should-apply check, then apply, then the countdown, and a false from apply removes the effect before it counts down An infinite effect gets the entity's tick count, as in vanilla, and one with no ticks left goes without asking The add hooks run inside `LivingEntity.addEffect`, after the effect's attribute modifiers, in vanilla's order A mob is its `Entity.getId`, a player `None`, with their state swapped in so `native_acting_player` names them The two tick hooks take `&self` A mob's effects tick inside its own tick, where the mob world borrows the game, so `&mut self` would alias that borrow The ticking mobs are out of `Game::mobs` then, and a player's effects are out of the game while they tick This is the one real difference from vanilla, whose `applyEffectTick` can change the entity, so a mod records what to do and acts from another hook The add hooks take `&mut self` Only content mods' effects reach the hooks Vanilla's effects keep their own code Server side only: the server thread, a LAN host and dedicated servers A server's client never calls them, including for the mount it steers Effects reach a mob through `/effect give`, a thrown potion or a tipped arrow, a creeper's lingering cloud, and an enchantment's `apply_mob_effect`, and each of those calls the add hooks I think the other places that give mobs effects only use vanilla's `forceAddEffect` calls neither hook, as in vanilla In vanilla the effects tick in the order of a `HashMap` keyed by effect, which I think comes down to identity hashes, and Horizon ticks them in the order they were given Without a mod nothing changes: in an optimized build no hook symbol is left, the add sites have no trace of the id check, and the player's effect tick keeps only the check on the effects it already asked about A mob's tick gets one id check per effect that isn't poison, wither or regeneration, and an indirect call only for a content mod's effect Adds the hook fragment `tools/native-hook-fragments/mob_effect_hooks.json` The stamp sets the API number after merge ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `MobEffect.applyEffectTick`, `shouldApplyEffectTickThisTick`, `onEffectStarted`, `onEffectAdded` (`world/effect/MobEffect.java:82`, `:92`, `:96`, `:99`) `MobEffectInstance.tickServer` (`world/effect/MobEffectInstance.java:224-241`) `LivingEntity.baseTick` calls `tickEffects` (`world/entity/LivingEntity.java:513`, `:859-875`) `LivingEntity.addEffect` (`world/entity/LivingEntity.java:1025-1043`) NeoForge's `MobEffectEvent.Added` and the overridden `MobEffect` methods: <https://docs.neoforged.net/docs/items/mobeffects/> (Events) ## Other projects' code none ## Self-check The 7 failures are all in `tests/lan_bot.rs` (`status_and_join`, `guests_see_each_other_and_the_world_entities` and 5 more), they fail on `main` too with prepared data (`b8f8c2515`) With `--no-fail-fast` the same tests give 2184 passed, and only these 7 fail | Check | Result | | --- | --- | | Scope | ✅ 14 files, +244 −24 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 499 passed (1 min 1 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (2 min 8 s) | | tests: horizon-client, horizon-client-core, horizon-client-render | ❌ 1394 passed, 7 failed (5 min 23 s) | | doc tests | ✅ 0 passed (3 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 | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:12:15 +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#6120
No description provided.