Events API

Hear what easy place, the printer, easy break and the excavator do, and when a build is finished.

For a quest mod (a quest done when a build is), a stats mod, or a HUD of your own. From BuildPrint 0.1.41.

Java
BuildprintEvents.listen("mymod", e -> {
    switch ((String) e.get("type")) {
        case "finished" -> MyQuests.buildDone((String) e.get("name"));
        case "placed" -> MyStats.count((String) e.get("by"));
        default -> { } // later versions may add types
    }
});

// No longer needed.
BuildprintEvents.unlisten("mymod");

Events #

Every event is a read-only map with a type. Later versions may add types and keys but never take one away, so ignore what you do not know.

typeWhenKeys
placedEasy place or the printer put a block down and the server took the click.by (easy_place or printer), dimension, pos (int[]{x, y, z}), block (the block state), build (the build there, or -1)
brokenEasy break or the excavator broke a block.The same, with by easy_break or excavator, and block what was there.
progressA build's counts changed. Looked at about once a second.build, completion (0 to 1), counts (as counts)
finishedEvery block of a build is right, after it was not. Once each time.build, name

Good to know #

  • Your listener is called on the client thread at the end of the tick the event happened in.
  • Blocks the player places or breaks by hand are not events here. The game has its own events for those.
  • A build that was already finished when it loaded does not send finished.
  • One listener per owner: a second call replaces the first. When it throws, BuildPrint logs it once and stops telling you until you listen again.
  • Only plain Java types, so you can call it by reflection.

Reference #

BuildprintEventsWhat it does
listen(String owner, Consumer<Map<String, Object>> listener)Hear every event.
unlisten(String owner)Stop telling that owner.
isAvailable()In a world. Listening works either way.

Something missing or wrong on this page? Say so on Discord.