[PR #193] [MERGED] Arrows can be picked up (#119) #2393

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

📋 Pull Request Information

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

Base: main ← Head: fix/arrow-pickup-119


📝 Commits (2)

📊 Changes

20 files changed (+927 additions, -259 deletions)

View changed files

📝 crates/horizon-client/examples/arrow_probe.rs (+89 -1)
📝 crates/horizon-client/src/arrows.rs (+236 -12)
📝 crates/horizon-client/src/entities.rs (+0 -74)
📝 crates/horizon-client/src/entity_nbt.rs (+85 -49)
📝 crates/horizon-client/src/game.rs (+24 -56)
📝 crates/horizon-client/src/game/commands.rs (+21 -6)
📝 crates/horizon-client/src/game/commands/data.rs (+12 -3)
📝 crates/horizon-client/src/game/creatures.rs (+152 -3)
📝 crates/horizon-client/src/game/crossbow.rs (+15 -3)
📝 crates/horizon-client/src/game/dispenser.rs (+20 -12)
📝 crates/horizon-client/src/game/enchant_effects.rs (+39 -0)
📝 crates/horizon-client/src/game/minecarts.rs (+34 -8)
📝 crates/horizon-client/src/game/persist.rs (+31 -12)
📝 crates/horizon-client/src/game/remote.rs (+1 -1)
📝 crates/horizon-client/src/game/wind.rs (+0 -5)
📝 crates/horizon-client/src/mobs/illager.rs (+1 -1)
📝 crates/horizon-client/src/mobs/undead.rs (+1 -1)
📝 crates/horizon-client/src/projectiles.rs (+10 -0)
📝 mods/horizon/src/test/java/dev/horizonlab/parity/VanillaArrowOracle.java (+75 -5)
📝 tools/test_arrow_parity.py (+81 -7)

📄 Description

Fixes #119

Stacked on #189 (fire) → #187 (arrow port) → #186; base is fix/arrow-fire-124. Retarget before merging the lower PRs with branch deletion.

Root cause

Arrows had no pickup rule and no item, and nothing checked a player touching them, so they could never be picked up. Arrows loaded from a save went into a separate legacy list that was drawn but never ticked: never picked up, never despawned, and not saved again once shot in-session (live arrows weren't saved at all).

Fix

  • arrows.rs: AbstractArrow's pickup and pickupItemStack.
    • set_item is the constructor: drawn ammo carrying INTANGIBLE_PROJECTILE makes the arrow CREATIVE_ONLY. As in vanilla, the item keeps the component, because vanilla removes it from the stack it was given, not from its copy.
    • set_owner is setOwner: a player turns DISALLOWED into ALLOWED.
    • player_touch is playerTouch + tryPickup: the arrow must be stuck (or without physics) and done shaking. ALLOWED gives the item; CREATIVE_ONLY is taken only by a creative player.
  • Shooters:
    • Bow and crossbow give the arrow the drawn ammo (ProjectileWeaponItem.useAmmo). Creative, Infinity and multishot's two extra arrows are intangible, hence CREATIVE_ONLY.
    • Dispensed arrows (plain, tipped, spectral) are ALLOWED, as in asProjectile.
    • Mobs' arrows stay DISALLOWED.
  • Game: each tick the player touches the arrows in its box grown by (1, 0.5, 1) (Player.aiStep). A taken arrow goes into the inventory; a creative player takes it even when it doesn't fit (Inventory.add). Pickup sound: entity.item.pickup at the arrow, volume 0.2, pitch (r - r) * 1.4 + 2 (handleTakeItemEntity).
  • Persistence: saved arrows load as live arrows: life, shake, inGround, inBlockState, pickup, item (tipped effects from it), fire, Owner and LeftOwner. Live arrows are saved, so stuck arrows survive a reload, stay pickable and despawn on time. The legacy list (entities::Arrow, Game.arrows) is gone; /kill, /tp, /data and selectors reach the live arrows. Projectiles are now cleared where the legacy list was (world load/leave, dimension reset, LAN join).

Parity proof

tools/test_arrow_parity.py (real vanilla Arrow in VanillaArrowOracle vs arrows::tick in examples/arrow_probe.rs) now prints a third line per operation: the pickup rule, whether the item is intangible, and what a touch did (taken, arrows added to the inventory). The oracle calls the real setOwner and playerTouch with a real Inventory/Abilities (a ServerPlayer subclass recording take).

New cases:

  • Arrows from no one, a player, a mob, intangible ammo (with and without a player owner), a dispenser, and combinations.
  • Touched in flight, every tick while shaking, and when stuck.
  • Survival and creative players, with empty, partly and fully filled inventories.
  • Arrows without physics, touched in flight.

Results:

  • Mac mini: 164,411 / 164,411 lines on both the client and server jars (323 fixtures, 934 touches: 152 taken, 63 of them into the inventory, 782 refused).
  • cargo clippy --workspace --all-targets -D warnings clean; cargo test -p horizon-client --lib 468 passed.

In-game check

Linux build on a vscreen:

  • Survival bow, shot into the floor: 10 → 9 arrows; walking over it: 10.
  • Creative shot: a survival player walking over it doesn't take it (/data get shows pickup: 2b and the intangible item); after switching to creative it is taken, with no item.
  • Survival Infinity bow: no arrow used, and its arrow can't be picked up.
  • A stuck survival arrow, saved and the world reopened: still stuck (inGround: 1b, life carried over) and picked up on walking over (4 → 5).

Not covered

  • Horizon has no arrows stuck in bodies (ArrowLayer / setArrowCount), so nothing to do there.
  • No ItemPickupParticle fly-to-player animation (dropped items don't have one in Horizon either).
  • An arrow bouncing off an entity it couldn't hurt (deflect + spawnAtLocation for slow ALLOWED arrows) is still removed on any entity hit, as before.
  • Spectral arrows still aren't persisted (only minecraft:arrow was before, too).

🤖 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/193 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/arrow-pickup-119` --- ### 📝 Commits (2) - [`228bdda`](https://github.com/horizon-rust/horizon/commit/228bdda2011b6232eafb3b58433d8018143390a5) Burning arrows: lava, fire, Flame and what they light (#125, #124) - [`89eaaab`](https://github.com/horizon-rust/horizon/commit/89eaaab2ee215b4bb1d9cca0f675f7410c134e0a) Arrows can be picked up (#119) ### 📊 Changes **20 files changed** (+927 additions, -259 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/arrow_probe.rs` (+89 -1) 📝 `crates/horizon-client/src/arrows.rs` (+236 -12) 📝 `crates/horizon-client/src/entities.rs` (+0 -74) 📝 `crates/horizon-client/src/entity_nbt.rs` (+85 -49) 📝 `crates/horizon-client/src/game.rs` (+24 -56) 📝 `crates/horizon-client/src/game/commands.rs` (+21 -6) 📝 `crates/horizon-client/src/game/commands/data.rs` (+12 -3) 📝 `crates/horizon-client/src/game/creatures.rs` (+152 -3) 📝 `crates/horizon-client/src/game/crossbow.rs` (+15 -3) 📝 `crates/horizon-client/src/game/dispenser.rs` (+20 -12) 📝 `crates/horizon-client/src/game/enchant_effects.rs` (+39 -0) 📝 `crates/horizon-client/src/game/minecarts.rs` (+34 -8) 📝 `crates/horizon-client/src/game/persist.rs` (+31 -12) 📝 `crates/horizon-client/src/game/remote.rs` (+1 -1) 📝 `crates/horizon-client/src/game/wind.rs` (+0 -5) 📝 `crates/horizon-client/src/mobs/illager.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs/undead.rs` (+1 -1) 📝 `crates/horizon-client/src/projectiles.rs` (+10 -0) 📝 `mods/horizon/src/test/java/dev/horizonlab/parity/VanillaArrowOracle.java` (+75 -5) 📝 `tools/test_arrow_parity.py` (+81 -7) </details> ### 📄 Description Fixes #119 **Stacked on #189** (fire) → #187 (arrow port) → #186; base is `fix/arrow-fire-124`. Retarget before merging the lower PRs with branch deletion. ## Root cause Arrows had no pickup rule and no item, and nothing checked a player touching them, so they could never be picked up. Arrows loaded from a save went into a separate legacy list that was drawn but never ticked: never picked up, never despawned, and not saved again once shot in-session (live arrows weren't saved at all). ## Fix - `arrows.rs`: `AbstractArrow`'s `pickup` and `pickupItemStack`. - `set_item` is the constructor: drawn ammo carrying `INTANGIBLE_PROJECTILE` makes the arrow CREATIVE_ONLY. As in vanilla, the item keeps the component, because vanilla removes it from the stack it was given, not from its copy. - `set_owner` is `setOwner`: a player turns DISALLOWED into ALLOWED. - `player_touch` is `playerTouch` + `tryPickup`: the arrow must be stuck (or without physics) and done shaking. ALLOWED gives the item; CREATIVE_ONLY is taken only by a creative player. - Shooters: - Bow and crossbow give the arrow the drawn ammo (`ProjectileWeaponItem.useAmmo`). Creative, Infinity and multishot's two extra arrows are intangible, hence CREATIVE_ONLY. - Dispensed arrows (plain, tipped, spectral) are ALLOWED, as in `asProjectile`. - Mobs' arrows stay DISALLOWED. - Game: each tick the player touches the arrows in its box grown by (1, 0.5, 1) (`Player.aiStep`). A taken arrow goes into the inventory; a creative player takes it even when it doesn't fit (`Inventory.add`). Pickup sound: `entity.item.pickup` at the arrow, volume 0.2, pitch `(r - r) * 1.4 + 2` (`handleTakeItemEntity`). - Persistence: saved arrows load as live arrows: life, shake, inGround, inBlockState, pickup, item (tipped effects from it), fire, Owner and LeftOwner. Live arrows are saved, so stuck arrows survive a reload, stay pickable and despawn on time. The legacy list (`entities::Arrow`, `Game.arrows`) is gone; `/kill`, `/tp`, `/data` and selectors reach the live arrows. Projectiles are now cleared where the legacy list was (world load/leave, dimension reset, LAN join). ## Parity proof `tools/test_arrow_parity.py` (real vanilla `Arrow` in `VanillaArrowOracle` vs `arrows::tick` in `examples/arrow_probe.rs`) now prints a third line per operation: the pickup rule, whether the item is intangible, and what a touch did (taken, arrows added to the inventory). The oracle calls the real `setOwner` and `playerTouch` with a real `Inventory`/`Abilities` (a `ServerPlayer` subclass recording `take`). New cases: - Arrows from no one, a player, a mob, intangible ammo (with and without a player owner), a dispenser, and combinations. - Touched in flight, every tick while shaking, and when stuck. - Survival and creative players, with empty, partly and fully filled inventories. - Arrows without physics, touched in flight. Results: - Mac mini: **164,411 / 164,411** lines on both the client and server jars (323 fixtures, 934 touches: 152 taken, 63 of them into the inventory, 782 refused). - `cargo clippy --workspace --all-targets -D warnings` clean; `cargo test -p horizon-client --lib` 468 passed. ## In-game check Linux build on a vscreen: - Survival bow, shot into the floor: 10 → 9 arrows; walking over it: 10. - Creative shot: a survival player walking over it doesn't take it (`/data get` shows `pickup: 2b` and the intangible item); after switching to creative it is taken, with no item. - Survival Infinity bow: no arrow used, and its arrow can't be picked up. - A stuck survival arrow, saved and the world reopened: still stuck (`inGround: 1b`, life carried over) and picked up on walking over (4 → 5). ## Not covered - Horizon has no arrows stuck in bodies (`ArrowLayer` / `setArrowCount`), so nothing to do there. - No `ItemPickupParticle` fly-to-player animation (dropped items don't have one in Horizon either). - An arrow bouncing off an entity it couldn't hurt (`deflect` + `spawnAtLocation` for slow ALLOWED arrows) is still removed on any entity hit, as before. - Spectral arrows still aren't persisted (only `minecraft:arrow` was before, too). 🤖 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:55:37 +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#2393
No description provided.