Keeping canvases
A canvas lives only as long as its program runs. To keep a design, save it: SAVE_CANVAS writes it into a file, and LOAD_CANVAS reads it again – in another program, a week later, on another server. The file is plain text, so you can read it, change it, or write a design by hand.
Functions: SAVE_CANVAS and LOAD_CANVAS, the file format, with DRAW_LINE, DRAW_BLOCK and RENDER_CANVAS
What you need
- the mods c0de and c0de paint 0.2.0 or later – c0de paint also on your own computer, because the files are kept there
- a trigger block with a button on it and an empty sheet for the program
- a chest with 13 stone bricks and 1 lantern for the gate
- for the bench: a text editor, 3 oak stairs and 2 spruce trapdoors
- a free place of 5 blocks in a row, 5 high
- no rights: everything is built from the chest
The gate
PROGRAM gate
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
NOOP
FUNCTION draw
RESULT result TYPE c0de_paint/cpaint/CANVAS
BEGIN
VARIABLE a STRUCT c0de_paint/cpaint/POINT
VARIABLE b STRUCT c0de_paint/cpaint/POINT
VARIABLE bricks STRUCT c0de_paint/cpaint/BLOCK
VARIABLE lantern STRUCT c0de_paint/cpaint/BLOCK
VARIABLE stone TYPE c0de_paint/cpaint/STYLE
VARIABLE light TYPE c0de_paint/cpaint/STYLE
ASSIGN bricks.id "stone_bricks" ;
ASSIGN lantern.id "lantern" ;
ASSIGN lantern.properties["hanging"] "true" ;
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block bricks ;
RESULT result stone
CALL c0de_paint/cpaint/STYLE_SOLID
PARAMETER block lantern ;
RESULT result light
ASSIGN b.y 3 ;
CALL c0de_paint/cpaint/DRAW_LINE
PARAMETER canvas result ;
PARAMETER from a ;
PARAMETER to b ;
PARAMETER style stone ;
ASSIGN a.x 4 ;
ASSIGN b.x 4 ;
CALL c0de_paint/cpaint/DRAW_LINE
PARAMETER canvas result ;
PARAMETER from a ;
PARAMETER to b ;
PARAMETER style stone ;
ASSIGN a.x 0 ;
ASSIGN a.y 4 ;
ASSIGN b.y 4 ;
CALL c0de_paint/cpaint/DRAW_LINE
PARAMETER canvas result ;
PARAMETER from a ;
PARAMETER to b ;
PARAMETER style stone ;
ASSIGN a.x 2 ;
ASSIGN a.y 3 ;
CALL c0de_paint/cpaint/DRAW_BLOCK
PARAMETER canvas result ;
PARAMETER point a ;
PARAMETER style light ;
END FUNCTION
NOOP
FUNCTION design
PARAMETER name STRING "gate"
PARAMETER overwrite BOOLEAN FALSE
BEGIN
VARIABLE gate TYPE c0de_paint/cpaint/CANVAS
CALL draw
RESULT result gate
CALL c0de_paint/cpaint/SAVE_CANVAS
PARAMETER canvas gate ;
PARAMETER file name ;
PARAMETER overwrite overwrite ;
END FUNCTION
NOOP
FUNCTION build
PARAMETER name STRING "gate"
BEGIN
VARIABLE plan TYPE c0de_paint/cpaint/CANVAS
VARIABLE site STRUCT c0de/minecraft/POSITION
VARIABLE chest STRUCT c0de/minecraft/POSITION
CALL c0de_paint/cpaint/LOAD_CANVAS
PARAMETER file name ;
RESULT result plan
ASSIGN site.x PID.x + 2 ;
ASSIGN site.y PID.y ;
ASSIGN site.z PID.z ;
ASSIGN chest.x PID.x - 2 ;
ASSIGN chest.y PID.y ;
ASSIGN chest.z PID.z ;
CALL c0de_paint/cpaint/RENDER_CANVAS
PARAMETER canvas plan ;
PARAMETER position site ;
PARAMETER input chest ;
END FUNCTIONBuilding and running it
- Set the trigger block to
gateanddesign, and press the button. Nothing happens in the world – but the folderschematicsof your game folder now holds the filegate.canvas. - Place the chest 2 blocks west of the trigger block, with the stone bricks and the lantern.
- Switch to
buildand press the button. The gate appears 2 blocks east of the trigger block: two posts and a lintel of stone bricks, with a lantern hanging under the lintel.

