Class ConfigBuilder
java.lang.Object
net.ixdarklord.coolcatcore.api.config.ConfigBuilder
Declares a config: its settings, then its groups and values, then
build() registers and loads it.
Values are added to the current group; push(String, String...) opens a nested group and pop() closes it, or
group(String, Consumer) does both around a block. Each value starts with a typed method
(bool(String, boolean), intValue(String, int), list(String, ConfigType, List)...), takes options, and ends with build(), which returns its
handle:
ConfigBuilder builder = Config.builder("mymod", ConfigScope.SERVER);
ConfigValue<Integer> maxHomes = builder.intValue("maxHomes", 3).range(0, 64).comment("Homes per player.").build();
builder.push("webhook");
ConfigValue<String> url = builder.string("url", "").serverOnly().build();
builder.pop();
Config config = builder.build();
-
Method Summary
Modifier and TypeMethodDescriptionbackground(net.minecraft.resources.Identifier texture) A background texture for this config's screen, by its full path (mymod:textures/gui/background.png), keeping the rest of the theme.build()Registers the config and loads its file.<T> EntryBuilder<T> A value of any codec, edited as JSON.An opaque color, packed as0xRRGGBB.colorWithAlpha(String key, int defaultValue) A color with alpha, packed as0xAARRGGBB.Lines at the top of the file.doubleValue(String key, double defaultValue) editPermission(net.minecraft.server.permissions.Permission permission) Who may change a synced config from a client (the in-game screen): game masters (Permissions.COMMANDS_GAMEMASTER) by default.effects(net.minecraft.resources.Identifier... effects) The animated effects of this config's screen, by the ids they're registered under on the client (CoolCatLib: Canvas'sConfigEffects.register), keeping the rest of the theme; none for a still screen.<E extends Enum<E>>
EntryBuilder<E> The file's path without extension, relative to the config folder:<modid>-<name>by default.floatValue(String key, float defaultValue) format(ConfigFormat format) The file's format:ConfigFormats.TOMLby default.group(String key, Consumer<ConfigBuilder> contents) Declares a nested group's contents in a block.hotReload(boolean hotReload) Whether edits to the file while the game runs are loaded automatically; on by default.EntryBuilder<net.minecraft.resources.Identifier> identifier(String key, net.minecraft.resources.Identifier defaultValue) EntryBuilder<net.minecraft.resources.Identifier> identifier(String key, net.minecraft.resources.Identifier defaultValue, net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> registry) An id suggested from a built-in registry, likeRegistries.BLOCK.<E> ListEntryBuilder<E> list(String key, ConfigType<E> elementType, List<E> defaultValue) migration(int fromVersion, ConfigMigration migration) Upgrades files of versionfromVersiontofromVersion + 1.The config's name, the path of its id (mymod:<name>); the scope's name by default.pop()Closes the group opened last.preset(String name, Consumer<ConfigPreset.Builder> values) A named set of values, translated asconfig.<modid>.<config>.preset.<name>.preset(String name, @Nullable net.minecraft.network.chat.Component displayName, Consumer<ConfigPreset.Builder> values) Opens a nested group; values and groups go into it untilpop().stringList(String key, List<String> defaultValue) theme(ConfigTheme theme) How this config's screen looks; the mod's theme (ConfigTheme.setForMod(String, ConfigTheme)) by default.<T> EntryBuilder<T> value(String key, ConfigType<T> type, T defaultValue) A value of any type, including a mod's ownConfigType.version(int version) The file version; files of older versions go through themigration(int, ConfigMigration)s.
-
Method Details
-
name
The config's name, the path of its id (mymod:<name>); the scope's name by default. -
fileName
The file's path without extension, relative to the config folder:<modid>-<name>by default. May contain folders:"mymod/client". -
format
The file's format:ConfigFormats.TOMLby default. Changing it later keeps players' values: a file in the other built-in format is converted once (and kept as a.bak). -
comment
Lines at the top of the file. -
version
The file version; files of older versions go through themigration(int, ConfigMigration)s. -
migration
Upgrades files of versionfromVersiontofromVersion + 1. -
editPermission
Who may change a synced config from a client (the in-game screen): game masters (Permissions.COMMANDS_GAMEMASTER) by default. The host of a singleplayer world always may. -
hotReload
Whether edits to the file while the game runs are loaded automatically; on by default. -
theme
How this config's screen looks; the mod's theme (ConfigTheme.setForMod(String, ConfigTheme)) by default. -
background
A background texture for this config's screen, by its full path (mymod:textures/gui/background.png), keeping the rest of the theme. -
effects
The animated effects of this config's screen, by the ids they're registered under on the client (CoolCatLib: Canvas'sConfigEffects.register), keeping the rest of the theme; none for a still screen. The id is all this needs, so it works in common code. -
push
Opens a nested group; values and groups go into it untilpop(). -
pop
Closes the group opened last. -
group
Declares a nested group's contents in a block. -
group
-
bool
-
intValue
-
longValue
-
floatValue
-
doubleValue
-
string
-
enumValue
-
color
An opaque color, packed as0xRRGGBB. -
colorWithAlpha
A color with alpha, packed as0xAARRGGBB. -
identifier
public EntryBuilder<net.minecraft.resources.Identifier> identifier(String key, net.minecraft.resources.Identifier defaultValue) -
identifier
public EntryBuilder<net.minecraft.resources.Identifier> identifier(String key, net.minecraft.resources.Identifier defaultValue, net.minecraft.resources.ResourceKey<? extends net.minecraft.core.Registry<?>> registry) An id suggested from a built-in registry, likeRegistries.BLOCK. -
list
-
stringList
-
value
A value of any type, including a mod's ownConfigType. -
codec
public <T> EntryBuilder<T> codec(String key, com.mojang.serialization.Codec<T> codec, T defaultValue) A value of any codec, edited as JSON. -
preset
A named set of values, translated asconfig.<modid>.<config>.preset.<name>. The block runs atbuild(), so it may refer to values declared after it. -
preset
public ConfigBuilder preset(String name, @Nullable @Nullable net.minecraft.network.chat.Component displayName, Consumer<ConfigPreset.Builder> values) -
build
Registers the config and loads its file.- Throws:
IllegalStateException- when a group is still open, or the config was already builtIllegalArgumentException- when a config with the same id exists
-