[PR #2113] [MERGED] Mod API: game.raycast, the block the player looks at #4015

Closed
opened 2026-11-03 04:14:03 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: feat/mod-raycast


📝 Commits (1)

  • c23b4e8 Mod API: game.raycast, the block the player looks at (level 2)

📊 Changes

10 files changed (+202 additions, -13 deletions)

View changed files

📝 crates/horizon-client/src/game/mods.rs (+57 -0)
📝 crates/horizon-client/src/lod.rs (+19 -0)
📝 crates/horizon-mod-sdk/wit/horizon.wit (+20 -1)
📝 crates/horizon-mods/src/api_level.rs (+3 -2)
📝 crates/horizon-mods/src/runtime.rs (+27 -2)
📝 crates/horizon-mods/tests/sandbox.rs (+44 -3)
📝 crates/horizon-mods/tests/ui_guest/src/lib.rs (+14 -2)
📝 docs/api/mods-reference.md (+16 -1)
📝 docs/api/stability.md (+1 -1)
📝 docs/mods.md (+1 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Mods can now ask which block the player looks at: game.raycast(distance) (capability game-read). It is the first step of porting Stink-O's Orbital Laser to a stock mod: the laser aims where the player looks, up to 1024 blocks away, so the ray has to go past the loaded chunks.

  • WIT: game.raycast: func(distance: f32) -> option<hit>, with record hit { block-x, block-y, block-z: s32, x, y, z: f64, block: string } (the block hit, the point on its face, minecraft:stone…). This is API level 2: a mod that calls it is refused by older Horizons with "update Horizon" (#2080).
  • The ray: through the loaded chunks it is the crosshair's own clip_ray (fluids pass). Past them, it walks the distant terrain's ground heights a block at a time (Lod::ground, ported from Stink-O's fork), so it reaches 1024 blocks when LOD Distance is on.
  • Cost: the game works the ray out only while a running mod imports game.raycast (Mods::wants_raycast), once per snapshot. Without such a mod, no ray is cast.
  • The host: it returns the hit when it is within min(distance, 1024) of the eye; otherwise, and for NaN, it returns None.

Tests:

  • sandbox game_raycast_sees_the_view_hit_within_its_distance;
  • api_reference regenerated (docs/api/mods-reference.md);
  • in game, in both modes (in-frame and server thread), the ui test guest's /raycast. Standing on glass and looking down, 2 blocks reach the glass and 1 doesn't. The hit and point are 0 199 0 (0.5 200.0 0.5). After /setblock, the ray sees gold. Looking at the sky gives no hit.

Not tested in game: the LOD part (the offscreen game has no distant terrain). Its walk is short, and Lod::ground is Stink-O's.

Labels: skip-release. API only; players see nothing until a mod uses it.

pr_ready (tools/pr_ready.py --quick --base b12c89650 on ludovics-mac-mini, against b12c89650 at b12c89650, 6 min 6 s)

Check Result
Scope ✅ 10 files, +201 −12
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ after cargo fmt (an import line in sandbox.rs)
clippy ✅ (1 min 48 s)
tests: horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest ✅ 1362 passed (2 min 21 s)
doc tests ✅ 2 passed (1 min 0 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (14 s)
launcher tests ✅ 130 passed (24 s)
Parity ➖ 113 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 101 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/2113 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/mod-raycast` --- ### 📝 Commits (1) - [`c23b4e8`](https://github.com/horizon-rust/horizon/commit/c23b4e8e416a59bd7001f77f3e8738b04db9deb3) Mod API: game.raycast, the block the player looks at (level 2) ### 📊 Changes **10 files changed** (+202 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/mods.rs` (+57 -0) 📝 `crates/horizon-client/src/lod.rs` (+19 -0) 📝 `crates/horizon-mod-sdk/wit/horizon.wit` (+20 -1) 📝 `crates/horizon-mods/src/api_level.rs` (+3 -2) 📝 `crates/horizon-mods/src/runtime.rs` (+27 -2) 📝 `crates/horizon-mods/tests/sandbox.rs` (+44 -3) 📝 `crates/horizon-mods/tests/ui_guest/src/lib.rs` (+14 -2) 📝 `docs/api/mods-reference.md` (+16 -1) 📝 `docs/api/stability.md` (+1 -1) 📝 `docs/mods.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Mods can now ask which block the player looks at: `game.raycast(distance)` (capability `game-read`). It is the first step of porting Stink-O's Orbital Laser to a stock mod: the laser aims where the player looks, up to 1024 blocks away, so the ray has to go past the loaded chunks. - **WIT:** `game.raycast: func(distance: f32) -> option<hit>`, with `record hit { block-x, block-y, block-z: s32, x, y, z: f64, block: string }` (the block hit, the point on its face, `minecraft:stone`…). This is API **level 2**: a mod that calls it is refused by older Horizons with "update Horizon" (#2080). - **The ray:** through the loaded chunks it is the crosshair's own `clip_ray` (fluids pass). Past them, it walks the distant terrain's ground heights a block at a time (`Lod::ground`, ported from Stink-O's fork), so it reaches 1024 blocks when LOD Distance is on. - **Cost:** the game works the ray out only while a running mod imports `game.raycast` (`Mods::wants_raycast`), once per snapshot. Without such a mod, no ray is cast. - **The host:** it returns the hit when it is within `min(distance, 1024)` of the eye; otherwise, and for NaN, it returns None. Tests: - sandbox `game_raycast_sees_the_view_hit_within_its_distance`; - api_reference regenerated (`docs/api/mods-reference.md`); - in game, in both modes (in-frame and server thread), the ui test guest's `/raycast`. Standing on glass and looking down, 2 blocks reach the glass and 1 doesn't. The hit and point are `0 199 0 (0.5 200.0 0.5)`. After `/setblock`, the ray sees gold. Looking at the sky gives no hit. Not tested in game: the LOD part (the offscreen game has no distant terrain). Its walk is short, and `Lod::ground` is Stink-O's. Labels: `skip-release`. API only; players see nothing until a mod uses it. **pr_ready** (`tools/pr_ready.py --quick --base b12c89650` on ludovics-mac-mini, against b12c89650 at b12c89650, 6 min 6 s) | Check | Result | | --- | --- | | Scope | ✅ 10 files, +201 −12 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ after `cargo fmt` (an import line in sandbox.rs) | | clippy | ✅ (1 min 48 s) | | tests: horizon-client, horizon-mod-sdk, horizon-mods, horizon-mods-test-ui-guest | ✅ 1362 passed (2 min 21 s) | | doc tests | ✅ 2 passed (1 min 0 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (14 s) | | launcher tests | ✅ 130 passed (24 s) | | Parity | ➖ 113 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 101 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 04:14:03 +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#4015
No description provided.