[PR #3948] [MERGED] Mobs use spears; iron golems keep to their village #5311

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

📋 Pull Request Information

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

Base: main ← Head: fix/split-spear-ai-golem


📝 Commits (10+)

  • 952fc5a Add LandRandomPos.getPosTowards for mobs that lean toward a spot
  • 2947c2d Share the spear hit search with the mob code
  • 89cbb09 Let mobs stab with a spear they are using
  • 26f4614 Make zombies and zombified piglins charge with a spear
  • b6f3d91 Raise the spear arm of zombies and piglins
  • 2153681 Make piglins with a golden spear close in on 10 blocks
  • 8ce62d3 Make piglins raise the spear to charge a target
  • 5968cd0 Make piglins run at the target and reposition mid-charge
  • 71092ca Make piglins back off 9 to 11 blocks after a spear charge
  • eba7cb0 Make iron golems return to and patrol their village

📊 Changes

17 files changed (+1482 additions, -86 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+3 -1)
📝 crates/horizon-client/src/game/lan.rs (+4 -0)
📝 crates/horizon-client/src/game/lan_mobs.rs (+3 -0)
📝 crates/horizon-client/src/game/mounts.rs (+6 -1)
📝 crates/horizon-client/src/game/spear.rs (+1 -57)
📝 crates/horizon-client/src/mobs.rs (+13 -0)
📝 crates/horizon-client/src/mobs/ai.rs (+6 -0)
📝 crates/horizon-client/src/mobs/anim.rs (+18 -1)
📝 crates/horizon-client/src/mobs/doors.rs (+1 -1)
📝 crates/horizon-client/src/mobs/goals.rs (+93 -8)
📝 crates/horizon-client/src/mobs/golem.rs (+138 -1)
📝 crates/horizon-client/src/mobs/piglin.rs (+57 -8)
📝 crates/horizon-client/src/mobs/render.rs (+1 -1)
➕ crates/horizon-client/src/mobs/spear_use.rs (+881 -0)
📝 crates/horizon-client/src/mobs/undead.rs (+152 -1)
📝 crates/horizon-client/src/mobs/villager_brain.rs (+38 -5)
📝 crates/horizon-client/src/spear.rs (+67 -1)

📄 Description

What and why

  • Add LandRandomPos.getPosTowards for mobs that lean toward a spot: Horizon only had getPosAway on land. Vanilla's LandRandomPos.getPosTowards (LandRandomPos.java:23) takes the direction to the point and goes through getPosInDirection, a quarter turn (float cast pi/2) either side. getPosAway now shares that helper, so it uses the same float-cast angle.
  • Share the spear hit search with the mob code: The stab's entity search (ProjectileUtil.getHitEntitiesAlong) lived in the game crate's spear module; mobs that stab need it from the client library, so it moves to the spear module there and the game keeps using it.
  • Let mobs stab with a spear they are using: A mob that held a spear could not use it: nothing started its use or ran KineticWeapon.damageEntities for it. A mob's use now counts ticks like the player's, stabs along its view from delay_ticks on (conditions scaled by 0.2, reach by the AttackRange mob_factor), hurts and pushes the player or mobs hit, dismounts riders and broadcasts entity event 2 (LivingEntity.stabAttack, causeExtraKnockback). A piglin's admiring is told apart from a spear in use by the off hand.
  • Make zombies and zombified piglins charge with a spear: Zombies, husks, zombie villagers and zombified piglins spawned with a spear just melee. SpearUseGoal (priority 2, and 1 for zombified piglins) walks to 10 blocks, lowers the spear for KineticWeapon.computeDamageUseDuration (halved, the goal ticks every other tick), charges along the target, repositions 6 to 7 blocks away, then backs off 9 to 11 blocks (LandRandomPos.getPosAway with a minimum distance) for up to 50 goal ticks. A mount's chargeSpeedModifier and the 2 blocks a passenger adds are kept.
  • Raise the spear arm of zombies and piglins: HumanoidMobRenderer.getArmPose gives an arm holding a spear the SPEAR pose, which AnimationUtils.animateZombieArms leaves alone; the mobs here drew zombie or piglin arms around it. Zombies, husks, zombie villagers, zombified piglins and piglins now hold the spear out and charge it by their use time, and a piglin admiring gold no longer counts as using the spear in its main hand.
  • Make piglins with a golden spear close in on 10 blocks: A piglin holding a golden spear (about 1 in 20 adults) walked up and meleed. PiglinAi.initFightActivity puts SpearApproach before the melee behaviour: with a target, a spear and no item in use, and no SPEAR_STATUS yet (checkExtraStartConditions), it sets the status APPROACH and walks to the target until it is within 10 blocks (SpearApproach.java), then the status is CHARGING. A piglin with a spear no longer melees (MeleeAttack.isHoldingUsableNonMeleeWeapon).
  • Make piglins raise the spear to charge a target: After closing in, a piglin with a golden spear never lowered it to attack. SpearAttack starts on the CHARGING status with a target, a spear and no item in use: it becomes aggressive, sets SPEAR_ENGAGE_TIME to the weapon's use time (KineticWeapon.computeDamageUseDuration), erases SPEAR_CHARGE_POSITION and starts using the spear (SpearAttack.start); the charge counts down while it looks at the target and ends in the RETREAT status (SpearAttack.java).
  • Make piglins run at the target and reposition mid-charge: A charging piglin stood still. SpearAttack.tick moves it every tick: run at the target (SpearAttack.java), and within 2 blocks of it or at the end of the path pick a spot 6 to 7 blocks past it (LandRandomPos.getPosAway, 2 more blocks on a mount) to run to, erasing it at the end of the path so it runs at the target again, until SPEAR_ENGAGE_TIME ends.
  • Make piglins back off 9 to 11 blocks after a spear charge: A piglin that charged with a spear stayed on its target. SpearRetreat starts on the RETREAT status with a target, a spear and no item in use when LandRandomPos.getPosAway finds a spot 9 to 11 blocks away (checkExtraStartConditions), remembers it as SPEAR_FLEEING_POSITION, walks there for up to 100 ticks while looking at the target, and ends by erasing the status so the next approach starts (SpearRetreat.java).
  • Make iron golems return to and patrol their village: Golems strolled anywhere at 0.6 (the plain stroll) and never went home. Vanilla IronGolem.registerGoals (IronGolem.java:68) adds MoveBackToVillageGoal at priority 2 (a stroll every 10 ticks, toward the section within 2 closest to a village, only outside the village) and GolemRandomStrollInVillageGoal at 4 (every 240 ticks: 3 in 10 anywhere, else toward a villager who wants a golem or a taken POI in a village section, from the level's random). Both are RandomStrollGoal subclasses, so Stroll takes an overriding spot picker and canUse test; the village sections and POI tickets come from the villager brain's helpers.
  • Walk zombies through their village at night: Zombies, husks and zombie villagers wandered with the plain stroll only. Vanilla Zombie.addBehaviourGoals adds MoveThroughVillageGoal(1.0, onlyAtNight, 4, canBreakDoors) at priority 6 (MoveThroughVillageGoal.java): within 6 sections of a village, pick the land spot (15, 7) whose nearest taken, unvisited village POI is closest, path to that POI (or ten blocks toward it, or only as far as a wooden door), and remember the 16 last POIs reached. The weighted land position now also honours a restricted home like vanilla's LandRandomPos.getPos.

Vanilla reference

Each commit message names the vanilla method and file it follows: LandRandomPos.java:23, SpearApproach.java, SpearAttack.java, SpearRetreat.java, IronGolem.java:68, MoveThroughVillageGoal.java

Self-check

Split out of #3926; rustfmt on changed files; built by CI; not run in game.


🔄 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/3948 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix/split-spear-ai-golem` --- ### 📝 Commits (10+) - [`952fc5a`](https://github.com/horizon-rust/horizon/commit/952fc5a1f5e3bc14101aacb5fd90d30ef9e2b9bd) Add LandRandomPos.getPosTowards for mobs that lean toward a spot - [`2947c2d`](https://github.com/horizon-rust/horizon/commit/2947c2d71f0f6858a7641ef708ffd7ee97080bd3) Share the spear hit search with the mob code - [`89cbb09`](https://github.com/horizon-rust/horizon/commit/89cbb09961e56692bdada178722b7fae3d2e1b25) Let mobs stab with a spear they are using - [`26f4614`](https://github.com/horizon-rust/horizon/commit/26f46141c7e7e93729339b172f9800a8cdc4ea58) Make zombies and zombified piglins charge with a spear - [`b6f3d91`](https://github.com/horizon-rust/horizon/commit/b6f3d91b091a55b95c6dcdd479c950dbe8b15ff8) Raise the spear arm of zombies and piglins - [`2153681`](https://github.com/horizon-rust/horizon/commit/2153681d4708fffa20b0bd96f7638fb84e5e4928) Make piglins with a golden spear close in on 10 blocks - [`8ce62d3`](https://github.com/horizon-rust/horizon/commit/8ce62d3aaac43cbd9d75de02d77f845dcb9824dc) Make piglins raise the spear to charge a target - [`5968cd0`](https://github.com/horizon-rust/horizon/commit/5968cd0f093c6e102651f3a3aa8f61882cc253ab) Make piglins run at the target and reposition mid-charge - [`71092ca`](https://github.com/horizon-rust/horizon/commit/71092caa147d57d4b1080e28b1ac75c084e8f783) Make piglins back off 9 to 11 blocks after a spear charge - [`eba7cb0`](https://github.com/horizon-rust/horizon/commit/eba7cb0409407588e495c42f72e43c4a96a6d9c1) Make iron golems return to and patrol their village ### 📊 Changes **17 files changed** (+1482 additions, -86 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+3 -1) 📝 `crates/horizon-client/src/game/lan.rs` (+4 -0) 📝 `crates/horizon-client/src/game/lan_mobs.rs` (+3 -0) 📝 `crates/horizon-client/src/game/mounts.rs` (+6 -1) 📝 `crates/horizon-client/src/game/spear.rs` (+1 -57) 📝 `crates/horizon-client/src/mobs.rs` (+13 -0) 📝 `crates/horizon-client/src/mobs/ai.rs` (+6 -0) 📝 `crates/horizon-client/src/mobs/anim.rs` (+18 -1) 📝 `crates/horizon-client/src/mobs/doors.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/goals.rs` (+93 -8) 📝 `crates/horizon-client/src/mobs/golem.rs` (+138 -1) 📝 `crates/horizon-client/src/mobs/piglin.rs` (+57 -8) 📝 `crates/horizon-client/src/mobs/render.rs` (+1 -1) ➕ `crates/horizon-client/src/mobs/spear_use.rs` (+881 -0) 📝 `crates/horizon-client/src/mobs/undead.rs` (+152 -1) 📝 `crates/horizon-client/src/mobs/villager_brain.rs` (+38 -5) 📝 `crates/horizon-client/src/spear.rs` (+67 -1) </details> ### 📄 Description ## What and why - Add LandRandomPos.getPosTowards for mobs that lean toward a spot: Horizon only had getPosAway on land. Vanilla's LandRandomPos.getPosTowards (LandRandomPos.java:23) takes the direction to the point and goes through getPosInDirection, a quarter turn (float cast pi/2) either side. getPosAway now shares that helper, so it uses the same float-cast angle. - Share the spear hit search with the mob code: The stab's entity search (ProjectileUtil.getHitEntitiesAlong) lived in the game crate's spear module; mobs that stab need it from the client library, so it moves to the spear module there and the game keeps using it. - Let mobs stab with a spear they are using: A mob that held a spear could not use it: nothing started its use or ran KineticWeapon.damageEntities for it. A mob's use now counts ticks like the player's, stabs along its view from delay_ticks on (conditions scaled by 0.2, reach by the AttackRange mob_factor), hurts and pushes the player or mobs hit, dismounts riders and broadcasts entity event 2 (LivingEntity.stabAttack, causeExtraKnockback). A piglin's admiring is told apart from a spear in use by the off hand. - Make zombies and zombified piglins charge with a spear: Zombies, husks, zombie villagers and zombified piglins spawned with a spear just melee. SpearUseGoal (priority 2, and 1 for zombified piglins) walks to 10 blocks, lowers the spear for KineticWeapon.computeDamageUseDuration (halved, the goal ticks every other tick), charges along the target, repositions 6 to 7 blocks away, then backs off 9 to 11 blocks (LandRandomPos.getPosAway with a minimum distance) for up to 50 goal ticks. A mount's chargeSpeedModifier and the 2 blocks a passenger adds are kept. - Raise the spear arm of zombies and piglins: HumanoidMobRenderer.getArmPose gives an arm holding a spear the SPEAR pose, which AnimationUtils.animateZombieArms leaves alone; the mobs here drew zombie or piglin arms around it. Zombies, husks, zombie villagers, zombified piglins and piglins now hold the spear out and charge it by their use time, and a piglin admiring gold no longer counts as using the spear in its main hand. - Make piglins with a golden spear close in on 10 blocks: A piglin holding a golden spear (about 1 in 20 adults) walked up and meleed. PiglinAi.initFightActivity puts SpearApproach before the melee behaviour: with a target, a spear and no item in use, and no SPEAR_STATUS yet (checkExtraStartConditions), it sets the status APPROACH and walks to the target until it is within 10 blocks (SpearApproach.java), then the status is CHARGING. A piglin with a spear no longer melees (MeleeAttack.isHoldingUsableNonMeleeWeapon). - Make piglins raise the spear to charge a target: After closing in, a piglin with a golden spear never lowered it to attack. SpearAttack starts on the CHARGING status with a target, a spear and no item in use: it becomes aggressive, sets SPEAR_ENGAGE_TIME to the weapon's use time (KineticWeapon.computeDamageUseDuration), erases SPEAR_CHARGE_POSITION and starts using the spear (SpearAttack.start); the charge counts down while it looks at the target and ends in the RETREAT status (SpearAttack.java). - Make piglins run at the target and reposition mid-charge: A charging piglin stood still. SpearAttack.tick moves it every tick: run at the target (SpearAttack.java), and within 2 blocks of it or at the end of the path pick a spot 6 to 7 blocks past it (LandRandomPos.getPosAway, 2 more blocks on a mount) to run to, erasing it at the end of the path so it runs at the target again, until SPEAR_ENGAGE_TIME ends. - Make piglins back off 9 to 11 blocks after a spear charge: A piglin that charged with a spear stayed on its target. SpearRetreat starts on the RETREAT status with a target, a spear and no item in use when LandRandomPos.getPosAway finds a spot 9 to 11 blocks away (checkExtraStartConditions), remembers it as SPEAR_FLEEING_POSITION, walks there for up to 100 ticks while looking at the target, and ends by erasing the status so the next approach starts (SpearRetreat.java). - Make iron golems return to and patrol their village: Golems strolled anywhere at 0.6 (the plain stroll) and never went home. Vanilla IronGolem.registerGoals (IronGolem.java:68) adds MoveBackToVillageGoal at priority 2 (a stroll every 10 ticks, toward the section within 2 closest to a village, only outside the village) and GolemRandomStrollInVillageGoal at 4 (every 240 ticks: 3 in 10 anywhere, else toward a villager who wants a golem or a taken POI in a village section, from the level's random). Both are RandomStrollGoal subclasses, so Stroll takes an overriding spot picker and canUse test; the village sections and POI tickets come from the villager brain's helpers. - Walk zombies through their village at night: Zombies, husks and zombie villagers wandered with the plain stroll only. Vanilla Zombie.addBehaviourGoals adds MoveThroughVillageGoal(1.0, onlyAtNight, 4, canBreakDoors) at priority 6 (MoveThroughVillageGoal.java): within 6 sections of a village, pick the land spot (15, 7) whose nearest taken, unvisited village POI is closest, path to that POI (or ten blocks toward it, or only as far as a wooden door), and remember the 16 last POIs reached. The weighted land position now also honours a restricted home like vanilla's LandRandomPos.getPos. ## Vanilla reference Each commit message names the vanilla method and file it follows: LandRandomPos.java:23, SpearApproach.java, SpearAttack.java, SpearRetreat.java, IronGolem.java:68, MoveThroughVillageGoal.java ## Self-check Split out of #3926; rustfmt on changed files; built by CI; not run in game. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:11:42 +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#5311
No description provided.