Skip to content

Structure Target

yuzhe edited this page Mar 12, 2026 · 1 revision

Structure Target

In addition to datapacks, RedScript can compile to Minecraft NBT structure files (.nbt) containing command blocks. This lets you place compiled logic directly in the world as a physical command block contraption.

Usage

redscript compile game.rs --target structure -o ./structures

Output: structures/game.nbt (NBT format, DataVersion 3953 for 1.21.4)

Layout

RedScript generates command blocks in this order:

[Impulse CB] __load     ← triggers on redstone pulse / button
[Chain CB]   function 1
[Chain CB]   function 2
[Repeat CB]  __tick      ← runs every tick automatically
[Chain CB]   tick logic
  • Impulse command blocks for one-shot functions
  • Chain command blocks for sequential execution
  • Repeat command blocks for @tick functions

Structure Optimizer

The structure target has additional optimizer passes:

Pass Description
Conditional chain flattening Collapses single-branch conditionals into the chain directly
Branch variable elimination Removes intermediate $cond scoreboard vars for unconditional branches
LICM Loop-invariant hoisting
Setblock → fill batching Same as datapack target

NBT Format

RedScript uses MC DataVersion 3953 (1.21.4). The NBT codec supports all 12 tag types including 64-bit Long via JavaScript BigInt.

Placing the Structure

  1. Copy structures/game.nbt to your world's structures/ folder or a datapack
  2. Use /place structure <namespace>:<name> ~ ~ ~
  3. Power the impulse command block to run __load
  4. The repeat command block runs __tick automatically

Comparison: Datapack vs Structure

Datapack Structure
Deploy Copy to datapacks/, /reload Place with /place structure
Performance Optimal (native function dispatch) Slightly worse (CB tick overhead)
Visibility Invisible Physical blocks in world
Use case Production logic Demos, workshops, self-contained maps

For most use cases, the datapack target is recommended.

Clone this wiki locally