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.
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>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());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();supported config annotations:
@Config,@Category, and@Groupfor structure@Optionfor editable values@Rangefor numeric sliders and typed numeric fields@Dropdownand@Modefor fixed string choices@Colorfor 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.
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.
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 runClientor 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
run tests:
./gradlew testcheck formatting, tests, and the forge jar:
./gradlew spotlessCheck test assemblethe remapped jar is written to:
build/libs/confikure-1.0.0-SNAPSHOT-forge.jar
mit
