Skip to content

BlockEntity

Represents a block entity within the game world, such as a chest or furnace, containing additional data beyond a regular block.

Fields

world: World Read-Only

A reference to the world where this block entity is located.

name: string Read-Only

The name identifier of the block entity.

pos: Vec3 Read-Only

A copy of the position of the block entity within the world.

type: BlockEntityType Read-Only

A reference to the specific type of block entity (e.g., chest, furnace).

nbt: table Read/Write

A copy of the NBT (Named Binary Tag) data associated with the block entity, including custom data and metadata. Modifications to the table will not affect the actual block entity. To apply changes, either assign the modified table back (blockEntity.nbt = modifiedTable) or use putNbt().

Methods

putNbt(nbt: table)

Merges the specified NBT data into this block entity's existing data. This allows updating or adding custom properties stored within the block entity.

Example

local o = spell.owner
local h = o:raycastBlock(5)
spell.pos = h.blockPos
if spell.block.type.id ~= "chest" then
    print("no chest found")
    return
end
local blockEntity = spell.blockEntity
blockEntity:putNbt({
  CustomName = { text = "Treasure Chest", color = "gold", bold = true },
  Lock = "SecretKey"
})

Parameters

Name Type Description
nbt table The NBT data to merge, which can include custom properties and attributes.