Diese Seite auf Deutsch

The builder's desk ​

Players share their buildings as schematics: files of Litematica, Create or Axiom that you download and keep in a folder. This program is a desk for them: it lists your schematics on a laptop, tells you what a schematic needs and which of its blocks your server doesn't have, and then builds it from a chest – with the missing blocks replaced by ones you have.

Functions: SCHEMATIC_LIST, SCHEMATIC_MATERIALS, SCHEMATIC_MISSING, SCHEMATIC_LOAD with replace and CANVAS_ITEMS, with RENDER_CANVAS

What you need

  • the mods c0de and c0de paint 0.2.0 or later – c0de paint also on your own computer, because it reads the files there
  • a trigger block with a button on it, an empty sheet for the program and a laptop
  • two schematics in the folder schematics of your game folder: the well (a .litematic of Litematica) and the mill (a .nbt of Create, with blocks of Create)
  • a chest with 9 stone bricks, 16 oak planks, 8 stripped spruce logs and 2 oak logs for the mill
  • a free place of 3 × 3 blocks, 4 high
  • no rights: the mill is built from the chest

Where the schematics come from ​

Litematica and Create save schematics in the folder schematics of the game folder, next to saves and config; Axiom keeps its blueprints (.bp) in a folder of its own, so copy them over. That folder is on your computer. On a server, the server can't see it – so the functions of c0de_paint/schematics ask the client of the player who runs the process: the player who pressed the button, or the owner of the trigger block. Your client reads the file and sends it to the server, while the process waits on its CALL line. In single player, both are your computer.

A schematic is named by its file name, like "mill.nbt": only files directly in the folder schematics, no folders, no /, \ or :. Nothing outside of the folder can be read. Every player decides whether their client reads files at all: allowSchematics in config/c0de_paint-client.properties.

The desk ​

c0de
PROGRAM desk
NOOP
INCLUDE c0de/minecraft
INCLUDE c0de_paint/cpaint
INCLUDE c0de_paint/schematics
NOOP
FUNCTION list
BEGIN
    VARIABLE names ARRAY STRING
    CALL c0de_paint/schematics/SCHEMATIC_LIST
        RESULT result names
    CALL CLS
    CALL PRINT
        PARAMETER value "Schematics:" ;
    EACH name names
    BEGIN
        CALL PRINT
            PARAMETER value name ;
    END EACH
END FUNCTION
NOOP
FUNCTION check
    PARAMETER file STRING "mill.nbt"
    RESULT missing HASH INTEGER
BEGIN
    VARIABLE items HASH INTEGER
    VARIABLE count INTEGER
    CALL c0de_paint/schematics/SCHEMATIC_MATERIALS
        PARAMETER file file ;
        RESULT result items
    CALL c0de_paint/schematics/SCHEMATIC_MISSING
        PARAMETER file file ;
        RESULT result missing
    CALL CLS
    CALL PRINT
        PARAMETER value file ⊕ " needs:" ;
    EACH id items
    BEGIN
        CALL PRINT
            PARAMETER value items[id] ⊕ " " ⊕ id ;
    END EACH
    CALL LEN
        PARAMETER value missing ;
        RESULT result count
    IF count = 0 ;
    BEGIN
        CALL PRINT
            PARAMETER value "Everything is on this server." ;
    END
    ELSE
    BEGIN
        CALL PRINT
            PARAMETER value "Not on this server:" ;
        EACH id missing
        BEGIN
            CALL PRINT
                PARAMETER value missing[id] ⊕ " " ⊕ id ;
        END EACH
    END IF
END FUNCTION
NOOP
FUNCTION build
    PARAMETER file STRING "mill.nbt"
BEGIN
    VARIABLE swap HASH STRING
    VARIABLE missing HASH INTEGER
    VARIABLE plan TYPE c0de_paint/cpaint/CANVAS
    VARIABLE items HASH INTEGER
    VARIABLE site STRUCT c0de/minecraft/POSITION
    VARIABLE chest STRUCT c0de/minecraft/POSITION
    ASSIGN swap["create:andesite_casing"] "stripped_spruce_log" ;
    ASSIGN swap["create:shaft"] "oak_log" ;
    CALL c0de_paint/schematics/SCHEMATIC_MISSING
        PARAMETER file file ;
        PARAMETER replace swap ;
        RESULT result missing
    EACH id missing
    BEGIN
        ASSIGN swap[id] "" ;
    END EACH
    CALL c0de_paint/schematics/SCHEMATIC_LOAD
        PARAMETER file file ;
        PARAMETER replace swap ;
        RESULT result plan
    CALL c0de_paint/cpaint/CANVAS_ITEMS
        PARAMETER canvas plan ;
        RESULT result items
    CALL CLS
    CALL PRINT
        PARAMETER value "Building " ⊕ file ⊕ " from:" ;
    EACH id items
    BEGIN
        CALL PRINT
            PARAMETER value items[id] ⊕ " " ⊕ id ;
    END EACH
    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 FUNCTION

