Addon API
Studio Menu has a small, stable API (com.studiomenu.api) so anyone can add new things to the menu editor. You write the drawing code; Studio Menu handles the editor UI, saving, moving and resizing, scaling to every resolution, entrance animations, opacity, background styles, undo, themes and modpack exports.
| You can add | Players see it as |
|---|---|
| Widgets (like the gallery or the server card) | a new entry in the editor's + panel, with its own settings in the inspector |
| Click actions | a new option in a button's "On click" list |
| Placeholders | {yourmod:name} working in any text, label, tip or changelog |
| Conditions | a new option in "Show in…" |
Rules
Addons are welcome, free or paid and under your own license, as long as (see the license page for details):
- Studio Menu is a required dependency of your addon, in
mods.tomland on CurseForge or Modrinth. - You never include Studio Menu inside your addon. Players download it from its official pages only (Modrinth and CurseForge).
- You don't present your addon as official. "Addon for Studio Menu" or "Requires Studio Menu" is great.
1. Set up the project
Quickest start: download the starter project above (a widget, a click action and a placeholder), put the Studio Menu jar in its libs/ folder and run gradlew runClient.
Or start from the MDK of your loader and Minecraft version. Put the official Studio Menu jar for that version in a libs/ folder (for compiling only; it is never shipped with your mod). The example below is for Minecraft 1.20.1 with ForgeGradle, the setup of the starter project; on newer versions use the same Studio Menu dependency in your MDK's build.gradle:
repositories {
flatDir { dir 'libs' }
}
dependencies {
minecraft "net.minecraftforge:forge:1.20.1-47.3.0"
// Studio Menu: compile against it; players install it themselves.
compileOnly fg.deobf("blank:studiomenu:0.2.0+1.20.1")
runtimeOnly fg.deobf("blank:studiomenu:0.2.0+1.20.1") // so it runs in your dev client too
}
blank:studiomenu:0.2.0+1.20.1 matches libs/studiomenu-0.2.0+1.20.1.jar; change it to the jar you have. The API (com.studiomenu.api) has the same shape on every Minecraft version; only Minecraft's own classes change between versions, so build one addon file per Minecraft version, like Studio Menu does.
2. Declare the dependency
In src/main/resources/META-INF/mods.toml:
[[dependencies.yourmod]]
modId = "studiomenu"
mandatory = true
versionRange = "[0.2,)"
ordering = "AFTER"
side = "CLIENT"
Studio Menu is client-only, so your addon should be too (displayTest="IGNORE_ALL_VERSION" in [[mods]]).
3. Register from client setup
@Mod.EventBusSubscriber(modid = "yourmod", value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public final class YourAddon {
@SubscribeEvent
public static void setup(FMLClientSetupEvent event) {
StudioMenuApi.registerWidget(HelloWidget.type());
StudioMenuApi.registerAction(MenuAction.withValue(new ResourceLocation("yourmod", "open_wiki"),
Component.literal("Open wiki page"), Component.literal("page name"),
(value, screen) -> Util.getPlatform().openUri("https://wiki.example.com/" + value)));
StudioMenuApi.registerPlaceholder(new ResourceLocation("yourmod", "season"), () -> Seasons.currentName());
StudioMenuApi.registerCondition(new ResourceLocation("yourmod", "winter"),
Component.literal("Winter"), () -> Seasons.current() == Season.WINTER);
}
}
Use your own mod id as the namespace. Registering the same id again replaces the earlier entry.
4. A complete widget
public final class HelloWidget implements MenuWidget {
public static WidgetType type() {
return WidgetType.builder(new ResourceLocation("yourmod", "hello"), HelloWidget::new)
.name(Component.literal("Hello"))
.description(Component.literal("Greets the player"))
.size(150, 24) // size when added, in GUI pixels
.property(WidgetProperty.text("message", Component.literal("Message"), "Hello {player}!"))
.property(WidgetProperty.color("color", Component.literal("Color"), "#FFFF55"))
.property(WidgetProperty.toggle("wave", Component.literal("Wave"), true))
.clickable() // optional: receive clicks
.build();
}
private int clicks; // one instance per placed widget
@Override
public void render(GuiGraphics g, WidgetContext ctx) {
ctx.drawBackground(g); // the style chosen in the editor
int y = ctx.y() + (ctx.height() - 8) / 2;
if (ctx.bool("wave")) y += Math.round(Mth.sin(ctx.millis() / 300f) * 2);
String text = ctx.text("message") + (clicks > 0 ? " ×" + clicks : "");
int x = ctx.x() + (ctx.width() - ctx.font().width(text)) / 2;
g.drawString(ctx.font(), text, x, y, ctx.withAlpha(ctx.color("color")), true);
}
@Override
public void onClick(WidgetContext ctx, int button) {
clicks++;
}
}
That's all. In game: open a menu, press F8, click + and your widget is under More widgets. Its settings appear in the inspector automatically.
Property kinds
| Factory | Editor row | Read with |
|---|---|---|
WidgetProperty.text(key, label, default[, hint]) | text box | ctx.string(key) (raw) or ctx.text(key) (placeholders applied) |
WidgetProperty.number(key, label, default, min, max, step[, suffix]) | − value + | ctx.integer(key) (always within min..max) |
WidgetProperty.toggle(key, label, default) | switch | ctx.bool(key) |
WidgetProperty.choice(key, label, default, Map<id, Component>) | cycle | ctx.string(key) (the option id) |
WidgetProperty.color(key, label, "#RRGGBB") | color cycle | ctx.color(key) (0xRRGGBB) |
WidgetProperty.image(key, label) (API 2) | picture picker | ctx.string(key); draw with ctx.drawImage(...) |
Keys are 1–32 characters of a-z, 0-9 and _. Add .initially(value) to a property when widgets added from now on should start with a different value than the default older saved widgets read (API 2).
What WidgetContext gives you
- The box:
x(),y(),width(),height(), already moved, scaled to the screen and animated. - Mouse:
mouseX(),mouseY(),hovered(),hoverProgress()(smooth 0 → 1). alpha()andwithAlpha(rgb): always draw with them, so opacity and fade-in work.millis(),partialTick(),font(),screen(),editing()(true inside the editor),elementId().drawBackground(g)andaccentColor(): the background style picked in the editor.placeholders(text)for any text of your own.scissor(g, x0, y0, x1, y1)to clip what you draw (theng.disableScissor()); it respects scaling on small screens.- (API 2)
drawImage(g, file, x, y, w, h, alpha, zoom)draws a picture from the media folder covering the box. - (API 2)
openLink(url)opens a link through Minecraft's confirmation screen. Don't call it whileediting().
Good practice
- Keep
renderfast. It runs every frame. Load files, images or network data in the background and cache them. - Draw something while editing. If there's nothing to show yet, use
ctx.editing()to draw a hint so the menu maker can see and place the widget. - Free what you create in
close()(textures, threads). It's called when the menu rebuilds and after ~30 s away from menus. - Translate your texts with your own lang files and
Component.translatable(...).
What Studio Menu does for you
- Safety: if your widget, action, placeholder or condition throws, Studio Menu logs it once and switches only that piece off.
- Missing addons: a layout that uses your widget without your addon installed keeps it hidden but saved; the editor shows "Missing addon: yourmod:hello" in its place, and it comes back when the addon is installed.
- Compatibility:
StudioMenuApi.VERSION(now2) only changes when something is added; code built for version 1 keeps working. Everything outsidecom.studiomenu.apiis internal.
Studio Menu's own Countdown and Image gallery widgets and its Copy modpack info action are built with this same public API. The sources jar on the download pages includes them as complete examples.