Repository navigation
API Block State and Placement
Lua API / Blocks / State and placement
On this page
Maps field names to saved metadata definitions. Fields are allocated in sorted name order. Their encoded widths must fit in four metadata bits; enum widths round up to a whole number of bits.
state = {
active = { type = "boolean", default = false }
}| Field | Type | Default / requirement |
|---|---|---|
state.<name>.type |
string | Required: boolean or enum. |
state.<name>.values |
list of strings | Required for enums; 2–16 distinct values. Not permitted for booleans. |
state.<name>.default |
boolean or enum string | False for booleans; first enum value for enums. Must belong to the field. |
Use ctx.state:get(name) and ctx.state:set(name, value) from an eligible action context. Unknown fields and incompatible values are errors. Use tile data for larger persistent values.
Changing field names or enum order can change saved metadata interpretation. Keep the schema stable for existing worlds.
Optional string "horizontal". Requires a state.facing enum containing exactly north, east, south and west. Sets orientation when a living entity places the block. Declared collision and selection boxes use the enum's default facing and rotate with the saved facing.
state = {
facing = { type = "enum", values = { "north", "east", "south", "west" } }
},
placement = { facing = "horizontal", facingFrom = "player" }Optional string; the only supported value is "player". The block's front faces the placer, like a vanilla furnace.
Optional list selecting permitted support categories: "floor", "wall", "ceiling". Defaults to all categories. An empty list allows none.
placement = { attachTo = { "floor" }, requiresSolidSupport = true }Boolean, default false. Requires the supporting block face to be solid before placement succeeds.
Boolean, default false. Drops the attached block when its support no longer satisfies the support check.
When either support option is enabled for anything beyond floor-only attachment, declare state.attachedFace as an enum containing every allowed clicked face. Floor uses up, ceiling uses down, walls use north/east/south/west. Its metadata records the attachment face.
Physical faces are down, up, north, south, west, east, corresponding to native sides 0–5. Directional redstone can additionally use relative faces when horizontal facing is configured; see Redstone.
Example: Attached blocks.
- Installation
- Install scripts
- Getting started
- VS Code and LuaLS
- Examples
- Reload and compatibility
- Troubleshooting
- Changelog
Scripts and shared values
- Script lifecycle
- Packaged Lua mods
- Modules
- References and stacks
- Queries
- Overrides
- Minecraft constants
- Chat and positions
- Structured data
- Script configuration
- Particles
Blocks and items
- Multiblocks
- Blocks
- Block state and placement
- Block shapes and rendering
- Block callbacks
- Block ticks and redstone
- Items
- Fluids
- Item callbacks
- Tools and armor
- Materials
- Textures
Entities
- Entities
- Entity access and movement
- Entity lifecycle and data
- Entity health and loot
- Entity inventories and relationships
- Projectiles and pickups
- Entity presentation and sounds
- Living entities and AI
- Entity parts and sensors
Assets and audio
- Assets
- Models and animations
- Built-in Minecraft models
- Model appearances
- Blockbench workflow
- Audio
- Texture-pack overrides
Events and world actions
World generation
World systems
Inventories and screens
Recipes