[PR #4082] [MERGED] Thrown pearls feel the water their box touches, as vanilla's isInWater #5406

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

📋 Pull Request Information

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

Base: main ← Head: fix-3072-pearl


📝 Commits (1)

  • f84b88b Thrown pearls feel the water their box touches, as vanilla's isInWater

📊 Changes

4 files changed (+154 additions, -12 deletions)

View changed files

📝 crates/horizon-client/src/game/creatures.rs (+123 -6)
📝 crates/horizon-client/src/game/remote_projectiles.rs (+2 -2)
📝 crates/horizon-client/src/mobs/shulker.rs (+1 -1)
📝 crates/horizon-client/src/projectiles.rs (+28 -3)

📄 Description

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

What and why

This covers the part of #3072 that was still open: pearls in water ("the ender pearl velocity becomes zero in water after 2 block distance"). #3085 already fixed the momentum part.

Root cause. Projectile::tick chose the water inertia (0.8 instead of 0.99) from one point: the fluid of the block at the projectile's feet, checked on every tick, including the first. Vanilla's ThrowableProjectile.applyInertia (and AbstractHurtingProjectile.applyInertia) read Entity.isInWater(), which returns wasTouchingWater. That flag comes from the previous tick: Entity.baseTick → updateFluidInteraction → EntityFluidInteraction.update sets it after the move, from the bounding box deflated by 0.001. It counts as water when some water block's surface reaches the bottom of the box. A new entity starts with the flag false, so its first tick always uses the air drag.

This had three visible effects:

  • A pearl thrown under water lost a fifth of its speed on its first tick. Thrown flat from 5.5 blocks under the surface, it landed about 6.0 blocks away; vanilla's lands about 7.4 blocks away.
  • A pearl skimming just above a pool slowed as if it were under water, because its feet were in a water block while its box was above the surface.
  • A pearl whose 0.25 box reached into the water of the next column didn't slow down at all.

Fix:

  • Projectile now keeps touching_water (wasTouchingWater). After each move it is set from the box, through ProjectileWorld::in_water(bounds). In the game, ProjWorld answers through MobWorld::fluids, the port of the same box test that mobs already use. Inertia reads the stored value, so the first tick uses the air drag.
  • LlamaSpit.tick runs Projectile.tick (the base tick) before it moves, so llama spit tests its box at the start of the tick.
  • Projectile::bounds() is the type's square box standing on the projectile's position, the same box game.rs already builds for these projectiles.
  • The client's tick for remote arrows now passes the arrow's box too: the trait method takes a box now.

This doesn't port water currents pushing a projectile (applyCurrentTo for projectiles in flowing water). That is a separate gap, left for a follow-up.

Part of #3072

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

Read with javap on the 26.3 client jar:

  • net.minecraft.world.entity.projectile.ThrowableProjectile.tick and applyInertia: isInWater() decides between 0.8 and 0.99, before the move and before Projectile.tick.
  • net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile.tick: applyInertia before Projectile.tick.
  • net.minecraft.world.entity.projectile.LlamaSpit.tick: Projectile.tick first, then the move, then the isInWater() discard.
  • net.minecraft.world.entity.Entity.isInWater (returns wasTouchingWater), Entity.baseTick → updateFluidInteraction (sets wasTouchingWater), and net.minecraft.world.entity.EntityFluidInteraction.update.

Test: game::creatures::tests::a_pearl_feels_the_water_its_box_touches runs a real ProjWorld over a MobWorld with a water pool, using the prepared 26.3 data. It checks three cases:

  • a pearl above the surface whose feet are in the water block keeps the air drag;
  • a pearl at the pool's edge whose box reaches the water gets the water drag from its second tick;
  • a pearl thrown under water gets the air drag on its first tick and the water drag after that.

No parity harness fits. Vanilla aims a throw with the pearl's unseeded entity random, so a vanilla-vs-Horizon landing spot can't be compared exactly. test_entity_fluid_parity.py checks EntityFluidInteraction.update against vanilla, but for the horizon-world port; MobWorld::fluids, the client-crate copy that mobs and now projectiles use, has no harness of its own.

Self-check

tools/pr_ready.py doesn't run on Windows (it needs SIGHUP), so I ran these by hand:

cargo fmt --all -- --check                                          # clean
cargo clippy -p horizon-client --all-targets -- -D warnings         # clean
cargo test -p horizon-client --bin horizon-client a_pearl_feels     # before the fix (only the code reverted): FAILED
    "a pearl above the surface slowed as in water: ... velocity: Vec3 { x: 0.192, y: -0.0432 ..."
cargo test -p horizon-client --bin horizon-client a_pearl_feels     # after: ok. 1 passed
cargo test -p horizon-client --lib -- projectiles:: arrows:: mobs::shulker               # ok. 10 passed
cargo test -p horizon-client --bin horizon-client -- remote_projectiles creatures:: trident fireworks   # ok. 3 passed

In game, single player on the server thread. In a glass tank of still water (floor at y=151, surface at y=162), a creative player stood on a block at y=155 and threw a pearl flat to the east, three throws per build. The distance is from the throw to the spot the pearl teleported them to:

Build Throws (blocks) Expected
v0.2.97 (before) 5.989, 5.973, 5.957 6.000 with the old drag
this branch 7.414, 7.402, 7.325 7.425 with vanilla's drag

The expected values come from simulating vanilla's rules from the same start: air drag on the first tick, then water drag. The small shortfall in each throw is the 1.0 inaccuracy spread.

Screenshots

Players see it in where the pearl takes them. A pearl thrown under water now carries about 7.4 blocks, as in vanilla, instead of stopping short at about 6. A pearl skimming a pool no longer slows as if it were under water. The table above has the numbers.

🤖 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/4082 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3072-pearl` --- ### 📝 Commits (1) - [`f84b88b`](https://github.com/horizon-rust/horizon/commit/f84b88b2e941858c95636b3b9286329b9291dcb9) Thrown pearls feel the water their box touches, as vanilla's isInWater ### 📊 Changes **4 files changed** (+154 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/creatures.rs` (+123 -6) 📝 `crates/horizon-client/src/game/remote_projectiles.rs` (+2 -2) 📝 `crates/horizon-client/src/mobs/shulker.rs` (+1 -1) 📝 `crates/horizon-client/src/projectiles.rs` (+28 -3) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why This covers the part of #3072 that was still open: pearls in water ("the ender pearl velocity becomes zero in water after 2 block distance"). #3085 already fixed the momentum part. **Root cause.** `Projectile::tick` chose the water inertia (0.8 instead of 0.99) from one point: the fluid of the block at the projectile's feet, checked on every tick, including the first. Vanilla's `ThrowableProjectile.applyInertia` (and `AbstractHurtingProjectile.applyInertia`) read `Entity.isInWater()`, which returns `wasTouchingWater`. That flag comes from the previous tick: `Entity.baseTick` → `updateFluidInteraction` → `EntityFluidInteraction.update` sets it after the move, from the bounding box deflated by 0.001. It counts as water when some water block's surface reaches the bottom of the box. A new entity starts with the flag false, so its first tick always uses the air drag. This had three visible effects: - A pearl thrown under water lost a fifth of its speed on its first tick. Thrown flat from 5.5 blocks under the surface, it landed about 6.0 blocks away; vanilla's lands about 7.4 blocks away. - A pearl skimming just above a pool slowed as if it were under water, because its feet were in a water block while its box was above the surface. - A pearl whose 0.25 box reached into the water of the next column didn't slow down at all. **Fix:** - `Projectile` now keeps `touching_water` (`wasTouchingWater`). After each move it is set from the box, through `ProjectileWorld::in_water(bounds)`. In the game, `ProjWorld` answers through `MobWorld::fluids`, the port of the same box test that mobs already use. Inertia reads the stored value, so the first tick uses the air drag. - `LlamaSpit.tick` runs `Projectile.tick` (the base tick) before it moves, so llama spit tests its box at the start of the tick. - `Projectile::bounds()` is the type's square box standing on the projectile's position, the same box `game.rs` already builds for these projectiles. - The client's tick for remote arrows now passes the arrow's box too: the trait method takes a box now. This doesn't port water currents pushing a projectile (`applyCurrentTo` for projectiles in flowing water). That is a separate gap, left for a follow-up. Part of #3072 ## 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 Read with javap on the 26.3 client jar: - `net.minecraft.world.entity.projectile.ThrowableProjectile.tick` and `applyInertia`: `isInWater()` decides between 0.8 and 0.99, before the move and before `Projectile.tick`. - `net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile.tick`: `applyInertia` before `Projectile.tick`. - `net.minecraft.world.entity.projectile.LlamaSpit.tick`: `Projectile.tick` first, then the move, then the `isInWater()` discard. - `net.minecraft.world.entity.Entity.isInWater` (returns `wasTouchingWater`), `Entity.baseTick` → `updateFluidInteraction` (sets `wasTouchingWater`), and `net.minecraft.world.entity.EntityFluidInteraction.update`. **Test:** `game::creatures::tests::a_pearl_feels_the_water_its_box_touches` runs a real `ProjWorld` over a `MobWorld` with a water pool, using the prepared 26.3 data. It checks three cases: - a pearl above the surface whose feet are in the water block keeps the air drag; - a pearl at the pool's edge whose box reaches the water gets the water drag from its second tick; - a pearl thrown under water gets the air drag on its first tick and the water drag after that. No parity harness fits. Vanilla aims a throw with the pearl's unseeded entity random, so a vanilla-vs-Horizon landing spot can't be compared exactly. `test_entity_fluid_parity.py` checks `EntityFluidInteraction.update` against vanilla, but for the `horizon-world` port; `MobWorld::fluids`, the client-crate copy that mobs and now projectiles use, has no harness of its own. ## Self-check `tools/pr_ready.py` doesn't run on Windows (it needs SIGHUP), so I ran these by hand: ``` cargo fmt --all -- --check # clean cargo clippy -p horizon-client --all-targets -- -D warnings # clean cargo test -p horizon-client --bin horizon-client a_pearl_feels # before the fix (only the code reverted): FAILED "a pearl above the surface slowed as in water: ... velocity: Vec3 { x: 0.192, y: -0.0432 ..." cargo test -p horizon-client --bin horizon-client a_pearl_feels # after: ok. 1 passed cargo test -p horizon-client --lib -- projectiles:: arrows:: mobs::shulker # ok. 10 passed cargo test -p horizon-client --bin horizon-client -- remote_projectiles creatures:: trident fireworks # ok. 3 passed ``` **In game, single player on the server thread.** In a glass tank of still water (floor at y=151, surface at y=162), a creative player stood on a block at y=155 and threw a pearl flat to the east, three throws per build. The distance is from the throw to the spot the pearl teleported them to: | Build | Throws (blocks) | Expected | |---|---|---| | v0.2.97 (before) | 5.989, 5.973, 5.957 | 6.000 with the old drag | | this branch | 7.414, 7.402, 7.325 | 7.425 with vanilla's drag | The expected values come from simulating vanilla's rules from the same start: air drag on the first tick, then water drag. The small shortfall in each throw is the 1.0 inaccuracy spread. ## Screenshots Players see it in where the pearl takes them. A pearl thrown under water now carries about 7.4 blocks, as in vanilla, instead of stopping short at about 6. A pearl skimming a pool no longer slows as if it were under water. The table above has the numbers. 🤖 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:12: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#5406
No description provided.