Raycasts
Raycasts generate a set of recursive functions that step forward from the entity's eyes until they hit a block or reach max distance.
They are ideal for “look at” interactions, custom tools, line-of-sight checks, or visual debugging because the helper pre-builds the recursive command chain for you.
API overview
The helper is centered around two entry points:
raycast { ... }– builds a freshRaycastConfiginline.raycast(config)– reuses an already configuredRaycastConfiginstance.
The generated RaycastHandle exposes a single cast() method that launches the raycast from the current function context.
RaycastConfig defaults:
name = "raycast"maxDistance = 100step = 0.5onHitBlock = {}onStep = nullonMaxDistance = null
DSL builder
Callback lifecycle
onStepruns for every successful step before the ray stops.onHitBlockruns when the next step collides with a block.onMaxDistanceruns when the ray reaches the configured limit without hitting anything.
If onMaxDistance is omitted, the ray quietly removes its internal tag when it reaches the limit, so the generated functions stop recursing without firing a fallback callback.
This makes it easy to keep gameplay logic explicit: particles can live in onStep, impact logic in onHitBlock, and fallback behavior in onMaxDistance.
Practical usage pattern
For precise interaction beams, prefer a smaller step; for cheaper “good enough” scans, use a larger one.
The step value is measured in blocks and is applied through a local-position offset, so smaller values increase precision while also generating more recursive calls.
See also
- Area – Define spatial zones that complement what a ray can detect or trigger.
- VFX Particles – Use particles inside
onStepfor visual debugging or beam effects. - Entities & Players – Execute raycasts from player or mob contexts with reusable selectors.
