Skip to content

Addon Development

Vortianski edited this page Nov 28, 2026 · 1 revision

Addon Development

Guided allows developers to register their own condition providers, page providers, page types, styles and text formatting tags using Java. You can use these extensions in guidebook JSON files the same way you use built-in features.

Registries

Registry Method Description
ProviderRegistry register(ResourceLocation, ConditionProvider) Registers a condition provider
PageProviders register(ResourceLocation, Provider) Registers a page provider
PageTypes register(ResourceLocation, PageFactory) Registers a page type
PageTypes register(ResourceLocation, Renderer) Registers a stateless page renderer
Styles register(ResourceLocation, StyleDefinition) Registers a Java style
FormattingRegistry register(ResourceLocation, String, UnaryOperator<Style>) Registers a text formatting tag

Registration

Register your extensions during client initialization, before any guidebooks are opened. Use your own mod ID as the namespace for registered identifiers.

Guided stores and resolves guidebook content on the client. Condition providers receive a LocalPlayer, not a ServerPlayer. Do not load your client-side extension classes on a dedicated server.

On Fabric call your registration methods from ClientModInitializer.onInitializeClient(). On NeoForge call them during client setup (for example, using FMLClientSetupEvent.enqueueWork). Keep Guided's Java API on your development classpath and declare Guided as a dependency of your addon. Use the dependency coordinates and version of the release you target.

The following Java examples use Minecraft 1.21.1 Mojang mappings. Registration statements are intended to be placed inside your client initialization method.

Condition providers

To create a condition provider implement ConditionProvider and register it using ProviderRegistry.

Example condition provider that checks the player's experience level:

import com.google.gson.JsonObject;
import net.minecraft.client.player.LocalPlayer;
import xox.labvorty.guided.data.providers.ConditionProvider;

public class ExperienceProvider implements ConditionProvider {
    @Override
    public boolean test(JsonObject definition, LocalPlayer player) {
        if (player == null || !definition.has("level")) {
            return false;
        }

        return player.experienceLevel >= definition.get("level").getAsInt();
    }
}

Register your provider:

import net.minecraft.resources.ResourceLocation;
import xox.labvorty.guided.data.registry.ProviderRegistry;
ProviderRegistry.register(
        ResourceLocation.parse("example:experience"),
        new ExperienceProvider()
);

Example condition definition:

{
  "type": "example:experience",
  "level": 5
}

Return true if the condition passes and false otherwise. The level parameter belongs to this example provider, not Guided's built-in providers. Validate your parameters and handle unavailable client data.

You can also use ProviderRegistry.testValues(comparison, currentValue, requiredValue) to compare integer or double values. Supported comparisons are >, >=, <, <=, == and !=.

Use ProviderRegistry.test(definition, player) to evaluate another condition from your own provider. Unknown provider IDs return false. Registering the same condition provider ID twice throws an exception.

For more information see Condition Providers.

Page providers

Page providers determine what happens when a page condition fails. To create a page provider implement PageProviders.Provider.

Parameter Type Description
page JsonObject Complete original page, including its type and definition
player LocalPlayer Current client player
depth int Current replacement recursion depth

Example page provider that displays a custom locked message:

import com.google.gson.JsonObject;
import net.minecraft.client.player.LocalPlayer;
import xox.labvorty.guided.data.page.PageProviders;

public class LockedPageProvider implements PageProviders.Provider {
    @Override
    public JsonObject resolve(JsonObject page, LocalPlayer player, int depth) {
        JsonObject definition = new JsonObject();
        definition.addProperty("text", "This page is locked!");

        JsonObject replacement = new JsonObject();
        replacement.addProperty("type", "guided:text");
        replacement.add("definition", definition);

        return PageProviders.resolve(replacement, player, depth + 1);
    }
}

Register your provider (import net.minecraft.resources.ResourceLocation and xox.labvorty.guided.data.page.PageProviders):

PageProviders.register(
        ResourceLocation.parse("example:locked"),
        new LockedPageProvider()
);

Example page definition:

{
  "type": "guided:text",
  "definition": {
    "text": "You have discovered diamonds!",
    "condition": {
      "type": "guided:advancement",
      "advancement": "minecraft:story/mine_diamond"
    },
    "provider_type": "example:locked"
  }
}

Return a complete replacement page or null to hide the original page. If the replacement has its own condition, resolve it using PageProviders.resolve(replacement, player, depth + 1). Guided stops resolving replacements when depth exceeds 16. Do not mutate the original page definition. Duplicate page provider IDs throw an exception.

For more information see Page Providers.

