Raycast

Functions to approximate the block or entity that a player is looking at

Requirements

Usage

The raycast functions are executed as a specific player and will call the function specified in raycast:callback function if a valid object is found:

data modify storage raycast:callback function set value "namespace:function"
function raycast:block

data modify storage raycast:callback function set value "namespace:function"
function raycast:entity

data modify storage raycast:callback function set value "namespace:function"
function raycast:any

The following prebuilt callbacks are available:

# generates a small particle effect on the contact point
function raycast:block_test
function raycast:entity_test
function raycast:any_test

# stores the coordinates of the contact block and the last empty block at
# `raycast:block` in `x1`, `y1`, `z1` and `x0`, `y0`, `z0` respectively
function raycast:block_store

Known Issues

The ray is only long enough to reach to blocks that could conceivably be selected by the player; it will query up to 74 positions at 1/16 units of distance from each other.

Considers all blocks tagged #wishlist:non_full empty, and everything else to be a full block; that means that partial blocks such as fences and pots can interrupt a ray even if the player is looking at the empty part of them, and blocks such as trapdoors and doors will not interrupt the ray even if they are in the way.