Skip to content

tsukure/confikure

Repository files navigation

confikure

latest release maven release workflow license

confikure is an annotation-driven config gui library for forge 1.8.9 mods. it scans plain java config objects, persists them as json, and renders an in-game settings screen.

confikure gui preview

install

gradle kotlin dsl:

repositories {
    maven("https://maven.tsuku.re/releases")
}

val shadowModImpl by configurations.creating {
    configurations.modImplementation.get().extendsFrom(this)
}

dependencies {
    shadowModImpl("re.tsuku:confikure:1.0.0")
}

tasks.shadowJar {
    configurations = listOf(shadowModImpl)
    relocate("re.tsuku.confikure", "your.mod.deps.confikure")
}

confikure is intended to be shaded into your mod. relocation is recommended so multiple mods can ship different confikure versions in the same game installation.

for snapshots, use:

repositories {
    maven("https://maven.tsuku.re/snapshots")
}

maven:

<repositories>
  <repository>
    <id>tsukure-releases</id>
    <url>https://maven.tsuku.re/releases</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>re.tsuku</groupId>
    <artifactId>confikure</artifactId>
    <version>1.0.0</version>
  </dependency>
</dependencies>

for snapshots, use:

<repository>
  <id>tsukure-snapshots</id>
  <url>https://maven.tsuku.re/snapshots</url>
</repository>

basic usage

create a config:

import re.tsuku.confikure.annotations.Category;
import re.tsuku.confikure.annotations.Config;
import re.tsuku.confikure.annotations.Option;
import re.tsuku.confikure.annotations.Range;

@Config(name = "examplemod", id = "examplemod", description = "examplemod settings")
public final class ExampleConfig {
    @Category(name = "general")
    public final General general = new General();

    public static final class General {
        @Option(name = "enabled")
        public boolean enabled = true;

        @Option(name = "speed", description = "movement multiplier")
        @Range(min = 0.0D, max = 3.0D, step = 0.25D)
        public double speed = 1.0D;
    }
}

scan it when you need a definition:

import re.tsuku.confikure.Confikure;
import re.tsuku.confikure.model.ConfigDefinition;

ConfigDefinition definition = Confikure.scan(new ExampleConfig());

forge 1.8.9

open the built-in screen from a command or keybind:

import java.io.File;
import net.minecraft.client.Minecraft;
import re.tsuku.confikure.forge.ForgeConfig;

File configFile = new File(new File(Minecraft.getMinecraft().mcDataDir, "config"), "examplemod.json");
ForgeConfig.open(config, configFile);

open delays screen creation by one client tick so chat can close before the gui opens. openNow displays an already-created screen immediately.

to embed confikure inside your own GuiScreen, create a controller and forward lifecycle calls:

import re.tsuku.confikure.forge.ForgeConfig;
import re.tsuku.confikure.forge.ForgeConfigGui;

ForgeConfigGui gui = ForgeConfig.gui(config, configFile, confikure -> {
    confikure.sidebarHeader((renderer, bounds, theme) -> {
        renderer.text("examplemod", bounds.x, bounds.y, theme.text);
        renderer.text("settings", bounds.x, bounds.y + 12, theme.mutedText);
    });
});

gui.init(Minecraft.getMinecraft());
gui.render(mc, width, height, mouseX, mouseY);
gui.click(width, height, mouseX, mouseY);
gui.keyTyped(typedChar, keyCode);
gui.close();

annotations

supported config annotations:

  • @Config, @Category, and @Group for structure
  • @Option for editable values
  • @Range for numeric sliders and typed numeric fields
  • @Dropdown and @Mode for fixed string choices
  • @Color for argb color values, with optional alpha
  • @Keybind, @Text, @Multiline, @Info, @SearchTag, and @Button

option ids are generated from names by default. set explicit ids when a setting has already shipped and should keep the same persisted key.

themes

use the default theme:

ConfigGui gui = new ConfigGui(definition);

or select a built-in color scheme:

gui.themeSupplier(() -> ConfigColorScheme.byDisplayName(config.visuals.themeScheme).theme());

the built-in schemes are minecraft, catppuccin mocha, and ayu mirage.

example

src/forge/java is the production forge adapter that is included in release jars. src/example/java is a local example mod that shows command registration, config persistence, gui customization, read-only settings, conditional settings, and a small mod-owned event bus.

run the example mod:

./gradlew runClient

or use the generated Minecraft Client run configuration in intellij.

open the example gui with:

/confikure

the example config is written to:

run/config/confikure-example.json

build

run tests:

./gradlew test

check formatting, tests, and the forge jar:

./gradlew spotlessCheck test assemble

the remapped jar is written to:

build/libs/confikure-1.0.0-SNAPSHOT-forge.jar

license

mit

About

a java config and gui library for minecraft mods

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages