[PR #7444] [MERGED] A mob's melee effect reaches the mob it hit #7605

Closed
opened 2026-11-03 07:20:38 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7444
Author: @MSedgeMC
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/cave-spider-poison-mob


📝 Commits (2)

  • e8191c9 A mob's hit effect reaches the mob it hit
  • 713582b Test that a cave spider, husk and wither skeleton effect reaches a mob

📊 Changes

3 files changed (+193 additions, -29 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+17 -0)
📝 crates/horizon-client/src/mobs.rs (+12 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+164 -29)

📄 Description

Behaviour: a cave spider's bite, a bare-handed husk's blow and a wither skeleton's hit now give their effect to the mob they hit, not only to the player. A wolf bitten by a cave spider on normal takes 140 ticks of poison, a villager hit by a bare-handed husk 140 ticks of hunger, a pig hit by a wither skeleton 200 ticks of wither.

Vanilla javap -p -c -constants -cp /tmp/cj:

net.minecraft.world.entity.monster.spider.CaveSpider.doHurtTarget(ServerLevel, Entity) — after super.doHurtTarget lands it tests LivingEntity, not Player:

 3: invokespecial Spider.doHurtTarget
 6: ifeq 90                     // the hit did not land: return false
 9: aload_2
10: instanceof #29              // net/minecraft/world/entity/LivingEntity
13: ifeq 88
21: iconst_0 / 22: istore 4     // i = 0
31: getstatic Difficulty.NORMAL / 34: if_acmpne 44 / 37: bipush 7 / 39: istore 4
45: getstatic Difficulty.HARD   / 54: if_acmpne 61 / 57: bipush 15 / 59: istore 4
63: iload 4 / 64: ifle 88       // easy and peaceful give none
67: new MobEffectInstance(POISON, i * 20, 0)
84: invokevirtual LivingEntity.addEffect(MobEffectInstance, Entity)

net.minecraft.world.entity.monster.skeleton.WitherSkeleton.doHurtTarget, same shape:

 3: invokespecial AbstractSkeleton.doHurtTarget
 6: ifne 11                    // only a hit that landed
12: instanceof #120             // net/minecraft/world/entity/LivingEntity
15: ifeq 42
24: new MobEffectInstance(WITHER, 200)
38: invokevirtual LivingEntity.addEffect(MobEffectInstance, Entity)

net.minecraft.world.entity.monster.zombie.Husk.doHurtTarget:

 7: iload_3 / 8: ifeq 71        // super's result
12: getMainHandItem / 15: ItemStack.isEmpty / 18: ifeq 71
22: instanceof #38              // net/minecraft/world/entity/LivingEntity
25: ifeq 71
39: ServerLevel.getCurrentDifficultyAt(blockPosition) / 42: DifficultyInstance.getEffectiveDifficulty
56: sipush 140 / 62: imul
67: invokevirtual LivingEntity.addEffect(MobEffectInstance, Entity)

What Horizon got wrong: mobs/ai.rs::do_hurt_target picked those effects only when who == Who::Player, and the Who::Mob arm pushed a bare MobEvent::AttackMob, which carries the damage and nothing else. So a mob's victim took the hit and Mob::add_effect was never reached: its effect list stayed empty and poison, hunger and wither never ticked. The tick code itself is fine and already covered (mobs::ai::poison_effect_tests, and a mob in a wither rose gets wither through the same Mob::add_effect).

A hit on a mob now goes out as MobEvent::AttackMobWithEffect, carrying the effect with the damage; game/creatures.rs runs Mob::add_effect only when mob_hits_mob says the hit landed, which is the same "only a landed hit gives it" rule AttackPlayerWithEffect already follows for the player.

Test: mobs::ai::hit_effect_tests::a_melee_effect_rides_the_hit_onto_a_mob drives do_hurt_target for the three species against mob 2 in the test world (normal difficulty, effective 1.5) and reads the hit event. A second test, an_easy_cave_spiders_bite_carries_no_effect, checks that easy keeps the plain hit.

Failing without the fix, the same test:

left:  [("minecraft:cave_spider", None), ("minecraft:husk", None), ("minecraft:wither_skeleton", None)]
right: [("minecraft:cave_spider", Some((2, "minecraft:poison", 140, 0))), ("minecraft:husk", Some((2, "minecraft:hunger", 140, 0))), ("minecraft:wither_skeleton", Some((2, "minecraft:wither", 200, 0)))]

i.e. the mob that was hit got 0 ticks of poison, hunger and wither where vanilla gives 140, 140 and 200.

Proven: the bytecode above for all three classes; the values in the test (poison 140 on normal and 300 on hard come from bipush 7/bipush 15 times 20, hunger 140 from 140 * (int) 1.5, wither 200 from sipush 200); that the effect reaches a mob target rather than the player; cargo test -p horizon-client-lib --lib mobs:: — 370 passed, 0 failed, 13 ignored; cargo clippy -q -p horizon-client-lib --lib silent; rustfmt --edition 2024 --check clean.

Not proven: that the hit lands before the effect in every game path — MobEvent::AttackMobWithEffect applies the effect after mob_hits_mob, as the player path does, but no test here drives a real shield block or invulnerability window on a mob. Hunger on a mob is added but has no effect in vanilla either (it only drains a player's food), so that branch is behaviour-neutral for mobs. The mob-side poison/wither damage tick is not re-tested here; it is the existing tick_effects path.


🔄 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/7444 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/cave-spider-poison-mob` --- ### 📝 Commits (2) - [`e8191c9`](https://github.com/horizon-rust/horizon/commit/e8191c9e8f02b1de2edc07f1ec7bf85c1d17f237) A mob's hit effect reaches the mob it hit - [`713582b`](https://github.com/horizon-rust/horizon/commit/713582bbdd5b48b7e4b13851ece5e437ebf763fa) Test that a cave spider, husk and wither skeleton effect reaches a mob ### 📊 Changes **3 files changed** (+193 additions, -29 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+17 -0) 📝 `crates/horizon-client/src/mobs.rs` (+12 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+164 -29) </details> ### 📄 Description **Behaviour:** a cave spider's bite, a bare-handed husk's blow and a wither skeleton's hit now give their effect to the mob they hit, not only to the player. A wolf bitten by a cave spider on normal takes 140 ticks of poison, a villager hit by a bare-handed husk 140 ticks of hunger, a pig hit by a wither skeleton 200 ticks of wither. Vanilla `javap -p -c -constants -cp /tmp/cj`: `net.minecraft.world.entity.monster.spider.CaveSpider.doHurtTarget(ServerLevel, Entity)` — after `super.doHurtTarget` lands it tests `LivingEntity`, not `Player`: ``` 3: invokespecial Spider.doHurtTarget 6: ifeq 90 // the hit did not land: return false 9: aload_2 10: instanceof #29 // net/minecraft/world/entity/LivingEntity 13: ifeq 88 21: iconst_0 / 22: istore 4 // i = 0 31: getstatic Difficulty.NORMAL / 34: if_acmpne 44 / 37: bipush 7 / 39: istore 4 45: getstatic Difficulty.HARD / 54: if_acmpne 61 / 57: bipush 15 / 59: istore 4 63: iload 4 / 64: ifle 88 // easy and peaceful give none 67: new MobEffectInstance(POISON, i * 20, 0) 84: invokevirtual LivingEntity.addEffect(MobEffectInstance, Entity) ``` `net.minecraft.world.entity.monster.skeleton.WitherSkeleton.doHurtTarget`, same shape: ``` 3: invokespecial AbstractSkeleton.doHurtTarget 6: ifne 11 // only a hit that landed 12: instanceof #120 // net/minecraft/world/entity/LivingEntity 15: ifeq 42 24: new MobEffectInstance(WITHER, 200) 38: invokevirtual LivingEntity.addEffect(MobEffectInstance, Entity) ``` `net.minecraft.world.entity.monster.zombie.Husk.doHurtTarget`: ``` 7: iload_3 / 8: ifeq 71 // super's result 12: getMainHandItem / 15: ItemStack.isEmpty / 18: ifeq 71 22: instanceof #38 // net/minecraft/world/entity/LivingEntity 25: ifeq 71 39: ServerLevel.getCurrentDifficultyAt(blockPosition) / 42: DifficultyInstance.getEffectiveDifficulty 56: sipush 140 / 62: imul 67: invokevirtual LivingEntity.addEffect(MobEffectInstance, Entity) ``` **What Horizon got wrong:** `mobs/ai.rs::do_hurt_target` picked those effects only when `who == Who::Player`, and the `Who::Mob` arm pushed a bare `MobEvent::AttackMob`, which carries the damage and nothing else. So a mob's victim took the hit and `Mob::add_effect` was never reached: its effect list stayed empty and poison, hunger and wither never ticked. The tick code itself is fine and already covered (`mobs::ai::poison_effect_tests`, and a mob in a wither rose gets wither through the same `Mob::add_effect`). A hit on a mob now goes out as `MobEvent::AttackMobWithEffect`, carrying the effect with the damage; `game/creatures.rs` runs `Mob::add_effect` only when `mob_hits_mob` says the hit landed, which is the same "only a landed hit gives it" rule `AttackPlayerWithEffect` already follows for the player. **Test:** `mobs::ai::hit_effect_tests::a_melee_effect_rides_the_hit_onto_a_mob` drives `do_hurt_target` for the three species against mob 2 in the test world (normal difficulty, effective 1.5) and reads the hit event. A second test, `an_easy_cave_spiders_bite_carries_no_effect`, checks that easy keeps the plain hit. Failing without the fix, the same test: ``` left: [("minecraft:cave_spider", None), ("minecraft:husk", None), ("minecraft:wither_skeleton", None)] right: [("minecraft:cave_spider", Some((2, "minecraft:poison", 140, 0))), ("minecraft:husk", Some((2, "minecraft:hunger", 140, 0))), ("minecraft:wither_skeleton", Some((2, "minecraft:wither", 200, 0)))] ``` i.e. the mob that was hit got 0 ticks of poison, hunger and wither where vanilla gives 140, 140 and 200. **Proven:** the bytecode above for all three classes; the values in the test (poison 140 on normal and 300 on hard come from `bipush 7`/`bipush 15` times 20, hunger 140 from `140 * (int) 1.5`, wither 200 from `sipush 200`); that the effect reaches a mob target rather than the player; `cargo test -p horizon-client-lib --lib mobs::` — 370 passed, 0 failed, 13 ignored; `cargo clippy -q -p horizon-client-lib --lib` silent; `rustfmt --edition 2024 --check` clean. **Not proven:** that the hit lands before the effect in every game path — `MobEvent::AttackMobWithEffect` applies the effect after `mob_hits_mob`, as the player path does, but no test here drives a real shield block or invulnerability window on a mob. Hunger on a mob is added but has no effect in vanilla either (it only drains a player's food), so that branch is behaviour-neutral for mobs. The mob-side `poison`/`wither` damage tick is not re-tested here; it is the existing `tick_effects` path. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 07:20:38 +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#7605
No description provided.