# Block Management

Before using block API, please create the block management objects. The methods as follows:

local Block = class.Block.new()

The specific function name and description are as follows:

Serial number Function name Description
1 isSolidBlock(...) Whether it is solid block
2 isLiquidBlock(...) Whether it is liquid block
3 isAirBlock(...) Whether it is gas block
4 getBlockID(...) Obtain corresponding block id
5 setBlockAll(...) Set blockalldata. Update and notify
6 getBlockData(...) Obtain blockdata
7 destroyBlock(...) Destroy the block dropitem:Drops(Default false, no drops)
8 placeBlock(...) Place the block
9 replaceBlock(...) Replace blocks 1.1+
10 setBlockAllForUpdate(...) Set blockalldata, notify surrounding blocks
11 setBlockAllForNotify(...) Set blockalldata update the block of current location
12 setBlockSettingAttState(...) Set block's attribute and state
13 getBlockSettingAttState(...) Obtain the attribute and status of block Set
14 getBlockSwitchStatus(...) Obtain on-off state of function block
15 setBlockSwitchStatus(...) Set on-off state of function block
16 getBlockDataByDir(...) Obtain the data of block with direction 1.4+
17 getBlockPowerStatus(...) Obtain the status of block with power 1.1+

# isSolidBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Whether it is solid block
  • The specific use cases are as follows:
--Determine whether the position of (0,0) height 6 is a solid block
local result=Block:isSolidBlock(0,6,0)
if result==0 then--is a solid block
	Chat:sendSystemMsg("The position of coordinates(0,0) height 6 is a solid square")
else--not a solid block
	Chat:sendSystemMsg("The position of coordinate(0,0) height 6 is not a solid block")
end

# isLiquidBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Whether it is liquid block
  • The specific use cases are as follows:
--Determine whether the position of (0,0) height 6 is a liquid block
local result=Block:isSolidBlock(0,6,0)
if result==0 then--is a liquid block
	Chat:sendSystemMsg("The position of the coordinate(0,0) height 6 is the liquid block")
else--not a liquid block
	Chat:sendSystemMsg("The position of coordinate(0,0) height 6 is not a liquid block")
end

# isAirBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Whether it is gas block
  • The specific use cases are as follows:
--Determine whether the position of (0,0) height 6 is a gas block
local result=Block:isSolidBlock(0,6,0)
if result==0 then--is a gas block
	Chat:sendSystemMsg("The position of coordinate(0,0) height 6 is the gas block")
else--not a gas block
	Chat:sendSystemMsg("The position of coordinate(0,0) height 6 is not a gas block")
end

# getBlockID

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain corresponding block id
  • The specific use cases are as follows:
--Get the id of the block at (0,0) height 6
local result,id=Block:getBlockID(0,6,0)
--Show in chat box
Chat:sendSystemMsg("(0,0) the id of the block at height 6 is "..id)

# setBlockAll

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set blockalldata. Update and notify
  • The specific use cases are as follows:
--Set the position of (0,0) height 6 as bedrock
--The penultimate parameter 1 is the block id,and the last parameter 0 is the block data
--data is the block data,such as the color of the hard sand block,the tone of the music block,etc.,you can get it with getBlockData
Block:setBlockAll(0,6,0,1,0)
--Show in chat box
Chat:sendSystemMsg("Set the position of(0,0) height 6 as bedrock,data is 0")

# getBlockData

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain blockdata
  • The specific use cases are as follows:
--Get the block data at the position of (0,0) height 6
--data is block data,such as the color of the hard sand block,the tone of the music block,etc.
local result,data=Block:getBlockData(0,6,0)
--Show in chat box
Chat:sendSystemMsg("(0,0) the block data at height 6 is "..data)

# destroyBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Destroy the block dropitem:Drops(Default false, no drops)
  • The specific use cases are as follows:
--Destroy (0,0) blocks with a height of 6 and drop them
--The last parameter true is dropped,false is not dropped
Block:destroyBlock(0,6,0,true)
--Show in chat box
Chat:sendSystemMsg("Destroy(0,0) blocks with a height of 6 and drop them")

# placeBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Place the block
  • The specific use cases are as follows:
--Place a bedrock at (0,0) height 7,facing west.If there is already a block in this position,it cannot be placed.
--The first parameter 1 is the id of the placed block
--The middle three parameters 0,7,0 are the placement coordinates
--The last parameter 0 is the orientation parameter:0 West 1 East 2 South 3 North 4 Down 5 Up
Block:placeBlock(1,0,7,0,0)
--Show in chat box
Chat:sendSystemMsg("A bedrock was placed at a height of 7 at(0,0),facing west")

