[PR #3578] [MERGED] Horses rear when hurt #5068

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3578
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @ludovic111

Base: main ← Head: fix-3432


📝 Commits (3)

  • a30b952 Horses rear when hurt
  • 62c0834 Merge main into this branch (rearing beside the horse finalize tests, one tests module)
  • d22aecd Format the equine tests' imports

📊 Changes

5 files changed (+89 additions, -5 deletions)

View changed files

📝 crates/horizon-client/examples/probe/mob_ai_probe.rs (+2 -0)
📝 crates/horizon-client/src/mobs.rs (+4 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+7 -0)
📝 crates/horizon-client/src/mobs/equine.rs (+71 -5)
📝 tools/test_mob_ai_parity.py (+5 -0)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

What and why

Fixes #3432

A horse that takes damage never reared in Horizon. AbstractHorse.hurtServer had no port: in vanilla, after a hurt that went through, the horse draws random.nextInt(3) and on 0 calls standIfPossible, which rears it for 20 ticks (setStanding(20), which also stops it eating). Llamas and camels (canPerformRearing is false) make the same draw but never rear.

  • equine::after_hurt_server makes that roll; Mob::damage_with calls it for every equine as its last step, after the hurt sound, where vanilla's AbstractHorse.hurtServer makes it after super.hurtServer.
  • equine::stand_if_possible is standIfPossible, and make_mad uses it too, so the two stay the same.
  • equine::stand_tick runs the stand counter down. Vanilla does this in AbstractHorse.tick, which runs with or without AI. Horizon did it only in the equine AI step, which a NoAI mob skips. Without this change, a NoAI horse that reared from a hit would stay reared for good. A mob with no AI now runs the counter down too.
  • The standing flag already reaches clients (AbstractHorse.DATA_ID_FLAGS bit 32 in game/lan.rs), so players on the server thread, LAN and dedicated servers see the rear.

Donkeys and mules still don't rear, because can_rear leaves them out. #2720 changes that, and after it this roll makes them rear on hurt too. A rearing horse being immobile (AbstractHorse.isImmobile) is also in #2720.

Vanilla reference

  • net.minecraft.world.entity.animal.equine.AbstractHorse.hurtServer: super.hurtServer, then if (hurt && random.nextInt(3) == 0) standIfPossible()
  • AbstractHorse.standIfPossible, setStanding, makeMad
  • AbstractHorse.tick: if (standCounter > 0 && --standCounter <= 0) clearStanding()
  • canPerformRearing overrides: Llama and Camel (CamelHusk extends Camel) return false.

Checked with javap -c -p on the 26.3 client jar.

Tests

Unit tests (mobs::equine::tests): one hit each on 300 fresh horses, where about a third should rear, and on 60 llamas and 60 camels, where none should. A third test checks that a rear ends after 20 ticks.

Before (the damage_with hook removed):

test mobs::equine::tests::a_hurt_horse_rears_one_hit_in_three ... FAILED
0 of 300 hits reared
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 641 filtered out

After:

test mobs::equine::tests::the_rear_ends_after_twenty_ticks ... ok
test mobs::equine::tests::llamas_and_camels_never_rear_when_hurt ... ok
test mobs::equine::tests::a_hurt_horse_rears_one_hit_in_three ... ok

mob_ai harness, new llama_hurt scenario. A player hits a llama every 25 ticks for 200 ticks, which checks the draw against vanilla's RNG trace. The probe now uses vanilla's names for MountPanic and LlamaHurtBy.

Before:

llama_hurt mob 0: first divergence at tick 10 of 201 (random draws this tick: vanilla 6, horizon 5)
0/1 scenarios match entirely; 10/201 mob-ticks match before each mob's first divergence

After:

llama_hurt: all 201 ticks match
1/1 scenarios match entirely; 201/201 mob-ticks match before each mob's first divergence

The other llama scenarios still match: llama_family, llama_wolf, llama_love, llama_tempted, llama_caravan and trader_llamas (7/7 with llama_hurt, 3614/3614 mob-ticks).

I also tried a horse_hurt scenario. With this change it matches vanilla's draws and the rear roll, up to the first hurt that rears (tick 35). From there vanilla's horse is immobile (isImmobile) and Horizon's isn't, which is #2720. So I left the horse scenario out until #2720 lands.

Self-check

tools/pr_ready.py wasn't run on this Windows machine. I ran these instead, with CARGO_TARGET_DIR set:

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client --features mods --all-targets -- -D warnings: clean
  • cargo test -p horizon-client --lib mobs::: 116 passed, 0 failed, 6 ignored
  • python tools/test_mob_ai_parity.py --only llama_hurt and the six other llama scenarios: 7/7 match

In game

On the server thread in survival, I hit a NoAI horse 10 times, 30 ticks apart. I took one screenshot 3 ticks after each hit and another 25 ticks after it. horizon-ctl attack confirmed every hit ("hit":true, health 53 → 43).

  • Before (origin/main, an earlier run with 10 hits 25 ticks apart): the horse never reared.
  • With only the hurt roll: the horse reared on hit 2 and was still rearing 25 ticks after each of the later hits. Its stand counter never ran down.
  • With this PR: the horse reared on hit 6 and was standing normally again 25 ticks later.

🤖 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/3578 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix-3432` --- ### 📝 Commits (3) - [`a30b952`](https://github.com/horizon-rust/horizon/commit/a30b9525d1db7118640ccc990f0c147655f53de5) Horses rear when hurt - [`62c0834`](https://github.com/horizon-rust/horizon/commit/62c08348801b077495e4cc8fc4d37e383193e81c) Merge main into this branch (rearing beside the horse finalize tests, one tests module) - [`d22aecd`](https://github.com/horizon-rust/horizon/commit/d22aecd5267a6db1ff5c19c19d879856d522ff10) Format the equine tests' imports ### 📊 Changes **5 files changed** (+89 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/probe/mob_ai_probe.rs` (+2 -0) 📝 `crates/horizon-client/src/mobs.rs` (+4 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+7 -0) 📝 `crates/horizon-client/src/mobs/equine.rs` (+71 -5) 📝 `tools/test_mob_ai_parity.py` (+5 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3432 A horse that takes damage never reared in Horizon. `AbstractHorse.hurtServer` had no port: in vanilla, after a hurt that went through, the horse draws `random.nextInt(3)` and on 0 calls `standIfPossible`, which rears it for 20 ticks (`setStanding(20)`, which also stops it eating). Llamas and camels (`canPerformRearing` is false) make the same draw but never rear. - `equine::after_hurt_server` makes that roll; `Mob::damage_with` calls it for every equine as its last step, after the hurt sound, where vanilla's `AbstractHorse.hurtServer` makes it after `super.hurtServer`. - `equine::stand_if_possible` is `standIfPossible`, and `make_mad` uses it too, so the two stay the same. - `equine::stand_tick` runs the stand counter down. Vanilla does this in `AbstractHorse.tick`, which runs with or without AI. Horizon did it only in the equine AI step, which a `NoAI` mob skips. Without this change, a `NoAI` horse that reared from a hit would stay reared for good. A mob with no AI now runs the counter down too. - The standing flag already reaches clients (`AbstractHorse.DATA_ID_FLAGS` bit 32 in `game/lan.rs`), so players on the server thread, LAN and dedicated servers see the rear. Donkeys and mules still don't rear, because `can_rear` leaves them out. #2720 changes that, and after it this roll makes them rear on hurt too. A rearing horse being immobile (`AbstractHorse.isImmobile`) is also in #2720. ## Vanilla reference - `net.minecraft.world.entity.animal.equine.AbstractHorse.hurtServer`: `super.hurtServer`, then `if (hurt && random.nextInt(3) == 0) standIfPossible()` - `AbstractHorse.standIfPossible`, `setStanding`, `makeMad` - `AbstractHorse.tick`: `if (standCounter > 0 && --standCounter <= 0) clearStanding()` - `canPerformRearing` overrides: `Llama` and `Camel` (`CamelHusk` extends `Camel`) return false. Checked with `javap -c -p` on the 26.3 client jar. ## Tests **Unit tests** (`mobs::equine::tests`): one hit each on 300 fresh horses, where about a third should rear, and on 60 llamas and 60 camels, where none should. A third test checks that a rear ends after 20 ticks. Before (the `damage_with` hook removed): ``` test mobs::equine::tests::a_hurt_horse_rears_one_hit_in_three ... FAILED 0 of 300 hits reared test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 641 filtered out ``` After: ``` test mobs::equine::tests::the_rear_ends_after_twenty_ticks ... ok test mobs::equine::tests::llamas_and_camels_never_rear_when_hurt ... ok test mobs::equine::tests::a_hurt_horse_rears_one_hit_in_three ... ok ``` **`mob_ai` harness, new `llama_hurt` scenario.** A player hits a llama every 25 ticks for 200 ticks, which checks the draw against vanilla's RNG trace. The probe now uses vanilla's names for `MountPanic` and `LlamaHurtBy`. Before: ``` llama_hurt mob 0: first divergence at tick 10 of 201 (random draws this tick: vanilla 6, horizon 5) 0/1 scenarios match entirely; 10/201 mob-ticks match before each mob's first divergence ``` After: ``` llama_hurt: all 201 ticks match 1/1 scenarios match entirely; 201/201 mob-ticks match before each mob's first divergence ``` The other llama scenarios still match: `llama_family`, `llama_wolf`, `llama_love`, `llama_tempted`, `llama_caravan` and `trader_llamas` (7/7 with `llama_hurt`, 3614/3614 mob-ticks). I also tried a `horse_hurt` scenario. With this change it matches vanilla's draws and the rear roll, up to the first hurt that rears (tick 35). From there vanilla's horse is immobile (`isImmobile`) and Horizon's isn't, which is #2720. So I left the horse scenario out until #2720 lands. ## Self-check `tools/pr_ready.py` wasn't run on this Windows machine. I ran these instead, with `CARGO_TARGET_DIR` set: - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client --features mods --all-targets -- -D warnings`: clean - `cargo test -p horizon-client --lib mobs::`: 116 passed, 0 failed, 6 ignored - `python tools/test_mob_ai_parity.py --only llama_hurt` and the six other llama scenarios: 7/7 match ## In game On the server thread in survival, I hit a `NoAI` horse 10 times, 30 ticks apart. I took one screenshot 3 ticks after each hit and another 25 ticks after it. `horizon-ctl attack` confirmed every hit (`"hit":true`, health 53 → 43). - Before (`origin/main`, an earlier run with 10 hits 25 ticks apart): the horse never reared. - With only the hurt roll: the horse reared on hit 2 and was still rearing 25 ticks after each of the later hits. Its stand counter never ran down. - With this PR: the horse reared on hit 6 and was standing normally again 25 ticks later. 🤖 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 05:10:00 +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#5068
No description provided.