Difference between revisions of "Commands.getBlockInfo"
From ComputerCraft Wiki
Smiley43210 (Talk | contribs) m (Changed "MineCraft" to "Minecraft") |
Magiczocker (Talk | contribs) m |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
{ | { | ||
+ | state = {{type|table}} state information | ||
name = {{type|string}} block's name, | name = {{type|string}} block's name, | ||
metadata = {{type|number}} block's metadata | metadata = {{type|number}} block's metadata | ||
Line 15: | Line 16: | ||
The block inspected will be in the same dimension as the computer. This function yields until the data is available to be returned. If the queried block exists in an ungenerated chunk, this function will cause that chunk to be generated. | The block inspected will be in the same dimension as the computer. This function yields until the data is available to be returned. If the queried block exists in an ungenerated chunk, this function will cause that chunk to be generated. | ||
− | See also: [ | + | The "state" sub-table is only present in Minecraft 1.8+, and contains the [https://minecraft.gamepedia.com/Block_states block state] info for the block being observed. For example, a log of wood's state table contains the keys "variant" (which may be set to eg "oak"), and "axis" (which may be set to eg "y", indicating an upright orientation). |
+ | |||
+ | See also: [[commands.getBlockInfos]](), [https://minecraft.gamepedia.com/Data_values Data Values @ Minecraft wiki] | ||
|examples= | |examples= | ||
Line 26: | Line 29: | ||
}} | }} | ||
{{Example | {{Example | ||
− | |desc= | + | |desc=Under MC 1.8, prints the facing of the [[Command Computer]] running the script by inspecting its own block state info. |
+ | |code=local blockInfo = '''commands.getBlockInfo( [[commands.getBlockPosition]]() )''' | ||
+ | |||
+ | [[print]]( "My facing is " .. blockInfo.state.facing ) | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Under MC 1.7.10, prints the facing of the [[Command Computer]] running the script by inspecting its own metadata. | ||
|code=local directions = {"unknown", "north", "south", "west", "east"} | |code=local directions = {"unknown", "north", "south", "west", "east"} | ||
local blockInfo = '''commands.getBlockInfo( [[commands.getBlockPosition]]() )''' | local blockInfo = '''commands.getBlockInfo( [[commands.getBlockPosition]]() )''' |
Latest revision as of 07:07, 4 August 2020
Function commands.getBlockInfo | |
Available only to Command Computers, returns a table containing information on the block at the specified world co-ordinate, formatted as follows:
{ state = table state information name = string block's name, metadata = number block's metadata } The block inspected will be in the same dimension as the computer. This function yields until the data is available to be returned. If the queried block exists in an ungenerated chunk, this function will cause that chunk to be generated. The "state" sub-table is only present in Minecraft 1.8+, and contains the block state info for the block being observed. For example, a log of wood's state table contains the keys "variant" (which may be set to eg "oak"), and "axis" (which may be set to eg "y", indicating an upright orientation). See also: commands.getBlockInfos(), Data Values @ Minecraft wiki | |
Syntax | commands.getBlockInfo(number x, number y, number z) |
Returns | table block info |
Part of | ComputerCraft |
API | commands |
Examples
Example | |
Prints the Command Computer's internal name and metadata value. | |
Code |
local blockInfo = commands.getBlockInfo( commands.getBlockPosition() ) print( "Computer block's name: ", blockInfo.name ) print( "Computer block's metadata: ", blockInfo.metadata ) |
Example | |
Under MC 1.8, prints the facing of the Command Computer running the script by inspecting its own block state info. | |
Code |
local blockInfo = commands.getBlockInfo( commands.getBlockPosition() ) print( "My facing is " .. blockInfo.state.facing ) |
Example | |
Under MC 1.7.10, prints the facing of the Command Computer running the script by inspecting its own metadata. | |
Code |
local directions = {"unknown", "north", "south", "west", "east"} local blockInfo = commands.getBlockInfo( commands.getBlockPosition() ) print( "My facing is ", directions[ blockInfo.metadata ], "." ) |
Commands API Functions |
---|
commands.exec - commands.execAsync - commands.list - commands.getBlockPosition - commands.getBlockInfo - commands.getBlockInfos |