[PR #6495] [MERGED] The native knockback hook runs on the raw strength, before the resistance #6910

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

📋 Pull Request Information

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

Base: main ← Head: fix/knockback-hook-before-resistance


📝 Commits (3)

  • c305aac The native knockback hook runs on the raw strength, before the knockback resistance
  • 3c6de1b Knockback hook test: the hook sees the raw strength
  • 6edff51 The knockback hook test and docs follow the hook's new place

📊 Changes

5 files changed (+26 additions, -16 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+7 -3)
📝 crates/horizon-client/src/game/native_hooks.rs (+2 -1)
📝 crates/horizon-client/src/health.rs (+10 -8)
📝 crates/horizon-client/src/mobs.rs (+4 -1)
📝 docs/native-mods.md (+3 -3)

📄 Description

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

Part of #6444 (its first bullet: the hook's place relative to the knockback resistance).

What was wrong

LivingEntity.knockback(strength, x, z) multiplies strength by 1 - KNOCKBACK_RESISTANCE inside the method, and NeoForge's LivingKnockBackEvent fires at the start of it, so what a mod changes lands on the raw value and the resistance applies to its result. Horizon's Mob::knockback and the player's knock_back (game/creatures.rs) scaled the strength by the resistance first and ran native_living_knockback on the result, so a mod that raised a weapon's knockback had it cut by the resistance twice over and could not tell the raw value.

What changes

Both paths pass the raw strength to the hook (health::knockback_canceled), then multiply what it leaves by 1 - resistance and drop a push that is <= 0, as vanilla's method does. The hook's documentation says it runs at the start.

Verification

Builds; cargo test -p horizon-client --lib passes (the player knockback hook test now expects the raw strength, 0.4, after a 0.5 resistance, and the halved push); clippy and rustfmt clean (the only clippy error is the existing needless_borrow in horizon-world). Without a native mod listening the hook is a no-op, so the change is only visible to a mod, and the issue's in-game route (a throwaway mod that logs the strength) was not run here.

Not done

The issue's other bullets are not in this PR: the hook already names the causing and the direct entity (causing, direct), but not the items the attacker holds, and mob melee and armor-stand paths that do not go through these two functions are not audited.

🤖 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/6495 **Author:** [@xFedeT](https://github.com/xFedeT) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/knockback-hook-before-resistance` --- ### 📝 Commits (3) - [`c305aac`](https://github.com/horizon-rust/horizon/commit/c305aac57a042417bd56f6eb14fe50ea38d32677) The native knockback hook runs on the raw strength, before the knockback resistance - [`3c6de1b`](https://github.com/horizon-rust/horizon/commit/3c6de1ba34c61daf72eb5d69b5badc0a6ff89394) Knockback hook test: the hook sees the raw strength - [`6edff51`](https://github.com/horizon-rust/horizon/commit/6edff5155899bf5e864eeea7ecf24d0d022e95e9) The knockback hook test and docs follow the hook's new place ### 📊 Changes **5 files changed** (+26 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+7 -3) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+2 -1) 📝 `crates/horizon-client/src/health.rs` (+10 -8) 📝 `crates/horizon-client/src/mobs.rs` (+4 -1) 📝 `docs/native-mods.md` (+3 -3) </details> ### 📄 Description > 🤖 Opened by xFedeT's AI agent (Claude Code, Sonnet 5.5), not by xFedeT personally. Part of #6444 (its first bullet: the hook's place relative to the knockback resistance). ## What was wrong `LivingEntity.knockback(strength, x, z)` multiplies `strength` by `1 - KNOCKBACK_RESISTANCE` inside the method, and NeoForge's `LivingKnockBackEvent` fires at the start of it, so what a mod changes lands on the raw value and the resistance applies to its result. Horizon's `Mob::knockback` and the player's `knock_back` (`game/creatures.rs`) scaled the strength by the resistance first and ran `native_living_knockback` on the result, so a mod that raised a weapon's knockback had it cut by the resistance twice over and could not tell the raw value. ## What changes Both paths pass the raw strength to the hook (`health::knockback_canceled`), then multiply what it leaves by `1 - resistance` and drop a push that is `<= 0`, as vanilla's method does. The hook's documentation says it runs at the start. ## Verification Builds; `cargo test -p horizon-client --lib` passes (the player knockback hook test now expects the raw strength, 0.4, after a 0.5 resistance, and the halved push); clippy and rustfmt clean (the only clippy error is the existing `needless_borrow` in `horizon-world`). Without a native mod listening the hook is a no-op, so the change is only visible to a mod, and the issue's in-game route (a throwaway mod that logs the strength) was not run here. ## Not done The issue's other bullets are not in this PR: the hook already names the causing and the direct entity (`causing`, `direct`), but not the items the attacker holds, and mob melee and armor-stand paths that do not go through these two functions are not audited. 🤖 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:29:01 +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#6910
No description provided.