[PR #6130] [MERGED] A mob's melee push follows knockback resistance and attack_knockback #6668

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

📋 Pull Request Information

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

Base: main ← Head: fix/mob-melee-knockback


📝 Commits (1)

  • 914c15d A mob's melee push is LivingEntity.knockback along its facing, with attack_knockback

📊 Changes

3 files changed (+18 additions, -14 deletions)

View changed files

📝 crates/horizon-client/src/entity_nbt.rs (+1 -0)
📝 crates/horizon-client/src/mobs.rs (+3 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+14 -14)

📄 Description

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

Fixes #6110.

What was wrong

Mob.doHurtTarget calls causeExtraKnockback(target, getKnockback(...)): getKnockback is the attack_knockback attribute plus the Knockback enchantment, halved, and the push goes along the attacker's yaw through LivingEntity.knockback (so 1 - knockback_resistance scales it, nothing happens at <= 0) and slows the attacker by 0.6. Horizon's do_hurt_target (mobs/ai.rs) pushed a fixed level * 0.5 along the line to the target with +0.1 up and never read attack_knockback, so resistance did nothing, a Ravager or Warden pushed nothing extra, and the attacker was not slowed.

What changes

  • do_hurt_target sends MobEvent::Knockback { power: (attack_knockback + knockback level) / 2, x: sin(yaw), z: -cos(yaw) } and multiplies the attacker's horizontal velocity by 0.6, the same shape as the spear stab's cause_extra_knockback. Nothing is sent at power <= 0.
  • Attrs.attack_knockback (new): the type default, or the mob's own from its attributes NBT (minecraft:attack_knockback).

Verification

cargo test -p horizon-client --lib mobs::: 274 passed; clippy and rustfmt clean for the changed files (the only clippy error is the existing needless_borrow in horizon-world). I did not run tools/test_server_knockback_parity.py (needs the vanilla jar and a newer Python than this machine has); the issue's numbers are the cases to compare, and CI runs the harness.

Not done

  • The issue's other finding, that Horizon pushes before the hit's result is known (a shield-blocked or cooldown-refused hit still pushes), is not changed: the push event is still sent with the hit.
  • Hoglins and zoglins keep their own throw_target path; iron golems and bees keep theirs.

🤖 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/6130 **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/mob-melee-knockback` --- ### 📝 Commits (1) - [`914c15d`](https://github.com/horizon-rust/horizon/commit/914c15d3498aafaa7a4abc97e3fe1a3110221df7) A mob's melee push is LivingEntity.knockback along its facing, with attack_knockback ### 📊 Changes **3 files changed** (+18 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entity_nbt.rs` (+1 -0) 📝 `crates/horizon-client/src/mobs.rs` (+3 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+14 -14) </details> ### 📄 Description > 🤖 Opened by xFedeT's AI agent (Claude Code, Sonnet 5.5), not by xFedeT personally. Fixes #6110. ## What was wrong `Mob.doHurtTarget` calls `causeExtraKnockback(target, getKnockback(...))`: `getKnockback` is the `attack_knockback` attribute plus the Knockback enchantment, halved, and the push goes along the attacker's yaw through `LivingEntity.knockback` (so `1 - knockback_resistance` scales it, nothing happens at `<= 0`) and slows the attacker by 0.6. Horizon's `do_hurt_target` (`mobs/ai.rs`) pushed a fixed `level * 0.5` along the line to the target with +0.1 up and never read `attack_knockback`, so resistance did nothing, a Ravager or Warden pushed nothing extra, and the attacker was not slowed. ## What changes - `do_hurt_target` sends `MobEvent::Knockback { power: (attack_knockback + knockback level) / 2, x: sin(yaw), z: -cos(yaw) }` and multiplies the attacker's horizontal velocity by 0.6, the same shape as the spear stab's `cause_extra_knockback`. Nothing is sent at `power <= 0`. - `Attrs.attack_knockback` (new): the type default, or the mob's own from its `attributes` NBT (`minecraft:attack_knockback`). ## Verification `cargo test -p horizon-client --lib mobs::`: 274 passed; clippy and rustfmt clean for the changed files (the only clippy error is the existing `needless_borrow` in `horizon-world`). I did not run `tools/test_server_knockback_parity.py` (needs the vanilla jar and a newer Python than this machine has); the issue's numbers are the cases to compare, and CI runs the harness. ## Not done - The issue's other finding, that Horizon pushes before the hit's result is known (a shield-blocked or cooldown-refused hit still pushes), is not changed: the push event is still sent with the hit. - Hoglins and zoglins keep their own `throw_target` path; iron golems and bees keep theirs. 🤖 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:24:40 +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#6668
No description provided.