# replaceBlock 1.1+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Replace blocks
  • The specific use cases are as follows:
--Replace the (0,0) height 6 position with bedrock,facing west.
--The first parameter 1 is the id of the placed block
--The middle three parameters 0,6,0 are replacement coordinates
--The last parameter 0 is the orientation parameter:0 West 1 East 2 South 3 North 4 Down 5 Up
Block:placeBlock(1,0,6,0,0)
--Show in chat box
Chat:sendSystemMsg("(0,0) height 6 position was replaced with bedrock,facing west")

# setBlockAllForUpdate

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set blockalldata, notify surrounding blocks
  • The specific use cases are as follows:
--Set the position of (0,0) height 6 as bedrock (id:1)
--The first three parameters 0,6,0 are coordinates,the last parameter 1 is the block id
Block:setBlockAllForUpdate(0,6,0,1)
--Show in chat box
Chat:sendSystemMsg("(0,0) height 6 position is set as bedrock")

# setBlockAllForNotify

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set blockalldata update the block of current location
  • The specific use cases are as follows:
--Set the position of (0,0) height 6 as bedrock (id:1)
--The first three parameters 0,6,0 are coordinates,the last parameter 1 is the block id
Block:setBlockAllForNotify(0,6,0,1)
--Show in chat box
Chat:sendSystemMsg("(0,0) height 6 position is set as bedrock")

# setBlockSettingAttState

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set block's attribute and state
  • The specific use cases are as follows:
--Make all soil blocks unbreakable
--The first parameter 101 is the block id
--The second parameter 1 is the block attribute:1 destruction 2 operation 4 push and pull 8 drop 16 push and drop
--The third parameter false is "unavailable",changed to true means "can"
Block:setBlockSettingAttState(101,1,false)
--Show in chat box
Chat:sendSystemMsg("All clods are set to be indestructible!")

# getBlockSettingAttState

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the attribute and status of block Set
  • The specific use cases are as follows:
--Obtain whether the soil can be destroyed
--The first parameter 101 is the block id
--The second parameter 1 is the block attribute:1 destruction 2 operation 4 push and pull 8 drop 16 push and drop
local result,switch=Block:getBlockSettingAttState(101,1)
if switch then--can be destroyed
	Chat:sendSystemMsg("The clod can be destroyed!")
else--unbreakable
	Chat:sendSystemMsg("The soil can't be destroyed!")
end

# getBlockSwitchStatus

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain on-off state of function block
  • The specific use cases are as follows:
--Determine whether the block (such as a switch) at the position of (0,0) height 7 is turned on
local result,isactive=Block:getBlockSwitchStatus({x=0,y=7,z=0})
if isactive then--is opened
	Chat:sendSystemMsg("(0,0) height 7 block has been opened!")
else--not opened
	Chat:sendSystemMsg("(0,0) the block at height 7 is not turned on!")
end

# setBlockSwitchStatus

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Set on-off state of function block
  • The specific use cases are as follows:
--Turn on the (0,0) height 7 block (such as a switch)
--The last parameter true is open,false is closed
Block:setBlockSwitchStatus({x=0,y=7,z=0},true)
--Show in chat box
Chat:sendSystemMsg("The square at(0,0) height 7 is turned on!")

# getBlockDataByDir 1.4+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the data of block with direction
  • The specific use cases are as follows:
--Get data for larch facing north
--The first parameter 201 is the block id
--The second parameter 3 is the orientation parameter:0 West 1 East 2 South 3 North 4 Down 5 Up
local result,data=Block:getBlockDataByDir(201,3)
--Show in chat box
Chat:sendSystemMsg("The data of larch wood when facing north is:"..data)

# getBlockPowerStatus 1.1+

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain the status of block with power
  • The specific use cases are as follows:
--Determine whether the block at the position of (0,0) height 7 is energized
local result,isactive=Block:getBlockPowerStatus({x=0,y=7,z=0})
if isactive then--power on
	Chat:sendSystemMsg("(0,0) the block at height 7 has been powered on!")
else--no power
	Chat:sendSystemMsg("(0,0) block at height 7 is not powered!")
end
Last Update: 6/11/2020, 9:30:46 PM