Interface Config
- All Known Implementing Classes:
ConfigImpl
@NonExtendable
public interface Config
A registered config: a tree of
groups and typed values, stored in one file.
Declare one with a ConfigBuilder, keeping the value handles in static fields:
public final class MyModConfig {
private static final ConfigBuilder BUILDER = Config.builder("mymod", ConfigScope.CLIENT);
public static final ConfigValue<Boolean> SHOW_HUD = BUILDER.bool("showHud", true)
.comment("Draws the overlay.").build();
static { BUILDER.push("rendering"); }
public static final ConfigValue<Integer> PARTICLES = BUILDER.intValue("particles", 32)
.range(0, 256).slider().enabledWhen(SHOW_HUD).build();
static { BUILDER.pop(); }
public static final Config CONFIG = BUILDER.build();
}
or from an annotated class with ConfigObject. Building
registers the config and loads its file; the config screen, commands, hot reloading and (for synced scopes)
server sync then work without more code.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(Config.ChangeListener listener) Called with the values that changed, whenever any do, on the thread that changed them.all()Every registered config, in registration order.voidapplyPreset(ConfigPreset preset) Sets a preset's values, in memory;save()writes them.static ConfigBuilderbuilder(String modId, ConfigScope scope) Starts declaring a config named after its scope (mymod:client).comment()The file's comment lines.intThe permission level (0 to 4) a player needs to change a synced config from a client.@Nullable PathfilePath()The config file, or null while it has none (aConfigScope.WORLDconfig with no server running).Optional<ConfigValue<?>>The value at a dotted path, like"rendering.particles".format()A mod's registered configs, in registration order.get(net.minecraft.resources.ResourceLocation id) A registered config by its id (mymod:client).net.minecraft.resources.ResourceLocationid()<modid>:<name>.booleanisLoaded()Whether the values come from the file (or a server) rather than being defaults waiting for a world.booleanisRemote()Whether this client currently shows a server's values: the config is synced and the client is connected to a remote server.default booleanWhether aConfigScope.STARTUPconfig has saved changes that apply after a restart.default StringmodId()default Stringname()presets()The presets declared on the builder, by name.voidreload()Reads the file again, notifying listeners of whatever changed.booleanremoveListener(Config.ChangeListener listener) voidresetAll()Sets every value back to its default, in memory;save()writes it.root()voidsave()Writes the current values to the file.scope()theme()How the config's screen looks: its own theme, or the mod's.net.minecraft.network.chat.Componenttitle()The config's title:config.<modid>.<name>.title, falling back to the mod id and name.default Stream<ConfigValue<?>>values()Every value, depth first.intversion()The file version values are migrated to; 0 when the config isn't versioned.
-
Method Details
-
builder
Starts declaring a config named after its scope (mymod:client). -
get
A registered config by its id (mymod:client). -
all
Every registered config, in registration order. -
forMod
A mod's registered configs, in registration order. -
id
net.minecraft.resources.ResourceLocation id()<modid>:<name>. -
modId
-
name
-
scope
ConfigScope scope() -
format
ConfigFormat format() -
root
ConfigGroup root() -
title
net.minecraft.network.chat.Component title()The config's title:config.<modid>.<name>.title, falling back to the mod id and name. -
theme
ConfigTheme theme()How the config's screen looks: its own theme, or the mod's. -
comment
The file's comment lines. -
version
int version()The file version values are migrated to; 0 when the config isn't versioned. -
editPermission
int editPermission()The permission level (0 to 4) a player needs to change a synced config from a client. -
filePath
The config file, or null while it has none (aConfigScope.WORLDconfig with no server running). -
isLoaded
boolean isLoaded()Whether the values come from the file (or a server) rather than being defaults waiting for a world. -
isRemote
boolean isRemote()Whether this client currently shows a server's values: the config is synced and the client is connected to a remote server. Local changes aren't saved meanwhile, and the client's own values come back on disconnecting. -
isRestartPending
default boolean isRestartPending()Whether aConfigScope.STARTUPconfig has saved changes that apply after a restart. -
save
void save()Writes the current values to the file. Does nothing while the config has no file or is remote. -
reload
void reload()Reads the file again, notifying listeners of whatever changed. -
resetAll
void resetAll()Sets every value back to its default, in memory;save()writes it. -
find
The value at a dotted path, like"rendering.particles". -
values
Every value, depth first. -
presets
Map<String,ConfigPreset> presets()The presets declared on the builder, by name. -
applyPreset
Sets a preset's values, in memory;save()writes them. -
addListener
Called with the values that changed, whenever any do, on the thread that changed them. -
removeListener
-