-
Notifications
You must be signed in to change notification settings - Fork 0
Structure Target
yuzhe edited this page Mar 12, 2026
·
1 revision
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.
redscript compile game.rs --target structure -o ./structuresOutput: structures/game.nbt (NBT format, DataVersion 3953 for 1.21.4)
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
@tickfunctions
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 |
RedScript uses MC DataVersion 3953 (1.21.4). The NBT codec supports all 12 tag types including 64-bit Long via JavaScript BigInt.
- Copy
structures/game.nbtto your world'sstructures/folder or a datapack - Use
/place structure <namespace>:<name> ~ ~ ~ - Power the impulse command block to run
__load - The repeat command block runs
__tickautomatically
| 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.