ModificationStation / StationAPI

A general use API for Fabric Loader mods on legacy Minecraft versions.
83 stars 19 forks source link

HUD Text API #122

Open zr0n1 opened 1 month ago

zr0n1 commented 1 month ago

A simple API for adding (debug) text to the game HUD.

@EventListener
private static void renderHudText(HudTextRenderEvent event) {
    // The position will change based on whether the debug HUD is enabled
    event.left.add(new HudTextLine("This text displays regardless of whether the debug HUD is enabled!"));
    if (event.debug) {
        event.left.add(new HudTextLine("This text only displays on the debug HUD!", 0xE0E0E0));
    } else {
        // This will only succeed if the priority exceeds other mods with version text or other mods' version texts are disabled
        event.setVersion(new HudTextLine("StationAPI v2.0-alpha.3"));
        Collections.addAll(event.right,
                new HudTextLine("Hello " + event.minecraft.player.name + "!"),
                new HudTextLine("This line is doubly offset from the last. Perchance.", 0xFFFFFF, 20)
        );
    }
}

2024-07-15_02 02 29 2024-07-15_02 02 32