Page types

To create a page type implement BookPage and register a factory using PageTypes.register. The factory receives the page's definition object and creates a new page instance.

Example interactive page that counts left mouse clicks:

import com.google.gson.JsonObject;
import xox.labvorty.guided.data.page.BookPage;
import xox.labvorty.guided.data.page.PageRenderContext;

public class CounterPage implements BookPage {
    private int count;

    public CounterPage(JsonObject definition) {
        count = definition.has("start")
                ? definition.get("start").getAsInt()
                : 0;
    }

    @Override
    public void render(PageRenderContext context) {
        context.getGraphics().drawString(
                context.getFont(),
                "Count: " + count,
                context.getX(),
                context.getY(),
                0xff382719,
                false
        );
    }

    @Override
    public boolean mouseClicked(double x, double y, int button) {
        if (button != 0) {
            return false;
        }

        count++;
        return true;
    }
}

Register your page type (import net.minecraft.resources.ResourceLocation and xox.labvorty.guided.data.page.PageTypes):

PageTypes.register(
        ResourceLocation.parse("example:counter"),
        CounterPage::new
);

Example page definition:

{
  "type": "example:counter",
  "definition": {
    "start": 5
  }
}

The start parameter is optional and belongs to this example page type. The page starts at 5 and increases its counter each time the player left-clicks the page.

BookPage methods

Method Required Description
render(PageRenderContext context) Yes Renders the page
tick() No Updates the page while it is open
onOpen() No Called when the page is opened
onClose() No Called when the page is closed
mouseClicked(double x, double y, int button) No Handles mouse clicks
mouseReleased(double x, double y, int button) No Handles mouse release
mouseDragged(double x, double y, int button, double dx, double dy) No Handles mouse dragging
mouseScrolled(double x, double y, double horizontal, double vertical) No Handles mouse scrolling
keyPressed(int key, int scan, int modifiers) No Handles keyboard input

Input methods return true to consume the event. Mouse coordinates are absolute GUI coordinates. Click and scroll events are dispatched within page bounds; drag and release events follow the page that consumed the click.

Page instances are cached by entry and page index for the lifetime of the screen. Reloading clears the cache. Do not use page fields for permanent player progress and do not retain GuiGraphics outside the render method.

PageRenderContext

Method Return type Description
getGraphics() GuiGraphics GUI rendering context
getFont() Font Minecraft font
getStyle() StyleDefinition Current guidebook style
getX() int X position of page
getY() int Y position of page
getWidth() int Width of page
getHeight() int Height of page
getMouseX() int X position of mouse
getMouseY() int Y position of mouse
getPartialTick() float Partial tick value
getActions() Actions Guidebook actions
contains(double x, double y) boolean Checks if coordinates are inside page

Record-style accessors such as graphics(), width() and actions() are also available.

Page actions

Use context.getActions() to interact with the guidebook.

Method Return type Description
texture(String key, String fallback) String Resolves a texture using category, book and style overrides
openEntry(String id) void Opens a visible entry
openCategory(String id) void Opens a visible category
playSound(ResourceLocation id) void Plays a UI sound
openLink(String url) void Opens the HTTP(S) link confirmation screen
tooltip(List<Component> lines) void Displays a custom tooltip
itemTooltip(ItemStack stack) void Displays an item tooltip

For example, inside render:

if (context.contains(context.getMouseX(), context.getMouseY())) {
    context.getActions().tooltip(
            java.util.List.of(net.minecraft.network.chat.Component.literal("Click to increase the counter"))
    );
}

Stateless page renderers

For simple pages that do not need to store state or handle input, you can also register a six-argument PageTypes.Renderer.

PageTypes.register(
        ResourceLocation.parse("example:label"),
        (graphics, font, definition, x, y, width, height) -> {
            graphics.drawString(font, "Example page", x, y, 0xff382719, false);
        }
);

Example page definition:

{
  "type": "example:label",
  "definition": {}
}

Use the BookPage factory API for interactive pages. Registering an existing page type ID replaces its factory; use unique IDs to avoid conflicts.

For more information see Page Types.

Java styles

To create a Java style implement StyleDefinition and register it using Styles.register. Java styles allow you to customize rendering behavior rather than only replacing textures.

Example style that replaces the default entry background with a solid color and uses Guided's default connections:

import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import xox.labvorty.guided.data.style.StyleDefinition;
import xox.labvorty.guided.data.style.Styles;

public class ExampleStyle implements StyleDefinition {
    @Override
    public void renderBackground(GuiGraphics graphics) {
    }

