Block ID||doc135662

September 20, 2022

Format

 item:block_id() 
  • The class to which the function belongs:item

Description

Get the item block id.


Precautions

If the item is not a block, the return value is nil.


Value Returned

type Description
int block id


Code Samples

On the server side of the player entity templatemount script, add the error when the registered player switches hand-held itemCallback, if the new item is not empty, output its item block id

Trigger.addHandler(this:cfg(), "HAND_ITEM_CHANGED", function(context)
      local entity = context.obj1
      local newItem = context.item
      print(newItem and newItem:block_id())     
end)