[PR #3559] [MERGED] Attack indicator shows at a spear's extra range #5050

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

📋 Pull Request Information

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

Base: main ← Head: fix-3209


📝 Commits (1)

  • c8915be Attack indicator shows at a spear's extra range

📊 Changes

2 files changed (+175 additions, -57 deletions)

View changed files

📝 crates/horizon-client/src/game/hand.rs (+103 -19)
📝 crates/horizon-client/src/game/spear.rs (+72 -38)

📄 Description

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

What and why

Fixes #3209

A spear hits a mob 4 blocks away, but the crosshair attack indicator only showed within 3 blocks. crosshair_living (game/hand.rs) took its living target from mob_hit(), which stops at the 3 blocks of entityInteractionRange (5 in creative). Beyond that it found no target, so the indicator never filled.

Vanilla picks in a different order. LocalPlayer.raycastHitResult first checks whether the active item has an attack_range component. If it does, it picks along that range with AttackRange.getClosesetHit: from the minimum reach to the maximum reach plus the player's movement along the view, with entity boxes grown by the hitbox margin and stopped by block outlines. Only a miss falls back to the plain pick. Hud then keeps the indicator only while AttackRange.isInRange holds for that hit.

  • crosshair_living now picks along the held item's attack_range first (reach_pick), and only falls back to mob_hit and armor stands when that pick misses. The existing isInRange check stays.
  • game/spear.rs: the stab's ProjectileUtil.getHitEntitiesAlong / getManyEntityHitResult code is now free functions (hits_in_reach, hits_along) over mob boxes, which also return where each box is hit. The spear's stab uses them with collider clipping, as before. The crosshair uses them with outline clipping, as getClosesetHit (ClipContext.Block.OUTLINE) does. The stab behaves the same as before.

Only mobs are picked along the range. Armor stands, paintings, frames, boats and carts still come from their usual 3-block picks (vanilla's CAN_BE_PICKED would include them), and when one of them is nearer it still hides the indicator.

Vanilla reference

  • net.minecraft.client.player.LocalPlayer.raycastHitResult
  • net.minecraft.world.item.component.AttackRange.getClosesetHit, effectiveMinRange, effectiveMaxRange, isInRange
  • net.minecraft.world.entity.projectile.ProjectileUtil.getHitEntitiesAlong (both overloads), getManyEntityHitResult
  • net.minecraft.client.gui.Hud crosshair: crosshairPickEntity instanceof LivingEntity, attack strength, and AttackRange.isInRange(player, hitResult.getLocation()) when the active item has a range

Checked with javap -c -p on the 26.3 client jar.

Tests

game::hand::tests::a_spear_picks_a_mob_past_the_plain_reach: a mob whose near face is 4 blocks ahead is picked at 4.0 with an iron spear's range (min 2, max 4.5, margin 0.125), and that distance is inside isInRange. The test also checks two misses: a mob at 4.7 blocks (past max + margin), and a block nearer than the minimum reach.

Before (reach_pick returning None, so only the plain pick runs, as on main):

test game::hand::tests::a_spear_picks_a_mob_past_the_plain_reach ... FAILED
assertion `left == right` failed
  left: None
 right: Some(4.0)
test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 144 filtered out

After:

test game::hand::tests::a_spear_picks_a_mob_past_the_plain_reach ... ok
test game::hand::tests::attack_range_uses_inclusive_float_bounds ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 144 filtered out

Self-check

tools/pr_ready.py wasn't run on this Windows machine. I ran these instead, with CARGO_TARGET_DIR set:

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client --features mods --all-targets -- -D warnings: clean
  • cargo test -p horizon-client --features mods --bin horizon-client hand::tests: 2 passed

In game

In game (server thread, survival), with an iron spear and a NoAI zombie straight ahead. I checked the crosshair in screenshots at each distance.

  • Before, near face 4.0 blocks away: no indicator. horizon-ctl looking-at reports no entity, but a jab still hurts the zombie (health 20 → 17.06).
  • Before, 2.5 blocks away (control): the indicator shows.
  • After, 4.0 blocks: the indicator shows.
  • After, 4.7 blocks (past 4.5 + 0.125): no indicator, as vanilla.
  • After, iron sword at 4.0 blocks: no indicator, as vanilla (3 blocks).
  • After, 2.5 blocks: still shows.

🤖 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/3559 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3209` --- ### 📝 Commits (1) - [`c8915be`](https://github.com/horizon-rust/horizon/commit/c8915be58c5eb60cd3d83a6ea28b30c2d2441729) Attack indicator shows at a spear's extra range ### 📊 Changes **2 files changed** (+175 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/hand.rs` (+103 -19) 📝 `crates/horizon-client/src/game/spear.rs` (+72 -38) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. ## What and why Fixes #3209 A spear hits a mob 4 blocks away, but the crosshair attack indicator only showed within 3 blocks. `crosshair_living` (game/hand.rs) took its living target from `mob_hit()`, which stops at the 3 blocks of `entityInteractionRange` (5 in creative). Beyond that it found no target, so the indicator never filled. Vanilla picks in a different order. `LocalPlayer.raycastHitResult` first checks whether the active item has an `attack_range` component. If it does, it picks along that range with `AttackRange.getClosesetHit`: from the minimum reach to the maximum reach plus the player's movement along the view, with entity boxes grown by the hitbox margin and stopped by block outlines. Only a miss falls back to the plain pick. `Hud` then keeps the indicator only while `AttackRange.isInRange` holds for that hit. - `crosshair_living` now picks along the held item's `attack_range` first (`reach_pick`), and only falls back to `mob_hit` and armor stands when that pick misses. The existing `isInRange` check stays. - `game/spear.rs`: the stab's `ProjectileUtil.getHitEntitiesAlong` / `getManyEntityHitResult` code is now free functions (`hits_in_reach`, `hits_along`) over mob boxes, which also return where each box is hit. The spear's stab uses them with collider clipping, as before. The crosshair uses them with outline clipping, as `getClosesetHit` (`ClipContext.Block.OUTLINE`) does. The stab behaves the same as before. Only mobs are picked along the range. Armor stands, paintings, frames, boats and carts still come from their usual 3-block picks (vanilla's `CAN_BE_PICKED` would include them), and when one of them is nearer it still hides the indicator. ## Vanilla reference - `net.minecraft.client.player.LocalPlayer.raycastHitResult` - `net.minecraft.world.item.component.AttackRange.getClosesetHit`, `effectiveMinRange`, `effectiveMaxRange`, `isInRange` - `net.minecraft.world.entity.projectile.ProjectileUtil.getHitEntitiesAlong` (both overloads), `getManyEntityHitResult` - `net.minecraft.client.gui.Hud` crosshair: `crosshairPickEntity instanceof LivingEntity`, attack strength, and `AttackRange.isInRange(player, hitResult.getLocation())` when the active item has a range Checked with `javap -c -p` on the 26.3 client jar. ## Tests `game::hand::tests::a_spear_picks_a_mob_past_the_plain_reach`: a mob whose near face is 4 blocks ahead is picked at 4.0 with an iron spear's range (min 2, max 4.5, margin 0.125), and that distance is inside `isInRange`. The test also checks two misses: a mob at 4.7 blocks (past max + margin), and a block nearer than the minimum reach. Before (`reach_pick` returning `None`, so only the plain pick runs, as on main): ``` test game::hand::tests::a_spear_picks_a_mob_past_the_plain_reach ... FAILED assertion `left == right` failed left: None right: Some(4.0) test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 144 filtered out ``` After: ``` test game::hand::tests::a_spear_picks_a_mob_past_the_plain_reach ... ok test game::hand::tests::attack_range_uses_inclusive_float_bounds ... ok test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 144 filtered out ``` ## Self-check `tools/pr_ready.py` wasn't run on this Windows machine. I ran these instead, with `CARGO_TARGET_DIR` set: - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client --features mods --all-targets -- -D warnings`: clean - `cargo test -p horizon-client --features mods --bin horizon-client hand::tests`: 2 passed ## In game In game (server thread, survival), with an iron spear and a NoAI zombie straight ahead. I checked the crosshair in screenshots at each distance. - Before, near face 4.0 blocks away: no indicator. `horizon-ctl looking-at` reports no entity, but a jab still hurts the zombie (health 20 → 17.06). - Before, 2.5 blocks away (control): the indicator shows. - After, 4.0 blocks: the indicator shows. - After, 4.7 blocks (past 4.5 + 0.125): no indicator, as vanilla. - After, iron sword at 4.0 blocks: no indicator, as vanilla (3 blocks). - After, 2.5 blocks: still shows. 🤖 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:09:53 +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#5050
No description provided.