Skip to content

Blocks & hits

Block state properties at a position, and the fields of block and entity raycast hits.

Block state

world:block_state(pos) returns a live handle; a block raycast hit carries the same thing in its state field.

Method Returns
id(), name() Block id ("minecraft:chest") and display name
position() The queried position, floored, as vec3
air(), liquid(), solid(), replaceable() Kind flags; replaceable means you can build over it
burnable() Fire consumes it
tool_required() Drops only with the right tool
opaque(), full_cube(), has_collision() Shape flags
has_block_entity() Carries extra data, like a chest or furnace
random_ticks() Receives random ticks
emits_redstone() Emits redstone power
piston_behavior() "normal", "destroy", "block", "push_only", …
hardness(), blast_resistance() Mining time and explosion resistance
slipperiness() 0.6 normal, 0.98 ice
velocity_multiplier(), jump_velocity_multiplier() Soul sand and honey movement modifiers
luminance(), opacity() Light emitted (0–15) and light blocked
map_color() Map color as a signed RGB integer, not 0xAARRGGBB
properties() State properties as strings
fluid() {id, level, still} when it holds fluid, or nil
tags() Block tag ids, e.g. "minecraft:mineable/pickaxe"

Property values are strings, including the booleans:

local b = world:block_state(pos)
if b and b:properties().lit == "true" then
    print(b:name() .. " is lit")
end

Raycast hits

world:raycast, world:raycast_entity and player:raycast return a plain table. Check type first, since player:raycast returns either kind.

Field On Meaning
type both "block" or "entity"
pos both Exact hit point as vec3
distance both From ray start to hit
block_pos block Hit block position as vec3
side block Hit face: "up", "down", "north", "south", "east", "west"
inside block true when the ray started inside the block
state block Block state handle of the hit block
entity entity Entity handle that was hit
local hit = player:raycast(20)
if hit then
    if hit.type == "entity" then
        print("looking at " .. hit.entity:name())
    else
        print("looking at " .. hit.state:name() .. " (" .. hit.side .. ")")
    end
end
Navigation

Type to search…

↑↓ navigate↵ selectEsc close