Skip to content

Block

Represents a block in the game, describing its type, light emission, and other characteristics.

Example: Building a flight of stairs

for _ = 1, 5 do
  spell.block = Block("oak_stairs", { facing = spell.facing })
  spell:move("forward")
  spell:move("up")
end

Fields

burnable: boolean — Read-Only

Indicates whether the block is flammable.

data: table — Read-Only

A reference to the modifiable collection of additional block-specific attributes. For example, a "ladder" has a "facing" attribute, and "grass" has a "snowy" attribute.

Example:

local hit = spell.owner:raycastBlock(5)
if not hit or hit.side == "up" or hit.side == "down" then return end
spell.pos = hit.blockPos
spell:move(hit.side)
local ladder = Block("ladder")
ladder.data.facing = hit.side
spell.block = ladder

luminance: number — Read-Only

The light level emitted by the block.

opaque: boolean — Read-Only

Indicates whether the block is opaque and blocks light.

toolRequired: boolean — Read-Only

Indicates whether a specific tool is required to break the block effectively.

type: BlockType — Read-Only

A reference to the specific type of the block (e.g., stone, dirt).

Methods

new(id: string, data?: table) → block: Block

Initializes a new block with the specified type.

Example

local b = Block:new("stone")
print(b.type.id)  -- Outputs "stone"

Example: With block data

local slab = Block:new("stone_slab", { type = "top" })
print(slab.data.type)  -- Outputs "top"

Parameters

  • id: string — The identifier for the block type (e.g., "stone", "oak_planks"). Raises an error for an unknown id.
  • data?: table — The values of the block's properties, as in data. Properties left out keep their defaults. Raises an error for a property the block doesn't have.

Returns

  • block: Block — A new instance of a Block with the specified type.

Block(id: string, data?: table) → block: Block

Convenient constructor for creating a new block. Equivalent to Block:new(id, data).

Example

spell.block = Block("oak_log", { axis = "x" })

Parameters

  • id: string — The identifier for the block type (e.g., "stone", "oak_planks"). Raises an error for an unknown id.
  • data?: table — The values of the block's properties, as in data. Properties left out keep their defaults. Raises an error for a property the block doesn't have.

Returns

  • block: Block — A new instance of a Block with the specified type.

Operators / Metamethods

__eq(a: Block, b: Block) → boolean

Metamethod for block1 == block2. Two blocks are equal if they have the same type and the same data.

Example

if spell.block == Block("air") then
  spell.block = Block("torch")
end

Parameters

Returns

  • boolean