# 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:
--判断(0,0)高度6的位置是不是固体方块
local result=Block:isSolidBlock(0,6,0)
if result==0 then--是固体方块
	Chat:sendSystemMsg("坐标(0,0)高度6的位置是固体方块")
else--不是固体方块
	Chat:sendSystemMsg("坐标(0,0)高度6的位置不是固体方块")
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:
--判断(0,0)高度6的位置是不是液体方块
local result=Block:isSolidBlock(0,6,0)
if result==0 then--是液体方块
	Chat:sendSystemMsg("坐标(0,0)高度6的位置是液体方块")
else--不是液体方块
	Chat:sendSystemMsg("坐标(0,0)高度6的位置不是液体方块")
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:
--判断(0,0)高度6的位置是不是气体方块
local result=Block:isSolidBlock(0,6,0)
if result==0 then--是气体方块
	Chat:sendSystemMsg("坐标(0,0)高度6的位置是气体方块")
else--不是气体方块
	Chat:sendSystemMsg("坐标(0,0)高度6的位置不是气体方块")
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:
--获取(0,0)高度6的位置的方块id
local result,id=Block:getBlockID(0,6,0)
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度6的位置的方块id是"..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:
--把(0,0)高度6的位置设置为基岩
--倒数第二个参数1为方块id,最后一个参数0为方块data
--data是方块数据,比如硬砂块的颜色、音乐方块的音调等等,具体可以用getBlockData获取
Block:setBlockAll(0,6,0,1,0)
--在聊天框显示
Chat:sendSystemMsg("把(0,0)高度6的位置设置为基岩,data为0")

# getBlockData

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Obtain blockdata
  • The specific use cases are as follows:
--获取(0,0)高度6的位置的方块data
--data是方块数据,比如硬砂块的颜色、音乐方块的音调等等
local result,data=Block:getBlockData(0,6,0)
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度6的位置的方块data是"..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:
--破坏(0,0)高度6的方块并掉落
--最后一个参数true为掉落,false为不掉落
Block:destroyBlock(0,6,0,true)
--在聊天框显示
Chat:sendSystemMsg("破坏了(0,0)高度6的方块并掉落")

# placeBlock

  • Parameters and types:
  • Return value and types:
  • The main role of this method: Place the block
  • The specific use cases are as follows:
--在(0,0)高度7放置一个基岩,朝向西。如果这个位置已经有了方块是无法放置的。
--第一个参数1为放置的方块id
--中间三个参数0,7,0为放置坐标
--最后一个参数0为朝向参数:0西 1东 2南 3北 4下 5上
Block:placeBlock(1,0,7,0,0)
--在聊天框显示
Chat:sendSystemMsg("在(0,0)高度7的位置放置了一个基岩,朝向西")

# 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:
--把(0,0)高度6的位置替换为基岩,朝向西。
--第一个参数1为放置的方块id
--中间三个参数0,6,0为替换坐标
--最后一个参数0为朝向参数:0西 1东 2南 3北 4下 5上
Block:placeBlock(1,0,6,0,0)
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度6的位置被替换成了基岩,朝向西")

# 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:
--把(0,0)高度6的位置设置为基岩(id:1)
--前三个参数0,6,0为坐标,最后一个参数1为方块id
Block:setBlockAllForUpdate(0,6,0,1)
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度6的位置被设置为了基岩")

# 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:
--把(0,0)高度6的位置设置为基岩(id:1)
--前三个参数0,6,0为坐标,最后一个参数1为方块id
Block:setBlockAllForNotify(0,6,0,1)
--在聊天框显示
Chat:sendSystemMsg("(0,0)高度6的位置被设置为了基岩")

# 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:
--把所有土块设置为不可破坏
--第一个参数101为方块id
--第二个参数1为方块属性:1破坏 2操作 4推拉 8掉落 16推拉掉落
--第三个参数false为“不可”,改为true表示“可以”
Block:setBlockSettingAttState(101,1,false)
--在聊天框显示
Chat:sendSystemMsg("所有土块被设置为了不可破坏!")

# 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:
--获取土块是否可被破坏
--第一个参数101为方块id
--第二个参数1为方块属性:1破坏 2操作 4推拉 8掉落 16推拉掉落
local result,switch=Block:getBlockSettingAttState(101,1)
if switch then--可以破坏
	Chat:sendSystemMsg("土块可以被破坏!")
else--不可破坏
	Chat:sendSystemMsg("土块无法被破坏!")
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:
--判断(0,0)高度7的位置的方块(比如开关)是否被打开
local result,isactive=Block:getBlockSwitchStatus({x=0,y=7,z=0})
if isactive then--被打开
	Chat:sendSystemMsg("(0,0)高度7的位置的方块已被打开!")
else--没有被打开
	Chat:sendSystemMsg("(0,0)高度7的位置的方块没有被打开!")
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:
--打开(0,0)高度7位置的方块(比如开关)
--最后一个参数true为打开,false为关闭
Block:setBlockSwitchStatus({x=0,y=7,z=0},true)
--在聊天框显示
Chat:sendSystemMsg("打开了(0,0)高度7的位置的方块!")

# 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:
--获取朝向北的落叶松木的data
--第一个参数201为方块id
--第二个参数3为朝向参数:0西 1东 2南 3北 4下 5上
local result,data=Block:getBlockDataByDir(201,3)
--在聊天框显示
Chat:sendSystemMsg("落叶松木在朝向北的时候的data为:"..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:
--判断(0,0)高度7的位置的方块有没有通电
local result,isactive=Block:getBlockPowerStatus({x=0,y=7,z=0})
if isactive then--通电
	Chat:sendSystemMsg("(0,0)高度7的位置的方块已被通电!")
else--没有通电
	Chat:sendSystemMsg("(0,0)高度7的位置的方块没有通电!")
end
Last Update: 9/7/2020, 10:19:13 PM