Modern Apps git

← Modern-Apps.git

voxels: throw snowballs and pearls along the touch ray (#ux-audit)

Commit
baa7240638c173777ccce2a3b2f46632e028516d
Author
Vayun Mathur <[email protected]>
When
2026-11-13 01:39 UTC (23 days ago)
Parents
274e8c6
Symptom (audit): throwables fired at the screen centre with no
crosshair, so tapping where you wanted a snowball or ender pearl to go
sent it somewhere else. On closer reading it was worse: they could not
be thrown at all.

Root cause:
- engine_part3.rs do_break checked `sel == 190 || sel == 191`, item
  ids from before items moved above ITEM_BASE (1024). Snowballs and
  ender pearls are 1086/1087 (see the snow -> snowballs recipe and the
  fishing loot table), so the branch was dead and holding one did
  nothing but fall through to block breaking.
- The branch, had it run, used player.forward() rather than the touch
  ray `dir` that do_break already receives; fireball deflection did
  the same.

Fix:
- item::SNOWBALL / item::ENDER_PEARL constants; the throw branch uses
  them.
- Projectiles leave the eye along `dir` (the ray through the touch,
  or through the crosshair when thrown with the Use button), Artemis'
  three-way spread fans around that ray, and fireball deflection
  targets fireballs along it too. (The crosshair itself landed with
  the Use button change.)

User-visible effect: snowballs and ender pearls work, and land where
you point.

Verification: new Rust test throwables_follow_the_touch_ray (a
snowball thrown with an off-centre ray flies along it and is consumed).

Diff

games/voxels/src/main/rust/src/engine_part3.rs
diff --git a/games/voxels/src/main/rust/src/engine_part3.rs b/games/voxels/src/main/rust/src/engine_part3.rsindex f68a71ca74..8136cc2575 100644--- a/games/voxels/src/main/rust/src/engine_part3.rs+++ b/games/voxels/src/main/rust/src/engine_part3.rs@@ -122,14 +122,16 @@ fn do_break(state: &mut EngineState, origin: Vec3, dir: Vec3) -> bool {         }         return false;     }-    // Throwables: snowball (light damage/knock) and ender pearl (teleport to impact).-    if (sel == 190 || sel == 191) && state.player.eat_cd <= 0.0 {+    // Throwables: snowball (light damage/knock) and ender pearl (teleport to impact). They fly along+    // `dir`, the ray through the touch (or the crosshair, for the Use button), so they land where the+    // player pointed. These checks used the pre-1024 ids 190/191, so throwables never fired at all.+    if (sel == item::SNOWBALL || sel == item::ENDER_PEARL) && state.player.eat_cd <= 0.0 {         // Paris never spends the charge; everyone else does.         let free = state.player.blessed(Passive::Infinity);         if free || state.inventory.consume_selected().is_some() {-            let f = state.player.forward();+            let f = dir.normalize_or_zero();             let origin = state.player.eye_pos() + f * 0.5;-            let (kind, spd) = if sel == 191 { (ProjKind::EnderPearl, 16.0) } else { (ProjKind::Snowball, 20.0) };+            let (kind, spd) = if sel == item::ENDER_PEARL { (ProjKind::EnderPearl, 16.0) } else { (ProjKind::Snowball, 20.0) };             // Artemis throws a spread of three; an ender pearl always flies alone so the             // teleport destination stays predictable.             let spread: &[f32] = if state.player.blessed(Passive::Multishot) && kind == ProjKind::Snowball {@@ -137,7 +139,7 @@ fn do_break(state: &mut EngineState, origin: Vec3, dir: Vec3) -> bool {             } else {                 &[0.0]             };-            let right = state.player.right();+            let right = { let r = f.cross(Vec3::Y).normalize_or_zero(); if r == Vec3::ZERO { state.player.right() } else { r } };             for &off in spread {                 let dir = (f + right * off).normalize_or_zero();                 state.projectiles.push(Projectile { pos: origin, vel: dir * spd, life: 5.0, kind, from_player: true, damage: 0.0, explosive: false });@@ -147,9 +149,10 @@ fn do_break(state: &mut EngineState, origin: Vec3, dir: Vec3) -> bool {         }     }     // Deflect an incoming fireball by attacking it — bats it back (now player-owned) at the shooter.+    // Aimed along the touch ray like everything else here.     {         let eye_pos = state.player.eye_pos();-        let f = state.player.forward();+        let f = dir.normalize_or_zero();         let mut best: Option<(usize, f32)> = None;         for (i, p) in state.projectiles.iter().enumerate() {             if p.from_player || p.kind != ProjKind::Fireball { continue; }
games/voxels/src/main/rust/src/engine_part6.rs
diff --git a/games/voxels/src/main/rust/src/engine_part6.rs b/games/voxels/src/main/rust/src/engine_part6.rsindex c7fbd236f5..a9558158b5 100644--- a/games/voxels/src/main/rust/src/engine_part6.rs+++ b/games/voxels/src/main/rust/src/engine_part6.rs@@ -121,4 +121,19 @@ mod state_tests {         assert!(!s.player.flying);         assert!(Inventory::empty().slots.iter().all(|sl| sl.id == 0 && sl.count == 0));     }) }++    // A thrown snowball flies along the ray it was thrown with (the touch), not the view centre.+    #[test]+    fn throwables_follow_the_touch_ray() { big_stack(|| {+        let mut s = small_state("throw");+        s.inventory.selected = 0;+        s.inventory.slots[0] = crate::inventory::InvSlot { id: crate::item::SNOWBALL, count: 4 };+        s.player.eat_cd = 0.0;+        let dir = vec3(0.6, 0.2, -0.77).normalize();+        let eye = s.player.eye_pos();+        assert!(do_break(&mut s, eye, dir), "the snowball was not thrown");+        let p = s.projectiles.last().expect("a projectile");+        assert!(p.vel.normalize().dot(dir) > 0.999, "thrown along {:?}, not the touch ray {:?}", p.vel, dir);+        assert_eq!(s.inventory.slots[0].count, 3);+    }) } }
games/voxels/src/main/rust/src/item.rs
diff --git a/games/voxels/src/main/rust/src/item.rs b/games/voxels/src/main/rust/src/item.rsindex f1d908201d..df93c3f6ba 100644--- a/games/voxels/src/main/rust/src/item.rs+++ b/games/voxels/src/main/rust/src/item.rs@@ -45,6 +45,9 @@ pub fn is_food(id: Id) -> bool { food_effects(id).is_some() } // {helmet,chestplate,leggings,boots}. Matcha's bronze sits between iron and diamond at 1135..1140, // and adamant tops the ladder at 1093..1098. Durability is stored in the inventory slot's `count`. pub fn is_tool(id: Id) -> bool { (1059..=1066).contains(&id) || matches!(id, 1093 | 1094 | 1135 | 1136 | 1148 | 1149 | 1151) }+/// Throwables: a snowball (light damage and knockback) and an ender pearl (teleport to impact).+pub const SNOWBALL: Id = 1086;+pub const ENDER_PEARL: Id = 1087; /// Brushing suspicious sand is the only thing it does. pub const BRUSH: Id = 1151; /// Shears: used on a sheep rather than on terrain, so they're a tool that mines nothing.