commands.getBlockInfos

From ComputerCraft Wiki
Revision as of 23:25, 26 December 2015 by Dan200 (Talk | contribs) (Clarified state)

Jump to: navigation, search


Grid Redstone.png  Function commands.getBlockInfos
Available only to Command Computers as of ComputerCraft version 1.76, returns a numerically-indexed table containing information on the blocks within the specified world co-ordinates. Each sub-table is formatted per the output of commands.getBlockInfo():
{
  state = table state information
  name = string block's name,
  metadata = number block's metadata
}

A maximum of 4096 (2^12) blocks may be inspected at a time (for example, a 16x16x16 cube); the function will error if the block count exceeds this.

The blocks are returned in the order of lowest x-co-ord to highest x-co-ord, then lowest z-co-ord to highest z-co-ord, then lowest y-co-ord to highest y-co-ord; that is to say, west to east, then north to south, then lowest altitude to highest altitude.

See also: commands.getBlockInfo(), Block States @ Minecraft wiki
Syntax commands.getBlockInfos(number x1, number y1, number z1, number x2, number y2, number z2)
Returns table blocks info
Part of ComputerCraft
API commands

Examples

Grid paper.png  Example
Reports on a 2x2x2 area, with the Command Computer being at the lowest north-west point.
Code
local x, y, z = commands.getBlockPosition()

local blocks = commands.getBlockInfos(x, y, z, x + 1, y + 1, z + 1)

print("North-west low block:"..blocks[1].name)
print("North-east low block:"..blocks[2].name)
print("South-west low block:"..blocks[3].name)
print("South-east low block:"..blocks[4].name)
print("North-west high block:"..blocks[5].name)
print("North-east high block:"..blocks[6].name)
print("South-west high block:"..blocks[7].name)
print("South-east high block:"..blocks[8].name)


Grid disk.png Commands API Functions
commands.exec - commands.execAsync - commands.list - commands.getBlockPosition - commands.getBlockInfo - commands.getBlockInfos