[PR #6686] [MERGED] A number key and an attack in one tick swing the new item at the old one's target (spear to mace) #7030

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6686
Author: @Ragbie
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: fix/attack-swap-pick


📝 Commits (5)

  • d073e1d A number key and an attack in one tick swing the new item at the old one's target
  • cbed0c0 Attack swap: the item's pick stops on a block, and its range holds the hit
  • d4f736d Attack swap e2e: the min-reach pig hovers at eye height, fully inside the spear's minimum
  • dfaa286 Attack swap e2e: a tagged pig, the world's own mobs cleared first
  • 0d75e2e Attack swap: pass the clip closure by value (clippy)

📊 Changes

6 files changed (+322 additions, -24 deletions)

View changed files

📝 crates/horizon-client-input/src/interaction_input.rs (+4 -0)
📝 crates/horizon-client/src/game.rs (+22 -2)
📝 crates/horizon-client/src/game/chat.rs (+2 -0)
📝 crates/horizon-client/src/game/hand.rs (+97 -8)
📝 crates/horizon-client/src/game/remote.rs (+41 -14)
➕ tools/attack_swap_e2e.py (+156 -0)

📄 Description

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

What and why

Attribute swapping a spear's reach onto a mace (#6376): holding a spear, a number key and an attack click in the same tick swing the mace at what the spear's 4.5-block attack_range picked. In vanilla Minecraft.tick picks the target (pick → LocalPlayer.raycastHitResult, with the held item's attack_range) before handleKeybinds, which takes the number keys and then the clicks; MultiPlayerGameMode.attack sends the new carried slot and the attack, and the server's handleAttack checks the mace's own range with its 3-block buffer. Horizon changed the slot as the key came in and picked the attacked mob at the click with the plain 3 blocks, so the swing hit nothing (the "animation but no hit" in the report).

  • game.rs, game/hand.rs: number keys queue (hotbar_presses) and select at the tick's pick (pick_tick_targets): the block and the mob are picked first, the mob with the active item's attack_range (AttackRange.getClosesetHit: a block within reach ends it, only a miss falls back to the plain pick), then the keys select. mob_hit returns that pick while the tick's clicks act. Swap hands, drop, inventory, chat and pick-block, which act on the key here, select the queued keys first, as handleKeybinds orders them.
  • startAttack's check that a main-hand item with an attack_range only attacks inside it (held_range_allows), local and remote.
  • game/remote.rs: the input tick's pick sends the new carried slot before the tick's attack or use (ensureHasSentCarriedItem); a tick that does nothing leaves it to the next tick's sync. horizon-client-input: InteractionInput::has_clicks.

Fixes #6376

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Minecraft.tick, pick, handleKeybinds, startAttack; LocalPlayer.raycastHitResult; AttackRange.getClosesetHit; ProjectileUtil.getHitEntitiesAlong; MultiPlayerGameMode.attack; ServerGamePacketListenerImpl.handleAttack; Player.isWithinAttackRange, cannotAttackWithItem (read with tools/rea_vanilla.py).

New tools/attack_swap_e2e.py: the real client (horizon-ctl, offscreen) on a real vanilla 26.3 server slowed to tick rate 1, so both inputs land in one client tick. Cases: the swap and click in one tick at a pig 3.75 blocks away hit; the swap a tick before the click misses; a mace at 2.25 blocks hits; a pig hovering inside the spear's 2-block minimum is missed with a wall 3.5 away (the spear's pick ends on the wall) and hit with nothing behind it (miss → plain pick); a stick given attack_range={min_reach:2,max_reach:4.5} does not attack that pig.

  • Before: same-tick … 'health_after': 10.0, 'hit': False, 'expected': True.
  • Before the review's part (first commit): min-reach-wall … 'hit': True, 'expected': False, ranged-stick … 'hit': True, 'expected': False.
  • After: 6/6 attack swaps match vanilla.

The same-tick hit does 3.0 to the pig where a mace swung after the swap does 1.2: the spear's full charge carries over, which is the point of the swap.

In game (Windows 11, single player, default server thread and --in-frame): spear in slot 1, mace in slot 2, a pig 3.75 blocks away, tick rate 1, key 2 tap + mouse left click in one tick → the pig drops from 10 to 4 (3 of 3 runs; in-frame 10 → 1).

Other projects' code

none

Self-check

The two failing Rust tests are the Windows checkout's CRLF (#6372, fixed by #6375), not touched here.

test_world_input_capture fails the same way on upstream main on Windows (left: (1, (500.0, 300.0)), right: (2, …)), since the refocus regrab change; not touched here.

pr_ready (tools/pr_ready.py --quick --base upstream/main on Evrim-PC, against upstream/main at 81e528f92, 2 min 8 s)

Check Result
Scope ✅ 6 files, +322 −24
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 598 run, FAILED (errors=1, skipped=2) (1 min 7 s)
rustfmt ✅ (9 s)
clippy ✅ (17 s)
tests: horizon-client, horizon-client-input ❌ 588 passed, 2 failed (30 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 305 affected, to run in CI (--quick): arrow, block_particles, breaking_model, chunk_generation, command_exec, command_parse, composter, consumable_emission, consumable, consume_effect, container_screen, container_title and 293 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/6686 **Author:** [@Ragbie](https://github.com/Ragbie) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/attack-swap-pick` --- ### 📝 Commits (5) - [`d073e1d`](https://github.com/horizon-rust/horizon/commit/d073e1dc7e21cbea5a384818d3fdf02976d4f242) A number key and an attack in one tick swing the new item at the old one's target - [`cbed0c0`](https://github.com/horizon-rust/horizon/commit/cbed0c07bd490637517a88811e29d9d0663b2413) Attack swap: the item's pick stops on a block, and its range holds the hit - [`d4f736d`](https://github.com/horizon-rust/horizon/commit/d4f736d2bf585576b202d2446c1feb2727f933e4) Attack swap e2e: the min-reach pig hovers at eye height, fully inside the spear's minimum - [`dfaa286`](https://github.com/horizon-rust/horizon/commit/dfaa2864d5129c35bed217cdcf5f8691f010053d) Attack swap e2e: a tagged pig, the world's own mobs cleared first - [`0d75e2e`](https://github.com/horizon-rust/horizon/commit/0d75e2e5193c7ef7ceadb60ec1f06381fd191479) Attack swap: pass the clip closure by value (clippy) ### 📊 Changes **6 files changed** (+322 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-input/src/interaction_input.rs` (+4 -0) 📝 `crates/horizon-client/src/game.rs` (+22 -2) 📝 `crates/horizon-client/src/game/chat.rs` (+2 -0) 📝 `crates/horizon-client/src/game/hand.rs` (+97 -8) 📝 `crates/horizon-client/src/game/remote.rs` (+41 -14) ➕ `tools/attack_swap_e2e.py` (+156 -0) </details> ### 📄 Description > 🤖 Opened by Ragbie's AI agent (Claude Code, Opus 5.5), not by Ragbie personally. ## What and why Attribute swapping a spear's reach onto a mace (#6376): holding a spear, a number key and an attack click in the same tick swing the mace at what the spear's 4.5-block `attack_range` picked. In vanilla `Minecraft.tick` picks the target (`pick` → `LocalPlayer.raycastHitResult`, with the held item's `attack_range`) before `handleKeybinds`, which takes the number keys and then the clicks; `MultiPlayerGameMode.attack` sends the new carried slot and the attack, and the server's `handleAttack` checks the mace's own range with its 3-block buffer. Horizon changed the slot as the key came in and picked the attacked mob at the click with the plain 3 blocks, so the swing hit nothing (the "animation but no hit" in the report). - `game.rs`, `game/hand.rs`: number keys queue (`hotbar_presses`) and select at the tick's pick (`pick_tick_targets`): the block and the mob are picked first, the mob with the active item's `attack_range` (`AttackRange.getClosesetHit`: a block within reach ends it, only a miss falls back to the plain pick), then the keys select. `mob_hit` returns that pick while the tick's clicks act. Swap hands, drop, inventory, chat and pick-block, which act on the key here, select the queued keys first, as `handleKeybinds` orders them. - `startAttack`'s check that a main-hand item with an `attack_range` only attacks inside it (`held_range_allows`), local and remote. - `game/remote.rs`: the input tick's pick sends the new carried slot before the tick's attack or use (`ensureHasSentCarriedItem`); a tick that does nothing leaves it to the next tick's sync. `horizon-client-input`: `InteractionInput::has_clicks`. Fixes #6376 ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `Minecraft.tick`, `pick`, `handleKeybinds`, `startAttack`; `LocalPlayer.raycastHitResult`; `AttackRange.getClosesetHit`; `ProjectileUtil.getHitEntitiesAlong`; `MultiPlayerGameMode.attack`; `ServerGamePacketListenerImpl.handleAttack`; `Player.isWithinAttackRange`, `cannotAttackWithItem` (read with `tools/rea_vanilla.py`). New `tools/attack_swap_e2e.py`: the real client (`horizon-ctl`, offscreen) on a real vanilla 26.3 server slowed to `tick rate 1`, so both inputs land in one client tick. Cases: the swap and click in one tick at a pig 3.75 blocks away hit; the swap a tick before the click misses; a mace at 2.25 blocks hits; a pig hovering inside the spear's 2-block minimum is missed with a wall 3.5 away (the spear's pick ends on the wall) and hit with nothing behind it (miss → plain pick); a stick given `attack_range={min_reach:2,max_reach:4.5}` does not attack that pig. - Before: `same-tick … 'health_after': 10.0, 'hit': False, 'expected': True`. - Before the review's part (first commit): `min-reach-wall … 'hit': True, 'expected': False`, `ranged-stick … 'hit': True, 'expected': False`. - After: `6/6 attack swaps match vanilla`. The same-tick hit does 3.0 to the pig where a mace swung after the swap does 1.2: the spear's full charge carries over, which is the point of the swap. In game (Windows 11, single player, default server thread and `--in-frame`): spear in slot 1, mace in slot 2, a pig 3.75 blocks away, `tick rate 1`, `key 2 tap` + `mouse left click` in one tick → the pig drops from 10 to 4 (3 of 3 runs; in-frame 10 → 1). ## Other projects' code none ## Self-check The two failing Rust tests are the Windows checkout's CRLF (#6372, fixed by #6375), not touched here. `test_world_input_capture` fails the same way on upstream main on Windows (`left: (1, (500.0, 300.0))`, `right: (2, …)`), since the refocus regrab change; not touched here. **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on Evrim-PC, against upstream/main at 81e528f92, 2 min 8 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +322 −24 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 598 run, FAILED (errors=1, skipped=2) (1 min 7 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (17 s) | | tests: horizon-client, horizon-client-input | ❌ 588 passed, 2 failed (30 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 305 affected, to run in CI (--quick): arrow, block_particles, breaking_model, chunk_generation, command_exec, command_parse, composter, consumable_emission, consumable, consume_effect, container_screen, container_title and 293 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 06:32:23 +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#7030
No description provided.