[PR #4967] [MERGED] Drop a saved anger at a player a golem cannot attack #5978

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4967
Author: @MSedgeMC
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/golem-anger-and-cracks


📝 Commits (2)

📊 Changes

3 files changed (+159 additions, -3 deletions)

View changed files

📝 crates/horizon-client/src/game/persist.rs (+4 -2)
📝 crates/horizon-client/src/mobs/goals.rs (+32 -1)
📝 crates/horizon-client/src/mobs/golem.rs (+123 -0)

📄 Description

One behaviour fix, plus the tests two behaviours never had. (No issue.)

The bug. Vanilla restores persistent anger through NeutralMob.readPersistentAngerSaveData → setTarget(getLivingEntity(…)), and Mob.setTarget stores asValidTarget(t), which returns null when the mob !canAttack(t) — and IronGolem.canAttack refuses every player when isPlayerCreated(). Horizon's world load (game/persist.rs) wrote the target straight into ai.target, so an angry player-built golem loaded from a save kept its builder as a target, and the golem's melee goal never re-checks canAttack, so it swung. NeutralMob.updatePersistentAnger never re-sets the target, so dropping it at load is complete rather than a delay until the next tick.

The golem clause of spares_players is now Mob::built_by_player, used by both the restore and the target goals, so the rule lives in one place.

What I deliberately did not widen. asValidTarget's first clause — a creative or spectator player — is not readable at that site: the level's owner is the server-thread hub, which has no player of its own and swaps each guest into self per tick, so self.creative there is not the loading player's mode. That clause is already covered where the mode is known (can_target_player, and tame::update_persistent_anger for pets). A restored anger at a mob is likewise still unmodelled; extra.angry_at is player-only.

Tests. only_a_golem_spares_the_player_that_built_it (data-free): a golem built by a player answers yes, a village golem no, and a zombie with the same flag no, so loosening the rule away from the species gate fails. a_golem_a_player_built_never_targets_one and a_crack_is_heard_once_at_the_threshold pin two behaviours that already work — the creator rule (e3fda9ce6) and the crack sound (d686f4b9d) — neither of which shipped a test. They are green against main by design; I am not claiming a fix there, the fix is the restore above.

Proven: on a build box with the prepared data, cargo test -p horizon-client --lib built_by_player → 1 passed and the whole --lib golem set → 10 passed.

Not proven: the restore itself has no test — load_mob needs a whole Game and there is no bin seam for it. The game-level check: save an angry player-built iron golem (PlayerCreated:1b, 400 ticks of anger, angry_at a player), reload in survival, and confirm it holds no target and does not swing at its builder while a village golem still targets the player.


🔄 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/4967 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/golem-anger-and-cracks` --- ### 📝 Commits (2) - [`486464c`](https://github.com/horizon-rust/horizon/commit/486464c829fd10cf0dc2499a26579d4393bc5e6f) Drop a saved anger at a player a golem cannot attack - [`b783268`](https://github.com/horizon-rust/horizon/commit/b783268374ff1dd033a267d4b5a36c78cadcdd43) Merge main into #4967 ### 📊 Changes **3 files changed** (+159 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/persist.rs` (+4 -2) 📝 `crates/horizon-client/src/mobs/goals.rs` (+32 -1) 📝 `crates/horizon-client/src/mobs/golem.rs` (+123 -0) </details> ### 📄 Description One behaviour fix, plus the tests two behaviours never had. (No issue.) **The bug.** Vanilla restores persistent anger through `NeutralMob.readPersistentAngerSaveData` → `setTarget(getLivingEntity(…))`, and `Mob.setTarget` stores `asValidTarget(t)`, which returns null when the mob `!canAttack(t)` — and `IronGolem.canAttack` refuses **every** player when `isPlayerCreated()`. Horizon's world load (`game/persist.rs`) wrote the target straight into `ai.target`, so an angry player-built golem loaded from a save kept its builder as a target, and the golem's melee goal never re-checks `canAttack`, so it swung. `NeutralMob.updatePersistentAnger` never re-sets the target, so dropping it at load is complete rather than a delay until the next tick. The golem clause of `spares_players` is now `Mob::built_by_player`, used by both the restore and the target goals, so the rule lives in one place. **What I deliberately did not widen.** `asValidTarget`'s first clause — a creative or spectator player — is not readable at that site: the level's owner is the server-thread hub, which has no player of its own and swaps each guest into `self` per tick, so `self.creative` there is not the loading player's mode. That clause is already covered where the mode is known (`can_target_player`, and `tame::update_persistent_anger` for pets). A restored anger at a *mob* is likewise still unmodelled; `extra.angry_at` is player-only. **Tests.** `only_a_golem_spares_the_player_that_built_it` (data-free): a golem built by a player answers yes, a village golem no, and a zombie with the same flag no, so loosening the rule away from the species gate fails. `a_golem_a_player_built_never_targets_one` and `a_crack_is_heard_once_at_the_threshold` pin two behaviours that already work — the creator rule (`e3fda9ce6`) and the crack sound (`d686f4b9d`) — neither of which shipped a test. They are green against `main` by design; I am not claiming a fix there, the fix is the restore above. **Proven:** on a build box with the prepared data, `cargo test -p horizon-client --lib built_by_player` → 1 passed and the whole `--lib golem` set → 10 passed. **Not proven:** the restore itself has no test — `load_mob` needs a whole `Game` and there is no bin seam for it. The game-level check: save an angry player-built iron golem (`PlayerCreated:1b`, 400 ticks of anger, `angry_at` a player), reload in survival, and confirm it holds no target and does not swing at its builder while a village golem still targets the player. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:21 +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#5978
No description provided.