TabbyLib Wiki
So baust du mit TabbyLib eine Config für deine Mod How to build a config for your mod with TabbyLib
Setup
Füge das TabbyLib-Maven-Repository und die Abhängigkeit für deinen Loader in die build.gradle ein. Ersetze 26.1 durch deine Minecraft-Version.
Add the TabbyLib maven repository and the dependency for your loader to your build.gradle. Replace 26.1 with your Minecraft version.
repositories {
maven { url = "https://avie29.me/maven" }
}
dependencies {
// Fabric (on 1.21.1: modImplementation)
implementation "me.avie29.tabbylib:tabbylib:1.0.0+26.1"
// NeoForge
implementation "me.avie29.tabbylib:tabbylib-neoforge:1.0.0+26.1"
// Forge (on 1.20.1: implementation fg.deobf("me.avie29.tabbylib:tabbylib-forge:1.0.0+1.20.1"))
implementation "me.avie29.tabbylib:tabbylib-forge:1.0.0+26.1"
}
Trage TabbyLib außerdem als Abhängigkeit deiner Mod ein, damit Spieler einen Hinweis bekommen, wenn es fehlt:
Also add TabbyLib as a dependency of your mod, so players get a message when it is missing:
// fabric.mod.json
"depends": {
"tabbylib": ">=1.0.0"
}
# neoforge.mods.toml (NeoForge) / mods.toml (Forge: mandatory=true instead of type)
[[dependencies.my_mod]]
modId = "tabbylib"
type = "required"
versionRange = "[1.0.0,)"
ordering = "AFTER"
side = "CLIENT"
Deine erste Config Your first config
Jede Einstellung ist ein Option-Objekt. Lege sie als Konstanten an und fasse sie in einer
TabbyConfig zusammen. build() registriert die Config bei TabbyLib und lädt die Datei
config/<modid>.json – sie wird angelegt, wenn es sie noch nicht gibt.
Every setting is an Option object. Create them as constants and put them into a
TabbyConfig. build() registers the config with TabbyLib and loads the file
config/<modid>.json – it is created when it does not exist yet.
public final class MyConfig {
public static final BooleanOption SHOW_HUD = BooleanOption.builder("showHud", true).build();
public static final IntOption SIZE = IntOption.builder("size", 10).slider(1, 50, 1).build();
public static final ColorOption COLOR = ColorOption.builder("color", 0xFFFFFFFF)
.alpha()
.dependsOn(SHOW_HUD)
.build();
private static TabbyConfig config;
// Call this in your client initializer (Fabric) / mod constructor (NeoForge, Forge)
public static void init() {
config = TabbyConfig.builder("my-mod")
.category("general", category -> category
.add(SHOW_HUD)
.group("look", group -> group.add(SIZE, COLOR)))
.build();
}
public static TabbyConfig get() {
return config;
}
}
Werte liest du mit get(). Änderst du einen Wert im Code, speichere die Config danach:
Read values with get(). When you change a value in code, save the config afterwards:
if (MyConfig.SHOW_HUD.get()) {
drawHud(MyConfig.SIZE.get(), MyConfig.COLOR.get());
}
MyConfig.SHOW_HUD.set(false);
MyConfig.get().save();
getPending()).
Erst „Speichern“ übernimmt ihn in get(). Für Vorschauen, die sofort reagieren sollen, nimm getPending().
getPending()).
Only "Save" moves it into get(). Use getPending() for previews that should react right away.
Optionstypen Option types
| Option | Im MenüIn the screen | BeispielExample |
|---|---|---|
BooleanOption |
An / Aus-ButtonOn / off button | BooleanOption.builder("enabled", true) |
IntOption |
Slider (slider) oder Eingabefeld (range)Slider (slider) or text field (range) |
IntOption.builder("size", 10).slider(1, 50, 1) |
DoubleOption |
Slider oder Eingabefeld für KommazahlenSlider or text field for decimals | DoubleOption.builder("scale", 1.0).slider(0.5, 3.0, 0.25) |
StringOption |
Textfeld, optional mit PrüfungText field, optionally validated | StringOption.builder("prefix", "Day").maxLength(32) |
EnumOption |
Button, der durch die Werte schaltet (Rechtsklick rückwärts)Button that cycles through the values (right click goes back) | EnumOption.builder("mode", Mode.SIMPLE) |
ColorOption |
Hex-Feld und Farbwähler, mit alpha() auch TransparenzHex field and color picker, with alpha() also transparency |
ColorOption.builder("color", 0xFFFF5555) |
KeyBindOption |
Tastenbelegung, gleich mit den Minecraft-SteuerungseinstellungenKey binding, in sync with Minecraft's controls | KeyBindOption.builder("toggleKey", myKeyMapping) |
StringListOption |
Liste mit Hinzufügen, Entfernen und SortierenList with add, remove and reorder | StringListOption.builder("players", List.of()) |
HudPositionOption |
Drag-&-Drop-Editor mit EinrastenDrag and drop editor with snapping | siehe HUDsee HUD |
Alle Builder haben dieselben zusätzlichen Einstellungen:
Every builder shares these extra settings:
BooleanOption.builder("glow", false)
.dependsOn(SHOW_HUD) // greyed out while SHOW_HUD is off
.enabledWhen(() -> SIZE.getPending() > 5) // or any other condition
.visibleWhen(() -> MODE.getPending() == Mode.ADVANCED) // hidden instead of greyed out
.requiresRestart() // shows a hint and a message after saving
.onChange(value -> reloadRenderer()) // runs after the value was saved
.binding(() -> Settings.glow, value -> Settings.glow = value) // use an existing field
.name(Component.literal("Glow")) // instead of the translation key
.tooltip(Component.literal("Makes it shine"))
.hidden() // saved, but not shown in the screen
.build();
Kategorien, Gruppen, Texte und Buttons Categories, groups, texts and buttons
Jede Kategorie wird ein Tab. Gruppen sind einklappbare Abschnitte innerhalb
einer Kategorie. Dazu kommen Textzeilen (label) und Buttons, die Code ausführen (ActionEntry).
Every category becomes a tab. Groups are collapsible sections inside a
category. You can also add lines of text (label) and buttons that run code (ActionEntry).
TabbyConfig.builder("my-mod")
.category("general", category -> category
.label(Component.translatable("config.my-mod.general.intro"))
.add(SHOW_HUD, SIZE)
.group("colors", group -> group
.description(Component.literal("Everything about colors"))
.collapsed() // closed when the screen opens
.add(COLOR, BACKGROUND)))
.category("advanced", category -> category
.add(DEBUG)
.add(ActionEntry.of(
Component.literal("Cache"),
Component.literal("Clear"),
() -> MyMod.clearCache())))
.build();
Übersetzungen Translations
TabbyLib sucht die Namen automatisch in den Sprachdateien deiner Mod (assets/<modid>/lang/en_us.json). Tooltips und Enum-Namen sind optional.
TabbyLib looks up all names in your mod's language files (assets/<modid>/lang/en_us.json). Tooltips and enum names are optional.
{
"config.my-mod.showHud": "Show HUD",
"config.my-mod.showHud.tooltip": "Shows or hides the whole HUD.",
"config.my-mod.mode.simple": "Simple",
"config.my-mod.mode.advanced": "Advanced",
"config.my-mod.category.general": "General",
"config.my-mod.group.colors": "Colors"
}
my_mod, auf Fabric aber
my-mod, setze .translationId("my-mod") – dann nutzen alle Loader dieselben Sprachdateien.
my_mod there but
my-mod on Fabric, set .translationId("my-mod") – then all loaders share the same language files.
HUD-Elemente HUD elements
Eine HudPositionOption speichert, wo ein HUD-Element steht. Die Position hängt an einer von neun
Ecken bzw. Kanten des Bildschirms und bleibt dort, auch wenn Fenstergröße oder GUI-Skalierung sich ändern.
Im Menü öffnet sie einen Editor, in dem Spieler das Element verschieben – mit Einrasten an Rändern, Mitte und Raster.
A HudPositionOption stores where a HUD element is. The position is attached to one of nine
anchors of the screen and stays there when the window size or GUI scale changes. In the screen it opens an
editor where players drag the element around – with snapping to the edges, the center and a grid.
public static final HudPositionOption POSITION = HudPositionOption.builder("position",
HudPosition.of(HudPosition.CENTER, HudPosition.END, 0, -50), // bottom center, 50 px above the bottom
MyHud::preview).build();
// Drawing the HUD
if (!TabbyLibApi.isHudEditorOpen()) { // the editor draws its own preview
HudPosition position = MyConfig.POSITION.get();
int x = position.x(screenWidth, width);
int y = position.y(screenHeight, height);
draw(graphics, x, y);
}
// Preview for the editor (uses the unsaved values)
public static HudPreview preview() {
return new HudPreview() {
public int width() { return currentWidth(); }
public int height() { return currentHeight(); }
public void render(GuiGraphicsExtractor graphics, int x, int y) { draw(graphics, x, y); }
};
}
// Open the editor directly, e.g. from a command
TabbyLibApi.openHudEditor(MyConfig.POSITION);
Auf 1.21.1 und 1.20.1 heißt die Grafikklasse GuiGraphics statt GuiGraphicsExtractor.
On 1.21.1 and 1.20.1 the graphics class is called GuiGraphics instead of GuiGraphicsExtractor.
Fortgeschritten Advanced
Config-Menü öffnenOpening the config screen
TabbyLibApi.openScreen("my-mod"); // e.g. from your own command
Screen screen = TabbyLibApi.createScreen(parent, "my-mod");
// Mod Menu (Fabric)
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> TabbyLibApi.createScreen(parent, "my-mod");
}
Auf NeoForge und Forge verbindet TabbyLib den „Config“-Button der Mod-Liste automatisch mit deiner Config.
On NeoForge and Forge, TabbyLib connects the "Config" button of the mod list to your config automatically.
Dateiname, Anzeige und SpeichernFile name, display and saving
TabbyConfig.builder("my-mod")
.fileName("mymod") // keeps an existing config/mymod.json
.name(Component.literal("My Mod")) // instead of the name from the mod metadata
.icon(Identifier.fromNamespaceAndPath("my-mod", "textures/gui/icon.png"))
.onSave(() -> MyMod.reload()) // runs after the file was written
...
Alte Config-Dateien übernehmenMigrating old config files
Hast du vorher eine eigene Config-Datei benutzt, kannst du sie beim Laden umbauen. Gibst du true zurück, wird die Datei danach neu geschrieben.
If you used your own config file before, you can convert it while loading. Return true and the file is written again afterwards.
.migration(json -> {
if (!json.has("oldName")) {
return false;
}
json.add("newName", json.remove("oldName"));
return true;
})
Verfügbare Versionen Available versions
| Minecraft | Fabric | NeoForge | Forge |
|---|---|---|---|
| 26.1 · 26.1.1 · 26.1.2 · 26.2 · 26.3 | tabbylib | tabbylib-neoforge | tabbylib-forge |
| 1.21.1 | tabbylib | tabbylib-neoforge | tabbylib-forge |
| 1.20.1 | – | – | tabbylib-forge |
Die Version ist immer 1.0.0+<Minecraft-Version>, zum Beispiel me.avie29.tabbylib:tabbylib-neoforge:1.0.0+1.21.1. Alle Versionen haben dieselben Funktionen und dieselbe API.
The version is always 1.0.0+<Minecraft version>, for example me.avie29.tabbylib:tabbylib-neoforge:1.0.0+1.21.1. All versions have the same features and API.