Editor API
Add your own tools, buttons and drawings to the BuildPrint editor.
Add tools to the The editor. They sit on the toolbar next to the built-in ones and work the same way. From BuildPrint 0.1.17. This API uses BuildPrint's interfaces and Minecraft types, so you compile against the BuildPrint jar.
Register #
List a class under the buildprint entrypoint. BuildPrint calls it once, after its own tools exist. Fabric only calls it when BuildPrint is installed, so your mod still runs without it.
fabric.mod.jsonJSON"entrypoints": {
"buildprint": ["com.example.MyEditorTools"]
}public class MyEditorTools implements BuildprintEditorPlugin {
@Override
public void registerEditor() {
BuildprintEditor.registerGroup("mymod:curves", Component.literal("Curves"));
BuildprintEditor.registerTool("mymod:curves", new SplineTool());
BuildprintEditor.registerAction(BuildprintEditor.MAKE, new ClearAction());
BuildprintEditor.registerOverlay("mymod:spline", (draw, state) -> drawSpline(draw));
BuildprintEditor.addListener(new EditorListener() {
@Override public void onExit() { dropHalfDoneSpline(); }
});
}
}Groups #
BuildPrint has two: make, for making a new schematic from the world, and place, for moving a loaded build. Add to one of those when your tool does that job. A group of your own gets its own bar on the toolbar, after them.
Make a tool #
public class SplineTool implements BuildprintTool {
@Override public String id() { return "mymod:spline"; }
@Override public Component name() { return Component.literal("Spline"); }
@Override public ItemStack icon() { return new ItemStack(Items.STRING); }
@Override public Component leftHint() { return Component.literal("add a point"); }
@Override
public boolean onMouseButton(EditorClick click) {
if (click.button() != EditorClick.LEFT || !click.press()) return false;
BlockPos at = click.pickBlock(true); // through grass and flowers
if (at != null) points.add(at);
return true;
}
@Override
public void renderGizmos(GizmoDraw draw, EditorState state) {
for (BlockPos p : points) draw.block(p, 0xFFFFE066, 2f, 0x22FFE066);
}
}- The number keys, the scroll wheel and Tab pick it, and the toolbar shows its name and what each click does.
- While your tool is active you get every mouse press and release, and BuildPrint gets none.
renderGizmosruns every frame while the tool is active, after BuildPrint's own.- The icon is a GUI sprite (
sprite(), drawn 16 by 16) or an item (icon()). - Return false from
usable(state)to grey it out, for example while there is no region.
Actions and overlays #
- Actions (
BuildprintAction) are buttons that run once. Clicking one or pressing its number runsrun(state). The active tool stays what it was, and the scroll wheel skips them. - Overlays are drawn every frame while the editor is open, whatever tool is active. Use them for things that should stay visible, like a curve you are editing.
- Listeners (
EditorListener) hear when the editor opens or closes, the tool changes, or the target build changes.
Drawing and picking #
GizmoDrawdraws lines, arrows, dots, boxes, quads, text, region boxes and handles in BuildPrint's style.handleSize(at)gives a size that stays the same on screen at any distance.EditorClickhas the button, Shift, Ctrl and Alt, the crosshair ray andpickBlock(skipCover).EditorRayhas the ray math BuildPrint's own handles use: hit a box, hit a plane, closest point on a line.EditorStatehas the selected regions, the active one, the target build and the camera position.
Keys #
1 to 9 and 0 pick the first ten slots in toolbar order. Tab opens a picker with all of them, so tools past the tenth are still easy to reach. Ctrl and the scroll wheel stay fly speed.
When your code throws, BuildPrint logs it once and carries on without it, so a bug in a tool does not close the editor.
Reference #
| BuildprintEditor | What it does |
|---|---|
registerGroup(String id, Component title) | Add a toolbar group, drawn as its own bar. |
registerTool(String group, BuildprintTool tool) | Add a tool to the end of a group. |
registerAction(String group, BuildprintAction action) | Add a button that runs once. |
registerOverlay(String id, BiConsumer<GizmoDraw, EditorState> overlay) | Draw every frame while the editor is open. The same id replaces it. |
addListener(EditorListener listener) | Hear about open, close, tool and target changes. |
isActive() | Whether the editor is open. |
activeTool() | The active tool's id, like buildprint:select. Null when the editor is closed. |
selectTool(String id) | Make a tool active, or run an action. False when there is no such id. |
state() / crosshair() | What the editor is working on, and the crosshair ray. |
| BuildprintTool | What it does |
|---|---|
id() / name() | A namespaced id, and the name shown above the toolbar. |
sprite() / icon() | The toolbar icon. |
leftHint() / rightHint() | What a left and right click do, shown on the toolbar. |
usable(EditorState state) | False to grey it out. |
onMouseButton(EditorClick click) | A button went down or up. Return true when you used it. |
renderGizmos(GizmoDraw draw, EditorState state) | Draw while active. |
onSelected(EditorState state) / onDeselected() | Became active, or stopped being active. |
Something missing or wrong on this page? Say so on Discord.