[PR #4259] [MERGED] Tame wolves' kills count for their owner #5524

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4259
Author: @d3grando
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3514-tame-wolf-kill-credit


📝 Commits (2)

  • 0341913 Credit a tame wolf's kills to its owner
  • 1e8f93a Check tame wolf kill credit in the command execution harness

📊 Changes

3 files changed (+106 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/game/commands/world_cmds.rs (+7 -2)
📝 crates/horizon-client/src/game/creatures.rs (+65 -3)
📝 tools/command_exec_corpus.py (+34 -0)

📄 Description

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

What and why

Part of #3514 (the LivingEntity.resolvePlayerResponsibleForDamage (gap) row).

When a tame wolf killed a mob, the kill counted as no one's. Mob::damage only set the victim's last-hurt-by-player timer when the attacker was Who::Player, and neither mob_hits_mob nor /damage … by <wolf> credited the wolf's owner. So mob_died saw by_player = false: the kill dropped no experience and no player-only loot, and the owner's kill counters did not go up.

Vanilla's LivingEntity.hurtServer calls resolvePlayerResponsibleForDamage after every hit that lands. If the causing entity is a tame Wolf, it calls setLastHurtByPlayer(owner uuid, 100). A tame wolf with no owner reference clears the field instead.

The fix adds Game::resolve_player_responsible, which runs after a mob's melee hit lands (mob_hits_mob) and after /damage with a causing entity:

  • If the attacker is a tame wolf, the victim's last_hurt_by_player timer is set to 100 (0 when the wolf has no owner).
  • The owner is looked up among the players in the world: the player in place, or a guest by UUID, which covers the single-player owner on the server thread. It is recorded in last_hurt_by_player, so mob_died credits that player through credit_kill (guests through as_guest).

die then credits the owner through getKillCredit → ServerPlayer.awardKillScore. That awards mob_kills, totalKillCount, team kills and player_killed_entity. It does not award the killed:<type> statistic: Player.killedEntity awards that one, and vanilla calls it on the causing entity (here the wolf). credit_kill used to add killed:<type> for every credited kill, so it now skips that stat when the killing blow came from a mob.

Two other death hooks read the same by_player flag but in vanilla follow the causing entity, not the credited player: Raider.die adds a hero of the village only when source.getEntity() is a player, and Villager.die tells witnesses about source.getEntity(). So mob_died now passes them by_player only when the killing blow did not come from a mob. Without that, a tame wolf killing a raider would make its owner a hero, and a wolf killing a villager would count as a murder by the owner.

One limit: when the owner is not in the world (a guest who left), the timer is still set, so experience and loot drop as in vanilla. But no kill-credit entry is recorded, so mob_died falls back to its existing "credit the host" path, the same one other timer-only player damage already uses.

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

  • LivingEntity.hurtServer → resolvePlayerResponsibleForDamage(DamageSource). For a Player it calls setLastHurtByPlayer(player, 100). For a Wolf with isTame() it calls setLastHurtByPlayer(getOwnerReference().getUUID(), 100), or clears lastHurtByPlayer when the owner reference is null.
  • LivingEntity.die → getKillCredit() (the resolved lastHurtByPlayer player, else lastHurtByMob) → awardKillScore.
  • ServerPlayer.awardKillScore: KILL_COUNT_ALL, MOB_KILLS, team kills, PLAYER_KILLED_ENTITY. Player.killedEntity (called on source.getEntity()): ENTITY_KILLED.
  • Raider.die: Raid.addHeroOfTheVillage only when source.getEntity() is a player. Villager.die: tellWitnessesThatIWasMurdered(source.getEntity()).
  • Checked with tools/test_command_exec_parity.py, new group tame wolf kills in tools/command_exec_corpus.py. A wild wolf and then a tame wolf owned by the harness player each kill a zombie through /damage … minecraft:mob_attack by <wolf>. After each kill the group probes for experience orbs and reads minecraft.killed:minecraft.zombie, minecraft.custom:minecraft.mob_kills and totalKillCount scores.

Self-check

tools/pr_ready.py doesn't run on Windows, so these are the commands I ran by hand (Windows 11, CARGO_TARGET_DIR set, JDK 25 on PATH):

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean
  • cargo test -p horizon-client --bin horizon-client creatures: 3 passed
  • python tools/test_command_exec_parity.py --only "tame wolf":
    • before (code part reverted): total: 11/14 commands match. After the tame wolf's kill, vanilla has Test passed. Count: 1 (an experience orb), Player has 1 [wolf_mob_kills] and Player has 1 [wolf_total]; Horizon has Test failed and none is set for both scores.
    • after: tame wolf kills: 14/14 commands match, total: 14/14 commands match. The killed-zombie score stays unset in both, as in vanilla.
  • In game on the server thread (survival, the owner tamed the wolf with bones): /damage <zombie> 30 minecraft:mob_attack by <the tame wolf>.
    • before: player XP total 0, mob_kills sidebar 0.
    • after: player XP total 5 (the orbs fly to the owner), sidebar 1.

Screenshots

Same arena, same time of day (noon), same view, 11 seconds after the tame wolf kills a zombie. The sidebar shows a minecraft.custom:minecraft.mob_kills objective.

  • Before: the experience bar is empty and the sidebar shows 0.
  • After: the experience bar is about 70% full (5 XP from the zombie) and the sidebar shows 1.

🤖 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/4259 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3514-tame-wolf-kill-credit` --- ### 📝 Commits (2) - [`0341913`](https://github.com/horizon-rust/horizon/commit/034191391b76fc30408c092b25c8a1c32ca2acff) Credit a tame wolf's kills to its owner - [`1e8f93a`](https://github.com/horizon-rust/horizon/commit/1e8f93a6924f067678a19a9674a3ce1dab132cc3) Check tame wolf kill credit in the command execution harness ### 📊 Changes **3 files changed** (+106 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/commands/world_cmds.rs` (+7 -2) 📝 `crates/horizon-client/src/game/creatures.rs` (+65 -3) 📝 `tools/command_exec_corpus.py` (+34 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Part of #3514 (the `LivingEntity.resolvePlayerResponsibleForDamage (gap)` row). When a tame wolf killed a mob, the kill counted as no one's. `Mob::damage` only set the victim's last-hurt-by-player timer when the attacker was `Who::Player`, and neither `mob_hits_mob` nor `/damage … by <wolf>` credited the wolf's owner. So `mob_died` saw `by_player = false`: the kill dropped no experience and no player-only loot, and the owner's kill counters did not go up. Vanilla's `LivingEntity.hurtServer` calls `resolvePlayerResponsibleForDamage` after every hit that lands. If the causing entity is a tame `Wolf`, it calls `setLastHurtByPlayer(owner uuid, 100)`. A tame wolf with no owner reference clears the field instead. The fix adds `Game::resolve_player_responsible`, which runs after a mob's melee hit lands (`mob_hits_mob`) and after `/damage` with a causing entity: - If the attacker is a tame wolf, the victim's `last_hurt_by_player` timer is set to 100 (0 when the wolf has no owner). - The owner is looked up among the players in the world: the player in place, or a guest by UUID, which covers the single-player owner on the server thread. It is recorded in `last_hurt_by_player`, so `mob_died` credits that player through `credit_kill` (guests through `as_guest`). `die` then credits the owner through `getKillCredit` → `ServerPlayer.awardKillScore`. That awards `mob_kills`, `totalKillCount`, team kills and `player_killed_entity`. It does not award the `killed:<type>` statistic: `Player.killedEntity` awards that one, and vanilla calls it on the causing entity (here the wolf). `credit_kill` used to add `killed:<type>` for every credited kill, so it now skips that stat when the killing blow came from a mob. Two other death hooks read the same `by_player` flag but in vanilla follow the causing entity, not the credited player: `Raider.die` adds a hero of the village only when `source.getEntity()` is a player, and `Villager.die` tells witnesses about `source.getEntity()`. So `mob_died` now passes them `by_player` only when the killing blow did not come from a mob. Without that, a tame wolf killing a raider would make its owner a hero, and a wolf killing a villager would count as a murder by the owner. One limit: when the owner is not in the world (a guest who left), the timer is still set, so experience and loot drop as in vanilla. But no kill-credit entry is recorded, so `mob_died` falls back to its existing "credit the host" path, the same one other timer-only player damage already uses. ## Kind - [x] 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 - `LivingEntity.hurtServer` → `resolvePlayerResponsibleForDamage(DamageSource)`. For a `Player` it calls `setLastHurtByPlayer(player, 100)`. For a `Wolf` with `isTame()` it calls `setLastHurtByPlayer(getOwnerReference().getUUID(), 100)`, or clears `lastHurtByPlayer` when the owner reference is null. - `LivingEntity.die` → `getKillCredit()` (the resolved `lastHurtByPlayer` player, else `lastHurtByMob`) → `awardKillScore`. - `ServerPlayer.awardKillScore`: `KILL_COUNT_ALL`, `MOB_KILLS`, team kills, `PLAYER_KILLED_ENTITY`. `Player.killedEntity` (called on `source.getEntity()`): `ENTITY_KILLED`. - `Raider.die`: `Raid.addHeroOfTheVillage` only when `source.getEntity()` is a player. `Villager.die`: `tellWitnessesThatIWasMurdered(source.getEntity())`. - Checked with `tools/test_command_exec_parity.py`, new group `tame wolf kills` in `tools/command_exec_corpus.py`. A wild wolf and then a tame wolf owned by the harness player each kill a zombie through `/damage … minecraft:mob_attack by <wolf>`. After each kill the group probes for experience orbs and reads `minecraft.killed:minecraft.zombie`, `minecraft.custom:minecraft.mob_kills` and `totalKillCount` scores. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so these are the commands I ran by hand (Windows 11, `CARGO_TARGET_DIR` set, JDK 25 on `PATH`): - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean - `cargo test -p horizon-client --bin horizon-client creatures`: 3 passed - `python tools/test_command_exec_parity.py --only "tame wolf"`: - before (code part reverted): `total: 11/14 commands match`. After the tame wolf's kill, vanilla has `Test passed. Count: 1` (an experience orb), `Player has 1 [wolf_mob_kills]` and `Player has 1 [wolf_total]`; Horizon has `Test failed` and `none is set` for both scores. - after: `tame wolf kills: 14/14 commands match`, `total: 14/14 commands match`. The killed-zombie score stays unset in both, as in vanilla. - In game on the server thread (survival, the owner tamed the wolf with bones): `/damage <zombie> 30 minecraft:mob_attack by <the tame wolf>`. - before: player XP `total 0`, `mob_kills` sidebar 0. - after: player XP `total 5` (the orbs fly to the owner), sidebar 1. ## Screenshots Same arena, same time of day (noon), same view, 11 seconds after the tame wolf kills a zombie. The sidebar shows a `minecraft.custom:minecraft.mob_kills` objective. - Before: the experience bar is empty and the sidebar shows 0. - After: the experience bar is about 70% full (5 XP from the zombie) and the sidebar shows 1. 🤖 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:13:10 +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#5524
No description provided.