Library API
Save a loaded build to the player's schematics folder, or load a file from it as a build.
Save any loaded build as a .litematic in the schematics folder, as if the player had saved it. Most useful with previews, which have no file until one is saved. From BuildPrint 0.1.19.
boolean started = BuildprintLibrary.save("mymod", id, "Castle restyled", path -> {
if (path != null) player.displayClientMessage(Component.literal("Saved " + path), true);
});Good to know #
- It never writes over a file. When the name is taken, the new file gets a number.
- Characters a file name cannot hold, and spaces, become
_. - It saves the blueprint as it is now, before turning. Blocks the player swapped in BuildPrint are saved as the blueprint's own blocks.
- The file is written off the client thread. The callback runs on the client thread once it is on disk.
- The player is not told. Tell them yourself if they asked for the save.
Load a file as a build #
From BuildPrint 0.1.41, load puts a file from the player's schematics folder into the world as a build, the way the player loads one: saved with the world, in the Loaded list, and back after a restart. Any format BuildPrint reads works.
// The corner at 100 64 -20; null puts it at the player's feet.
BuildprintLibrary.load("mymod", "castles/keep.litematic", new int[]{100, 64, -20}, id -> {
if (id >= 0) MyQuests.track(id); // a BuildprintPlacements id
});- The file is a path inside the schematics folder, with
/between folders. Nothing outside the folder. - It is read off the client thread.
doneruns on the client thread once the build is in the world. - The player sees a line in chat naming your mod and the build, and can move or unload it like any other.
Reference #
| BuildprintLibrary | What it does |
|---|---|
isAvailable() | In a world. |
save(String owner, int id, String name, Consumer<String> done) | Write the build to <name>.litematic. done gets the path inside the schematics folder, or null when writing failed. Returns false, without calling done, when there is no such build. |
load(String owner, String file, int[] origin, IntConsumer done) | Load a file from the schematics folder as a build. origin is {x, y, z}, or null for the player's feet. done gets the build id, or -1 when the file could not be read. Returns false, without calling done, when the file is not there. Since 0.1.41. |
Something missing or wrong on this page? Say so on Discord.