The file
Open gate.canvas in a text editor:
# A canvas of c0de paint, saved by SAVE_CANVAS and read by LOAD_CANVAS of c0de_paint/cpaint.
# palette: the blocks, numbered from 0.
# rows: "x y z: entries", the voxels from x y z on along the x axis. An entry is the number
# of a block of the palette or _ for a voxel that isn't set; *n repeats it n times.
format: c0de_paint canvas
version: 1
palette:
- "minecraft:stone_bricks"
- "minecraft:lantern[hanging=true]"
rows:
- "0 0 0: 0 _*3 0"
- "0 1 0: 0 _*3 0"
- "0 2 0: 0 _*3 0"
- "0 3 0: 0 _ 1 _ 0"
- "0 4 0: 0*5"The palette lists the blocks of the canvas, numbered from 0, with their states – like in /setblock. Every row is a line of voxels along the x axis: 0 3 0: starts at the voxel 0, 3, 0, and then each entry stands for one voxel further east: 0 is stone bricks, _ a voxel that isn't set, 1 the lantern. 0*5 is five stone bricks in a row. The file format has all the details.
How it works
drawonly draws, like in A first canvas: three DRAW_LINEs for the posts and the lintel, and a DRAW_BLOCK for the lantern, whose BLOCK has the statehangingtrue.- SAVE_CANVAS writes the canvas into the folder
schematics, next to the schematics. The name"gate"gets the extension: the file isgate.canvas. Names are plain file names: no folders, no/,\or:. - On your computer. On a server, the file is written by the client of the player who runs the process, and read from there again – like the schematics of the builder's desk. Every player decides whether their client writes files:
allowSchematicWritesinconfig/c0de_paint-client.properties. - Only with
overwrite. A file that exists is only replaced withoverwrite TRUE. Without it, SAVE_CANVAS raises SCHEMATIC_EXISTS, so a seconddesigncan't destroy a design by accident. - LOAD_CANVAS reads the file into a canvas with the same voxels, blocks, states and data. The coordinates stay as they were, so the gate is built exactly as it was drawn.
A bench written by hand
A canvas file doesn't need a program. Write this into a file bench.canvas in your folder schematics:
# A garden bench, written by hand: three oak stairs between two spruce trapdoors as armrests.
format: c0de_paint canvas
version: 1
palette:
- "spruce_trapdoor[facing=west,half=bottom,open=true]"
- "oak_stairs[facing=north,half=bottom]"
- "spruce_trapdoor[facing=east,half=bottom,open=true]"
rows:
- "0 0 0: 0 1*3 2"Put the stairs and the trapdoors into the chest, a STRING variable item name with bench into the trigger block, and press build. An id without a namespace is one of Minecraft, like everywhere in c0de paint.
Try it yourself
- Press
designa second time. What happens – and how do you save a changed gate?
Solution
The program crashes with SCHEMATIC_EXISTS: gate.canvas is there already, and the file stays as it was. Put a BOOLEAN variable item overwrite with TRUE into the trigger block, and design replaces it.
- Make the bench longer, with five stairs, without touching the program.
Solution
Change the row to "0 0 0: 0 1*5 2" and save the file. Break the old bench, put 5 stairs and the 2 trapdoors into the chest and press build again: the bench is 7 blocks long now.
- Write
"0 0 0: 0 1*3 3"into the bench. What does LOAD_CANVAS say?
Solution
It raises SCHEMATIC_INVALID: the palette has no block 3. The message names the row and the entry, so you can find the mistake.
Read more
- The functions of this recipe: SAVE_CANVAS, LOAD_CANVAS, DRAW_LINE, DRAW_BLOCK and RENDER_CANVAS
- The file format of canvas files and the errors of c0de paint
- Your own schematics: canvases for Litematica, Create and Axiom