Block API
The Block wrapper gives scripts access to the active computer block and nearby block state.
Typical usage
block = console.getBlock()
pos = block.getPos()
print("Computer block at:", pos.x, pos.y, pos.z)
if block.isDisplayModule() then
block.setDisplayText("LuaMade online")
end
Common patterns
Read metadata once with
getInfo()and cache values used often.Use
hasInventory()beforegetInventory()to avoid nil checks everywhere.Check
isDisplayModule()before writing display text.
Reference
getPos()Returns block position index asLuaVec3i(x,y,z) in segment-space coordinates.getWorldPos()Returns block world position asLuaVec3f(x,y,z) using the block’s world transform.getId()Returns the element ID for this block.getInfo()ReturnsBlockInfo(name, description, ID metadata).isActive()Returns whether the block is active.setActive(active<Boolean>)Sets the block active state and syncs it to the world/network state.getEntity()Returns the owningEntitywrapper.getEntityInfo()Compatibility alias that returns the sameEntitywrapper asgetEntity().hasInventory()Returns true if an inventory exists at this block position.getInventory()ReturnsInventoryornilwhen no inventory is present.isDisplayModule()Returns true when the block is a text display module.setDisplayText(text<String>)Updates text shown on display modules.getDisplayText()Returns current display text ornilwhen not a display module.
Example:
local block = peripheral.getRelative("front")
if block ~= nil and block.hasInventory() then
local items = block.getItems()
print("Has inventory:", block.getInventoryName())
end