[PR #311] [MERGED] Shields turn arrows back, as vanilla does #2479

Closed
opened 2026-11-02 15:56:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/311
Author: @ludovic111
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ludovic111

Base: main ← Head: fix/shield-deflects-arrows


📝 Commits (1)

  • e2473aa Shields turn arrows back, as vanilla does

📊 Changes

5 files changed (+319 additions, -101 deletions)

View changed files

📝 crates/horizon-client/examples/arrow_probe.rs (+56 -5)
📝 crates/horizon-client/src/arrows.rs (+111 -18)
📝 crates/horizon-client/src/game/creatures.rs (+91 -73)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaArrowOracle.java (+35 -4)
📝 tools/test_arrow_parity.py (+26 -1)

📄 Description

Fixes #277. Thanks to Cosmic (Online5277) for the report.

What

An arrow that hits a raised shield now bounces back off it, as in vanilla. Before, it vanished. A very slow arrow that bounces off drops as an item when it can be picked up.

Why

AbstractArrow.onHitEntity: when hurtOrSimulate fails (the shield blocked it), the arrow gets the target's fire ticks back and calls deflect(ProjectileDeflection.REVERSE): velocity × −0.1 (power 0.2) and yaw + 170 + 20 × the arrow's random. Below 1e-7 squared speed it spawnAtLocations its pickup at y + 0.1 and is discarded. The rest of the tick (drag, gravity and so on) then runs as usual.

How

  • arrows.rs:
    • Entity hits follow ProjectileUtil.getManyEntityHitResult: an exact clip first, then computeMargin (tickCount-based, up to 0.3) inside the arrow's swept and inflated box.
    • New finish_entity_hit(Hurt | Refused | Deflected) finishes the tick after the game has applied the damage.
    • New ArrowEvent::Drop.
  • game/creatures.rs:
    • Player targets: a refused hit (a blocked one) restores the fire ticks and deflects the arrow.
    • Punch knockback applies only when the hit hurts.
    • The damage roll uses the arrow's own random.

Mobs that refuse an arrow still swallow it: mob hits don't go through hurtServer's refusal yet. That is a follow-up.

How tested

The arrow harness has new target cases: an entity box that takes or refuses the hit, with random aims and slow arrows. They compare against vanilla AbstractArrow through the oracle: 171,563 states match, including 35 entity hits (20 taken, 15 refused and deflected) and 1 drop.

Self-check (Mac mini), all five branches of this batch rebased on origin/main 050b2038:
- cargo fmt --all --check: OK
- cargo clippy --workspace --all-targets -- -D warnings: OK on this branch alone, and on the integration of all five
- cargo test -p horizon-client (integration): 649 + 41 + 15 + 2 + 2 + 1 passed, 0 failed
- tools/parity.py --changed origin/main on the integration commit: 79 passed, 0 failed
  (including arrow, use_item_on, first_person, dispenser and mob_ai)
- tools/parity.py, run explicitly: player_hurt, blocking_rules, blocking_item_damage, item_use, item_use_start,
  item_use_lifecycle, living_hurt, damage_reduction, player_equipment, registered_player_combat,
  server_player_combat, server_player_damage: 12 passed, 0 failed

Screenshots: ~/code/horizon-parity/shots/offhand-276/ on the Mac mini.

Needs Ludovic

Nothing. An in-game shot of a deflected arrow wasn't practical offscreen: /summon arrow isn't supported, and the skeleton got stuck. The harness covers the motion exactly.

🤖 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/311 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/shield-deflects-arrows` --- ### 📝 Commits (1) - [`e2473aa`](https://github.com/horizon-rust/horizon/commit/e2473aafd8210c35db267441abea9ba8751c2683) Shields turn arrows back, as vanilla does ### 📊 Changes **5 files changed** (+319 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/arrow_probe.rs` (+56 -5) 📝 `crates/horizon-client/src/arrows.rs` (+111 -18) 📝 `crates/horizon-client/src/game/creatures.rs` (+91 -73) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaArrowOracle.java` (+35 -4) 📝 `tools/test_arrow_parity.py` (+26 -1) </details> ### 📄 Description Fixes #277. Thanks to Cosmic (Online5277) for the report. ## What An arrow that hits a raised shield now bounces back off it, as in vanilla. Before, it vanished. A very slow arrow that bounces off drops as an item when it can be picked up. ## Why `AbstractArrow.onHitEntity`: when `hurtOrSimulate` fails (the shield blocked it), the arrow gets the target's fire ticks back and calls `deflect(ProjectileDeflection.REVERSE)`: velocity × −0.1 (power 0.2) and yaw + 170 + 20 × the arrow's random. Below 1e-7 squared speed it `spawnAtLocation`s its pickup at y + 0.1 and is discarded. The rest of the tick (drag, gravity and so on) then runs as usual. ## How - `arrows.rs`: - Entity hits follow `ProjectileUtil.getManyEntityHitResult`: an exact clip first, then `computeMargin` (tickCount-based, up to 0.3) inside the arrow's swept and inflated box. - New `finish_entity_hit(Hurt | Refused | Deflected)` finishes the tick after the game has applied the damage. - New `ArrowEvent::Drop`. - `game/creatures.rs`: - Player targets: a refused hit (a blocked one) restores the fire ticks and deflects the arrow. - Punch knockback applies only when the hit hurts. - The damage roll uses the arrow's own random. Mobs that refuse an arrow still swallow it: mob hits don't go through `hurtServer`'s refusal yet. That is a follow-up. ## How tested The `arrow` harness has new `target` cases: an entity box that takes or refuses the hit, with random aims and slow arrows. They compare against vanilla `AbstractArrow` through the oracle: 171,563 states match, including 35 entity hits (20 taken, 15 refused and deflected) and 1 drop. ``` Self-check (Mac mini), all five branches of this batch rebased on origin/main 050b2038: - cargo fmt --all --check: OK - cargo clippy --workspace --all-targets -- -D warnings: OK on this branch alone, and on the integration of all five - cargo test -p horizon-client (integration): 649 + 41 + 15 + 2 + 2 + 1 passed, 0 failed - tools/parity.py --changed origin/main on the integration commit: 79 passed, 0 failed (including arrow, use_item_on, first_person, dispenser and mob_ai) - tools/parity.py, run explicitly: player_hurt, blocking_rules, blocking_item_damage, item_use, item_use_start, item_use_lifecycle, living_hurt, damage_reduction, player_equipment, registered_player_combat, server_player_combat, server_player_damage: 12 passed, 0 failed ``` Screenshots: ~/code/horizon-parity/shots/offhand-276/ on the Mac mini. ## Needs Ludovic Nothing. An in-game shot of a deflected arrow wasn't practical offscreen: `/summon arrow` isn't supported, and the skeleton got stuck. The harness covers the motion exactly. 🤖 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-02 15:56:32 +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#2479
No description provided.