    @Override
    public void renderPoint(GuiGraphics graphics) {
        graphics.fill(-12, -12, 12, 12, 0xff356e73);
    }

    @Override
    public void renderConnection(GuiGraphics graphics, Point start, Point end) {
        renderConnection(graphics, start, end, false, true);
    }

    @Override
    public void renderConnection(
            GuiGraphics graphics, Point start, Point end,
            boolean reversed, boolean arrow
    ) {
        Styles.get(ResourceLocation.parse("guided:default"))
                .renderConnection(graphics, start, end, reversed, arrow);
    }
}

Register your style (import net.minecraft.resources.ResourceLocation and xox.labvorty.guided.data.style.Styles):

Styles.register(
        ResourceLocation.parse("example:custom"),
        new ExampleStyle()
);

Example book definition:

{
  "name": "Example Guidebook",
  "type": "browser",
  "style": "example:custom"
}

StyleDefinition methods

Method Required Description
renderBackground(GuiGraphics) Yes Background hook; not called by the screen
renderPoint(GuiGraphics) Yes Renders default entry background
renderConnection(GuiGraphics, Point, Point) Yes Renders a connection
renderConnection(GuiGraphics, Point, Point, boolean, boolean) No Renders a connection with reversed and arrow flags
renderPanel(GuiGraphics, boolean, int, int, int, int) No Renders book or browser panel
renderButton(GuiGraphics, String, boolean, int, int) No Renders navigation button
renderButton(GuiGraphics, String, boolean, int, int, int, int) No Renders navigation button with mouse coordinates
renderUnread(GuiGraphics, int, int) No Renders unread indicator
renderFrameOverlay(GuiGraphics, String, int, int, int, int) No Renders decorative overlay
renderBookmark(GuiGraphics, int, int, boolean, boolean) No Renders category bookmark with selected and complete states
renderTab(GuiGraphics, int, int, boolean) No Legacy tab rendering hook
resolveTexture(String, String) No Resolves style texture override
renderEntryBackground(GuiGraphics, JsonObject) No Renders entry background
renderEntryIcon(GuiGraphics, JsonObject, int, int) No Renders entry icon
renderParallax(GuiGraphics, ResourceLocation, int, int, int, int, int, int, double, double) No Renders tiled browser background
renderPage(BookPage, PageRenderContext) No Renders page using current style
renderPageSprite(GuiGraphics, ResourceLocation, int, int, int, int) No Renders page sprite
getBrowserCullingMargin() No Returns browser culling margin (32 by default)

StyleDefinition.Point contains integer x() and y() coordinates. Entry backgrounds render around the translated origin, so a 24 × 24 background starts at (-12, -12).

Override renderParallax to customize the browser background. Its arguments after the texture are left, top, width, height, textureWidth, textureHeight, panX and panY.

Override the five-argument connection method if your style needs to respect line_reversed and draw_arrow. The default implementation delegates to the three-argument method and ignores these flags. Increase the culling margin if your decorations extend beyond the default bounds.

JSON styles take precedence over Java styles with the same ID. Unknown style IDs fall back to guided:default. Avoid replacing the built-in default when delegating to it as in the example above.

For more information see Styles.

Text formatting

To create a formatting tag use FormattingRegistry.register. Each tag applies a transformation to Minecraft's text Style.

Parameter Type Description
id ResourceLocation Unique registration ID
marker String Tag name used in text
transform UnaryOperator<Style> Transformation applied to the current text style

Example registration (import net.minecraft.resources.ResourceLocation and xox.labvorty.guided.data.page.FormattingRegistry):

FormattingRegistry.register(
        ResourceLocation.parse("example:highlight"),
        "highlight",
        style -> style.withColor(0xffaa00).withBold(true)
);

Example page definition:

{
  "type": "guided:text",
  "definition": {
    "text": "<highlight>Important information!</highlight>"
  }
}

Markers can contain letters, numbers, underscores, hyphens and colons. Use unique markers to avoid conflicts with other addons and built-in tags. Formatting transformations can be combined with other active tags. Return the modified Style from your transformation.

You can also use FormattingRegistry.parse(String text) to convert formatted text into a Minecraft Component. Translate the text before parsing if you want to support localization. This registration API defines fixed tags, not new parameterized tag syntax or arbitrary click handlers.

For more information see Text Formatting.

Testing your addon

Register your extensions, create a test resource pack and reference your registered identifiers in its JSON files. Open the guidebook and test both successful and failed conditions, page navigation, input and resource reloads. Test dedicated server startup to ensure client-only classes are not loaded there.

Clone this wiki locally