Building and running it ​

  1. Download the two schematics and put them into your folder schematics.
  2. Place the trigger block with the button 2 blocks west of where the mill should stand, and the chest 2 blocks west of the trigger block.
  3. Bind the laptop to desk / list, set the trigger block to desk and list, and press the button. The laptop lists your schematics.
  4. Switch both to check and press the button again. The laptop shows what the mill needs and what the server lacks:
mill.nbt needs:
8 create:andesite_casing
1 create:cogwheel
2 create:shaft
16 minecraft:oak_planks
9 minecraft:stone_bricks
Not on this server:
8 create:andesite_casing
1 create:cogwheel
2 create:shaft
  1. Put the oak logs, planks, stripped spruce logs and stone bricks into the chest, switch the trigger block and the laptop to build and press the button. The laptop lists what the mill was built from, and the mill appears 2 blocks east of the trigger block: a floor of stone bricks, walls of planks around a log as its axle, and a ring of stripped spruce on top.
the little mill of the schematic, 3 × 3 blocks and 4 high: stone bricks at the bottom, oak planks around an oak log, a ring of stripped spruce logs on top with a gap in its middle, the trigger block, the chest and the laptop with the list next to it

How it works ​

  • SCHEMATIC_LIST gives the names of the schematics in the folder, sorted – the names that the other functions take. Canvas files of SAVE_CANVAS are listed too.
  • SCHEMATIC_MATERIALS counts the items that RENDER_CANVAS would take, by item id. It works on the file and doesn't need a canvas, so it also counts schematics that are too large for one.
  • SCHEMATIC_MISSING lists the blocks that the server doesn't have: here the blocks of Create, which isn't installed. On a server with Create, the list is empty, and so is the result missing of check.
  • Replacing. replace is a HASH from block to block, applied while the file is read. The casings become stripped spruce logs, the shafts oak logs. A new block keeps the states of the old one that it has too: the shaft stands upright (axis y), so the log does as well.
  • Whatever is left out. build asks SCHEMATIC_MISSING again, now with replace: what is still missing – the cogwheel – gets the value "", which leaves its voxel empty. That way, build works with any schematic, even one full of blocks of other mods: everything the server doesn't know is skipped.
  • SCHEMATIC_LOAD reads the schematic into a canvas, its lowest corner at the voxel 0, 0, 0, with the states of the blocks and the data of chests and signs. Schematics of older versions of Minecraft are upgraded on the way. Entities like armor stands are left out; the result entities counts them.
  • CANVAS_ITEMS lists the items that RENDER_CANVAS takes for the canvas – after the replacing, so it is the list for the chest. Unlike CANVAS_MATERIALS, it counts items, not blocks: a double slab takes two slabs, water a water bucket.
  • Building. RENDER_CANVAS with input takes the blocks from the chest, like the shed of A first canvas, and checks the chest before the first block. Large schematics are built over many ticks, and the chunks they need are loaded on the way.

Try it yourself ​

  1. The mill has a hole where its cogwheel was. Put a lantern there instead.
Solution

One more line before the first SCHEMATIC_MISSING: ASSIGN swap["create:cogwheel"] "lantern" ;. Now nothing is left over, and the chest needs a lantern too – the laptop lists it.

  1. Check the well: what does it need, and is anything missing?
Solution

Put a STRING variable item file with well.litematic into the trigger block and run check. The well needs 17 cobblestone, 8 oak fences and 9 oak planks, and the laptop says "Everything is on this server." – it has only blocks of Minecraft.

  1. Press build while you are far away, and let a friend press it while you are offline. What happens?
Solution

Far away it works: the file comes from your client wherever you are, and the chunks of the mill are loaded for building. If you are offline, nobody's computer has the file: a friend who presses the button runs the process, so their client is asked – and without the file in their folder, the program crashes with SCHEMATIC_NOT_FOUND. A timer block without a player raises CLIENT_UNAVAILABLE.

Read more ​