Skip to content

CTConfig

friendlyhj edited this page Aug 21, 2026 · 1 revision

CrT Configs

@since 1.25.0

Zen Utils allows to create config files in CrT that can be used in your scripts. The config will be accessible as file and ingame through the mod config GUI. Values changed ingame will automatically be updated in your scripts.

Create a config by using ConfigUtils.named("test").ADD_ENTRIES_HERE().register(), which will create a file /config/test.cfg and a CrT class dynamic.zenutils.config.Test.

Using .withGui(ConfigUtils.createMeta("Mod Name").ADD_MORE_METADATA_HERE()) makes it show in mod config GUI with the given fake mod metadata (description, credits etc.).

All entries are added using .add() behind them, to allow for nested entries. For example you add categories using .category("myCategory").ADD_ENTRIES_HERE().add().

The following entries are available:

Categories

category(name as string)

Single values

booleanValue(name as string, default as bool)

integer           (name as string, default as int)
lowerRangedInteger(name as string, default as int, min as int)
upperRangedInteger(name as string, default as int, max as int)
rangedInteger     (name as string, default as int, min as int, max as int)

doubleValue      (name as string, default as double)
lowerRangedDouble(name as string, default as double, min as double)
upperRangedDouble(name as string, default as double, max as double)
rangedDouble     (name as string, default as double, min as double, max as double)

stringValue(name as string, default as string)

configEnum(name as string, default as string, enums as string[])

Lists

booleanValues(name as string, ...default as bool)
integerArray(name as string, ...default as int)
doubleValues(name as string, ...doubles as double)
stringValues(name as string, ...strings as string)

Maps from String to various single values

booleanMap(name as string, OPTIONAL default as bool[string])
intMap   (name as string, OPTIONAL default as int[string])
doubleMap(name as string, OPTIONAL default as double[string])
stringMap(name as string, OPTIONAL default as string[string])

Maps from String to various lists

booleanArrayMap(name as string, OPTIONAL default as bool[][string])
intArrayMap   (name as string, OPTIONAL default as int[][string])
doubleArrayMap(name as string, OPTIONAL default as double[][string])    
stringArrayMap(name as string, OPTIONAL default as string[][string])

All entries can be modified by chaining some of the following functions before calling .add(). These enhance both the cfg files and the ingame config GUI.

displayName(displayName as string)
comment(...comments as string)
langKey(langKey as string)
requiresMcRestart()
requiresWorldRestart()
sliding() # only works for int & double ranged values (min&max given)

Note that if you set langKey to my.lang.key, the required keys will be my.lang.key for the config name and my.lang.key.tooltip for the config comment (use \n for newlines).

Example

import mods.zenutils.config.ConfigUtils;

ConfigUtils.named("testconfig")
    .withGui(
        ConfigUtils.createMeta("Test Config")
            .setDescription("§4Test Description")
            .setVersion("1.0.0")
            .addAuthor("My Name")
            .setCredits("§aSome credits")
    )
    
    .booleanValue("booleanValue", false).add()
    .rangedInteger("integer", 100, 0, 100)
        .displayName("Some int config")
        .langKey("mymodid.mylangkey")
        .comment("Some comment", "with another line")
        .sliding()
        .requiresMcRestart()
    .add()
    .doubleValue("doubleValue", 0.0).add()
    .stringValue("stringValue", "value").add()
    .configEnum("testEnum", "YES", ["YES", "NO", "MAYBE", "IDK"]).add()
    
    .category("lists")
        .booleanValues("bool_list", [true, true, false]).add()
        .integerArray("integer_list", [1, 1, 4, 5, 1, 4]).add()
        .doubleValues("double_list", [0.0, 0.1, 0.2]).add()
        .stringValues("string_list", ["hello world", "hello second"]).add()
    .add()
    
    .category("maps")
        .booleanMap("booleanMap", {someKey:true, someOtherKey:false}).add()
        .intMap("intMap", {someKey:0, someOtherKey:1}).add()
        .doubleMap("doubleMap", {someKey:0.0, someOtherKey:1.0}).add()
        .stringMap("stringMap", {someKey:"Yes :)", someOtherKey:"No :("}).add()
        
        .booleanArrayMap("booleanListMap", {someKey:[true, true, false]}).add()
        .intArrayMap("intListMap", {someKey:[0, 1, 2]}).add()
        .doubleArrayMap("doubleListMap", {someKey:[0.0, 1.0, 2.0]}).add()
        .stringArrayMap("stringListMap", {someKey:["Various", "strings"]}).add()
    .add()
    
.register();

Usage

import dynamic.zenutils.config.Testconfig;
import mods.zenutils.config.ConfigUtils;
import crafttweaker.data.IData;

print(Testconfig.stringValue);

print(Testconfig.maps.stringListMap.someKey[0]);

if (Testconfig.testEnum.getName() == "YES")
    print("enum value is YES");

Clone this wiki locally