set block configuration||doc135665

September 20, 2022

Format

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

Description

Set the block configuration name of the item.


Parameters

Variable name type Description
name string block configuration name


Code Samples

On the server side of the player entity templatemount script, add the error when the registered player switches hand-held itemCallback, when the new item is not empty and is a block, set the block configuration name of the item

Trigger.addHandler(this:cfg(), "HAND_ITEM_CHANGED", function(context)
    local entity = context.obj1
    local newItem = context.item
    local oldItem = context.oldItem
    if newItem and newItem:is_block() then
      newItem:set_block("blockName")
   end
  end)