[PR #6340] [MERGED] Send an iron golem to a spot near its target, not straight at it #6811

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

📋 Pull Request Information

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

Base: main ← Head: fix/golem-move-towards


📝 Commits (1)

  • 367515a Send an iron golem to a spot near its target, not straight at it

📊 Changes

1 file changed (+89 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/mobs/golem.rs (+89 -4)

📄 Description

MoveTowardsTargetGoal (what IronGolem.registerGoals adds at priority 2) does not walk to
the target itself:

// javap -p -c on MoveTowardsTargetGoal, in canUse
50: bipush        16
52: bipush        7
56: getfield      target
59: invokevirtual LivingEntity.position
62: ldc2_w        1.5707963705062866     // PI / 2
65: invokestatic  DefaultRandomPos.getPosTowards:(PathfinderMob,IILnet/minecraft/world/phys/Vec3;D)Vec3
69: ifnonnull     75
73: iconst_0                              // no spot: the goal does not run
75-96: store x, y, z
// start: getNavigation().moveTo(wantedX, wantedY, wantedZ, speedModifier)

Horizon's MoveTowardsTarget::can_use called nav_move_to_entity at the target's position
and navigated there, so a golem's approach was always dead straight and always aimed at the
entity rather than at a point near it.

Proven: on the build VM, cargo test -q -p horizon-client --lib an_iron_golem_walks_to_a_spot_near_its_target
→ 1 passed: the picked spot is within 16 blocks horizontally and 7 vertically of the golem,
and its horizontal step is at most 90 degrees off the step to the target (the cone
getPosTowards accepts). cargo clippy -q -p horizon-client --lib --tests -- -D warnings is
clean.

Not proven: not checked in game; the check is an iron golem approaching a zombie and taking
a slightly random line, and standing still when no spot is found.

Two notes on the test: it tries mob ids in turn because the spot is random (the mob's seed
comes from its id) and a flat test world only offers a few workable heights, so a single draw
often finds nothing - which is also vanilla's behaviour when getPosTowards returns null.

Note (added after the crate split): the tests under crates/horizon-client/src/ other than game/ and entry/ are now compiled by the horizon-client-lib crate, so the command above is cargo test -p horizon-client-lib --lib <filter> on current main. The change and the assertions are unchanged.


🔄 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/6340 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/golem-move-towards` --- ### 📝 Commits (1) - [`367515a`](https://github.com/horizon-rust/horizon/commit/367515af39e761dff141e126c40d8da49e3dd633) Send an iron golem to a spot near its target, not straight at it ### 📊 Changes **1 file changed** (+89 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/golem.rs` (+89 -4) </details> ### 📄 Description `MoveTowardsTargetGoal` (what `IronGolem.registerGoals` adds at priority 2) does not walk to the target itself: ```java // javap -p -c on MoveTowardsTargetGoal, in canUse 50: bipush 16 52: bipush 7 56: getfield target 59: invokevirtual LivingEntity.position 62: ldc2_w 1.5707963705062866 // PI / 2 65: invokestatic DefaultRandomPos.getPosTowards:(PathfinderMob,IILnet/minecraft/world/phys/Vec3;D)Vec3 69: ifnonnull 75 73: iconst_0 // no spot: the goal does not run 75-96: store x, y, z // start: getNavigation().moveTo(wantedX, wantedY, wantedZ, speedModifier) ``` Horizon's `MoveTowardsTarget::can_use` called `nav_move_to_entity` at the target's position and navigated there, so a golem's approach was always dead straight and always aimed at the entity rather than at a point near it. **Proven:** on the build VM, `cargo test -q -p horizon-client --lib an_iron_golem_walks_to_a_spot_near_its_target` → `1 passed`: the picked spot is within 16 blocks horizontally and 7 vertically of the golem, and its horizontal step is at most 90 degrees off the step to the target (the cone `getPosTowards` accepts). `cargo clippy -q -p horizon-client --lib --tests -- -D warnings` is clean. **Not proven:** not checked in game; the check is an iron golem approaching a zombie and taking a slightly random line, and standing still when no spot is found. Two notes on the test: it tries mob ids in turn because the spot is random (the mob's seed comes from its id) and a flat test world only offers a few workable heights, so a single draw often finds nothing - which is also vanilla's behaviour when `getPosTowards` returns null. Note (added after the crate split): the tests under `crates/horizon-client/src/` other than `game/` and `entry/` are now compiled by the `horizon-client-lib` crate, so the command above is `cargo test -p horizon-client-lib --lib <filter>` on current main. The change and the assertions are unchanged. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:27:20 +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#6811
No description provided.