[PR #4542] [MERGED] Crossbow piglins back away from a target within 5 blocks (BackUpIfTooClose) #5687

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4542
Author: @xFedeT
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/piglin-back-up


📝 Commits (1)

  • 9ad0a3a Crossbow piglins back away from a target within 5 blocks (BackUpIfTooClose)

📊 Changes

2 files changed (+44 additions, -1 deletions)

View changed files

📝 crates/horizon-client/src/mobs/piglin.rs (+43 -0)
📝 tools/port_map/game-007.tsv (+1 -1)

📄 Description

🤖 Opened by xFedeT's AI agent (Claude Code, Sonnet 5.5), not by xFedeT personally.

Refs #3521 (row BackUpIfTooClose.create)

What

A piglin holding a crossbow stayed put when you came close. In vanilla PiglinAi.initFightActivity runs BackUpIfTooClose.create(5, 0.75) behind hasCrossbow: with no walk target and the attack target in sight within 5 blocks, the piglin looks at it, strafes backwards at 0.75 and keeps its head and body aligned (Mth.rotateIfNecessary(yRot, yHeadRot, 0)), while CrossbowAttack keeps aiming.

I read BackUpIfTooClose.java first and ported each step in order. Horizon's piglin runs on goals, so the behaviour is a goal with no flags (it runs beside the crossbow goal, as the two behaviours do in the brain): mobs/piglin.rs::BackUpIfTooClose. Entity.closerThan is the 3D Vec3.closerThan check (< 5), "target visible" is Mob::sees, "no walk target" is a finished navigation.

Proof

Real game (horizon-ctl, scratch dirs, a survival player with resistance, a stone platform, a piglin given a crossbow). The player stands 2 blocks from the piglin. It backs off while aiming and stops at about 5.2 blocks (distance in blocks, one sample every 3 ticks; the goal list shows BackUpIfTooClose only while it is closer than 5):

dist 1.12 ['CrossbowAttack', 'BackUpIfTooClose']
dist 2.37 ['CrossbowAttack', 'BackUpIfTooClose']
dist 3.96 ['CrossbowAttack', 'BackUpIfTooClose']
dist 5.19 ['CrossbowAttack']
dist 5.28 ['CrossbowAttack']

Start (2 blocks) After (about 5 blocks, still aiming)

Notes

  • No tick-for-tick parity check: the mob_ai probe has no piglin brain (same limit as in the villager/door work). The logic was compared with the vanilla class by reading it.
  • Depends on #4362 to show up in game: on current main a crossbow piglin does not get the crossbow goal (it is registered before the spawn weapon is equipped), so it melees. I tested with #4362's change applied locally and left it out of this PR to avoid a conflict. This goal checks the held item itself, so it works either way once that lands.
  • pr_ready --quick: fmt, clippy, 1064 horizon-client tests and 481 Python tests pass.

🤖 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/4542 **Author:** [@xFedeT](https://github.com/xFedeT) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/piglin-back-up` --- ### 📝 Commits (1) - [`9ad0a3a`](https://github.com/horizon-rust/horizon/commit/9ad0a3abf18e290646f39f72dcae856e6f07a809) Crossbow piglins back away from a target within 5 blocks (BackUpIfTooClose) ### 📊 Changes **2 files changed** (+44 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/mobs/piglin.rs` (+43 -0) 📝 `tools/port_map/game-007.tsv` (+1 -1) </details> ### 📄 Description > 🤖 Opened by xFedeT's AI agent (Claude Code, Sonnet 5.5), not by xFedeT personally. Refs #3521 (row `BackUpIfTooClose.create`) ## What A piglin holding a crossbow stayed put when you came close. In vanilla `PiglinAi.initFightActivity` runs `BackUpIfTooClose.create(5, 0.75)` behind `hasCrossbow`: with no walk target and the attack target in sight within 5 blocks, the piglin looks at it, strafes backwards at 0.75 and keeps its head and body aligned (`Mth.rotateIfNecessary(yRot, yHeadRot, 0)`), while `CrossbowAttack` keeps aiming. I read `BackUpIfTooClose.java` first and ported each step in order. Horizon's piglin runs on goals, so the behaviour is a goal with no flags (it runs beside the crossbow goal, as the two behaviours do in the brain): `mobs/piglin.rs::BackUpIfTooClose`. `Entity.closerThan` is the 3D `Vec3.closerThan` check (`< 5`), "target visible" is `Mob::sees`, "no walk target" is a finished navigation. ## Proof Real game (`horizon-ctl`, scratch dirs, a survival player with resistance, a stone platform, a piglin given a crossbow). The player stands 2 blocks from the piglin. It backs off while aiming and stops at about 5.2 blocks (distance in blocks, one sample every 3 ticks; the goal list shows `BackUpIfTooClose` only while it is closer than 5): ``` dist 1.12 ['CrossbowAttack', 'BackUpIfTooClose'] dist 2.37 ['CrossbowAttack', 'BackUpIfTooClose'] dist 3.96 ['CrossbowAttack', 'BackUpIfTooClose'] dist 5.19 ['CrossbowAttack'] dist 5.28 ['CrossbowAttack'] ``` ![](https://raw.githubusercontent.com/xFedeT/horizon/pr-screenshots/piglin-back-up/backup.gif) | Start (2 blocks) | After (about 5 blocks, still aiming) | |---|---| | ![](https://raw.githubusercontent.com/xFedeT/horizon/pr-screenshots/piglin-back-up/before.png) | ![](https://raw.githubusercontent.com/xFedeT/horizon/pr-screenshots/piglin-back-up/after.png) | ## Notes - No tick-for-tick parity check: the `mob_ai` probe has no piglin brain (same limit as in the villager/door work). The logic was compared with the vanilla class by reading it. - Depends on #4362 to show up in game: on current main a crossbow piglin does not get the crossbow goal (it is registered before the spawn weapon is equipped), so it melees. I tested with #4362's change applied locally and left it out of this PR to avoid a conflict. This goal checks the held item itself, so it works either way once that lands. - `pr_ready --quick`: fmt, clippy, 1064 `horizon-client` tests and 481 Python tests pass. 🤖 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:14:19 +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#5687
No description provided.