### Client Configuration Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example of client-side configuration properties. These settings control client behavior such as menu forcing, search inclusion, and formatting. ```properties # [Force Configured Menu] forceConfiguredMenu=false # [Include Folders in Search] includeFoldersInSearch=true # [Changed Formatting] changedFormatting=ITALIC ``` -------------------------------- ### Example Client Configuration Properties Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/configuration.md This example shows how to configure client-side settings for the Configured mod, such as overriding menus, including folders in search, and formatting changed properties. Ensure the file is named `configured-client.properties` and placed in the config directory. ```properties # -------- CONFIGURED CLIENT CONFIG -------- # If properties are missing, delete this file # and load the game to regenerate the config. # [Force Configured Menu] # If enabled, will attempt to override config screens provided by # other mods in favour for Configured's auto generated screen. May # not works for all mods. # Possible values: true, false forceConfiguredMenu=false # [Include Folders in Search] # When using the search bar in the config screen, the results will # also include folders and not just config properties. # Possible values: true, false includeFoldersInSearch=false # [Changed Formatting] # The chat formatting of a config property name when it has changed # during editing. # Possible values: OBFUSCATED, BOLD, STRIKETHROUGH, UNDERLINE, ITALIC changedFormatting=ITALIC ``` -------------------------------- ### Server Configuration Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example of server-side configuration properties. These settings enable developer mode, broadcast logs, and specify developer UUIDs. ```properties # [Developer Mode] developerMode=true # [Broadcast Logs] broadcastLogs=true # [Developers] developers=741c1d6f-84fa-47e8-99ad-78f97bb70eaa,8e91cfb3-5671-472f-a021-85d101025b1b ``` -------------------------------- ### Forge/NeoForge Registration Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfigProvider.md Example of how to register IModConfigProvider implementations in the mods.toml file for Forge or NeoForge. ```toml [modproperties.mod_id] configuredProviders=[ "com.example.path.to.MyProvider", "com.another.ProviderId" ] ``` -------------------------------- ### Fabric Registration Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfigProvider.md Example of how to register IModConfigProvider implementations in the fabric.mod.json file for Fabric. ```json { "custom": { "configured": { "providers": [ "com.example.path.to.MyProvider", "com.another.ProviderId" ] } } } ``` -------------------------------- ### Configuration Tree Model Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/core-architecture.md Illustrates the hierarchical structure of configuration entries, including folders and values with their types and constraints. ```text Root ├── Folder "graphics" │ ├── Value "brightness" (0-100) │ └── Value "quality" ("low"|"medium"|"high") └── Folder "gameplay" ├── Value "difficulty" (0-3) └── Value "pvp_enabled" (true|false) ``` -------------------------------- ### Handle Configuration Editing Start Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Called once when the player begins editing the configuration. Use this for initialization tasks. ```java default void startEditing() {} ``` -------------------------------- ### Working with Configuration Values Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md This example demonstrates how to retrieve, manipulate, and validate configuration values using the IConfigValue interface. ```APIDOC ## Usage Example This section illustrates how to use the `IConfigValue` interface to manage configuration settings. ### Methods - **`getConfigValue(String key)`**: Retrieves an `IConfigValue` instance for the given key. - **`get()`**: Reads the current value of the configuration setting. - **`getDefault()`**: Reads the default value of the configuration setting. - **`isChanged()`**: Checks if the current value differs from the initial value. - **`isDefault()`**: Checks if the current value is the same as the default value. - **`isValid(T value)`**: Validates if a given value is acceptable for the configuration setting. - **`set(T value)`**: Sets a new value for the configuration setting. - **`restore()`**: Resets the configuration value to its default. - **`getComment()`**: Retrieves the descriptive comment associated with the configuration setting. - **`requiresGameRestart()`**: Checks if changing this value requires a game restart. ### Example Usage ```java // Working with a configuration value IConfigValue brightness = getConfigValue("brightness"); // Read current and default values int current = brightness.get(); // e.g., 80 int defaultVal = brightness.getDefault(); // e.g., 100 // Check if value has been changed if (brightness.isChanged()) { System.out.println("Value was modified"); } // Check if matches default if (brightness.isDefault()) { System.out.println("Value is at default"); } // Validate before setting int newBrightness = 150; if (brightness.isValid(newBrightness)) { brightness.set(newBrightness); } else { System.out.println("Invalid: " + brightness.getValidationHint()); } // Reset to defaultrightness.restore(); // Access metadata System.out.println("Requires restart: " + brightness.requiresGameRestart()); System.out.println("Comment: " + brightness.getComment()); ``` ### Validation Hint - **`getValidationHint()`**: Provides a message explaining why a value is invalid. ``` -------------------------------- ### Check Log Broadcasting Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example showing how to check if logs should be broadcast and initiating broadcast if true. ```java // Check if logs should be broadcast if (Config.shouldBroadcastLogs()) { // Broadcast config updates to all developers broadcastUpdate(update); } ``` -------------------------------- ### Integrate Config Opening with Key Bindings Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Provides an example of how to open a configuration screen using a key binding. It handles gathering available configs and displays a message if no configs are found. ```java public class ConfigKeyBindings { public static final KeyMapping OPEN_CONFIG = new KeyMapping( "key.configured.open_config", InputConstants.KEY_C, "key.categories.configured" ); public static void handleKeyPress() { ClientPacketListener connection = Minecraft.getInstance().getConnection(); if (connection == null) return; // Gather all available configs for current mods Map> configs = ClientHandler.createConfigMap( new ModContext(MOD_ID) ); if (configs.isEmpty()) { Minecraft.getInstance().player.displayClientMessage( Component.literal("No configs available"), false ); return; } Screen configScreen = ConfigScreenHelper.createSelectionScreen( Minecraft.getInstance().screen, Component.literal("Mod Configuration"), configs ); Minecraft.getInstance().setScreen(configScreen); } } ``` -------------------------------- ### Example Java Code Block Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/MANIFEST.md This is a placeholder for a typical Java code example that might be found in the documentation. It demonstrates a common usage pattern. ```java ```java // Example usage of a configuration method ConfigEntry entry = new ConfigEntry("exampleKey", "Default Value"); String value = entry.getValue(); System.out.println("Current value: " + value); ``` ``` -------------------------------- ### Check and Use Forced Menu Configuration Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example demonstrating how to check if the forced menu is enabled and use Configured's config screen if it is. ```java // Check if forced menu is enabled if (Config.isForceConfiguredMenu()) { // Use Configured's config screen for all mods useConfiguredScreen(); } ``` -------------------------------- ### Get Developers and Authorize Player Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example of retrieving the list of authorized developers and checking if a player is in that list to allow remote editing. ```java // Get list of authorized developers ImmutableList developers = Config.getDevelopers(); if (developers.contains(player.getUUID())) { // Player is authorized for remote editing allowRemoteEdit(player); } ``` -------------------------------- ### Validate Developer Setup Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md A method to validate the developer setup by checking if developer mode is enabled and if developers are listed. It prints the status and lists authorized developers. ```java public void validateDeveloperSetup() { if (!Config.isDeveloperEnabled()) { System.out.println("Developer mode is disabled"); return; } ImmutableList developers = Config.getDevelopers(); if (developers.isEmpty()) { System.out.println("WARNING: Developer mode enabled but no developers listed"); return; } System.out.println("Developer mode enabled for " + developers.size() + " players:"); for (UUID uuid : developers) { System.out.println(" - " + uuid); } } ``` -------------------------------- ### Get and Apply Changed Value Formatting Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example of retrieving the ChatFormatting for changed values and applying it to a Component. ```java // Get the formatting for changed values ChatFormatting format = Config.getChangedFormatting(); // Apply when displaying modified config names Component configName = Component.literal("brightness") .withStyle(format); ``` -------------------------------- ### Implement IModConfigProvider Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfigProvider.md Example of a custom configuration provider that loads configurations for a specific mod. Implement this interface to integrate your own configuration loading system. ```java public class MyConfigProvider implements IModConfigProvider { @Override public Set getConfigurationsForMod(ModContext context) { Set configs = new HashSet<>(); // Load configurations specific to this mod String modId = context.modId(); // Example: load from custom config system MyConfigManager.getConfigs(modId) .stream() .map(MyModConfig::new) .forEach(configs::add); return configs; } } ``` -------------------------------- ### Developer Configuration Properties Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/configuration.md This example shows the structure and default values for developer configuration properties. Ensure these properties are set correctly in the `configured-developer.properties` file for server development. ```properties # ------- CONFIGURED DEVELOPER CONFIG ------- # If properties are missing, delete this file # and load the game to regenerate the config. # [Developer Mode] # Enables the ability to update remote configs. You should only enabled # developer mode when you are developing your server. This mode should not # be enabled if you are running in production, a public server, or a server # with players you don't trust. Even if this mode is enabled, you will still # need to authorise players who have access to editing remote configs by # listing them in the developers property below and they must also have # operator privileges. Only config systems that support remote editing will # be able to be edited. # Possible values: true, false developerMode=false # [Broadcast Logs] # When a remote config is updated by a developer, broadcast those changes, # successful or not, into the chat of other developers. The log is also included # in the normal log of the game. # Possible values: true, false broadcastLogs=true # [Developers] # A list of comma separated UUIDS of players who are authorised to edit remote # configs. The players must also have operator privileges. # You can find the UUID of a player in the log file when they join your server # or use https://mcuuid.net/ # EXAMPLE: developers=741c1d6f-84fa-47e8-99ad-78f97bb70eaa,8e91cfb3-5671-472f-a021-85d101025b1b developers= ``` -------------------------------- ### Framework Config Provider Implementation Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfigProvider.md An example implementation of IModConfigProvider for a framework that manages its own configurations. It filters configurations by mod ID. ```java public class FrameworkConfigProvider implements IModConfigProvider { @Override public Set getConfigurationsForMod(ModContext context) { if(!Services.PLATFORM.isModLoaded("framework")) return Collections.emptySet(); return FrameworkConfigManager.getInstance().getConfigs() .stream() .filter(config -> config.getName().getNamespace().equals(context.modId())) .map(FrameworkModConfig::new) .collect(Collectors.toUnmodifiableSet()); } } ``` -------------------------------- ### Check if Server-Side Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/types.md Determines if a configuration type is loaded when the server starts. Returns true for server-related configurations. ```java boolean isServer() ``` -------------------------------- ### NeoForge Config Provider Implementation Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfigProvider.md An example implementation of IModConfigProvider for NeoForge. It collects configurations from different ModConfig types. ```java public class NeoForgeConfigProvider implements IModConfigProvider { @Override public Set getConfigurationsForMod(ModContext context) { Set configs = new HashSet<>(); // Collect configurations from each config type addForgeConfigSetToMap(context, ModConfig.Type.CLIENT, configs::add); addForgeConfigSetToMap(context, ModConfig.Type.COMMON, configs::add); addForgeConfigSetToMap(context, ModConfig.Type.SERVER, configs::add); addForgeConfigSetToMap(context, ModConfig.Type.STARTUP, configs::add); return configs; } private static void addForgeConfigSetToMap( ModContext context, ModConfig.Type type, Consumer consumer) { Set configSet = ModConfigs.getConfigSet(type); configSet.stream() .filter(config -> config.getModId().equals(context.modId()) && config.getSpec() instanceof ModConfigSpec) .map(NeoForgeConfig::new) .forEach(consumer); } } ``` -------------------------------- ### Check and Use Folder Inclusion in Search Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example showing how to check if folders are included in search and enable folder entry searching if true. ```java // Check if folders are included in search if (Config.isIncludeFoldersInSearch()) { // Include folder entries in search results searchIncludeFolders(); } ``` -------------------------------- ### Usage Example for IConfigValue Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Demonstrates how to interact with a configuration value of type Integer. Shows reading current and default values, checking modification status, validation, setting new values, and accessing metadata. ```java IConfigValue brightness = getConfigValue("brightness"); int current = brightness.get(); // e.g., 80 int defaultVal = brightness.getDefault(); // e.g., 100 if (brightness.isChanged()) { System.out.println("Value was modified"); } if (brightness.isDefault()) { System.out.println("Value is at default"); } int newBrightness = 150; if (brightness.isValid(newBrightness)) { brightness.set(newBrightness); } else { System.out.println("Invalid: " + brightness.getValidationHint()); } brightness.restore(); System.out.println("Requires restart: " + brightness.requiresGameRestart()); System.out.println("Comment: " + brightness.getComment()); ``` -------------------------------- ### Get Tooltip for Configuration Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigEntry.md Provides an optional tooltip component for the configuration entry, displayed on hover in the GUI. ```java @Nullable Component getTooltip() ``` -------------------------------- ### ClientHandler Error Logging Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Illustrates the error message logged by ClientHandler when a configuration provider throws an exception during discovery. This helps in diagnosing issues with specific providers. ```text An error occurred when loading configs from provider: com.mrcrayfish.configured.impl.neoforge.NeoForgeConfigProvider java.lang.NullPointerException at com.mrcrayfish.configured.impl.neoforge.NeoForgeConfigProvider.getConfigurationsForMod(NeoForgeConfigProvider.java:24) ``` -------------------------------- ### IModConfig Implementation Examples Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ActionResult.md Illustrates how ActionResult is used within an IModConfig implementation for various operations like updating configuration, checking player edit permissions, and loading world configurations. ```java public class MyConfig implements IModConfig { @Override public ActionResult update(IConfigEntry entry) { Set> changedValues = getChangedValues(entry); if (changedValues.isEmpty()) { return ActionResult.success(); // No changes to save } try { saveChanges(changedValues); return ActionResult.success( Component.literal("Saved " + changedValues.size() + " values") ); } catch (IOException e) { return ActionResult.fail( Component.literal("Save failed: " + e.getMessage()) ); } } @Override public ActionResult canPlayerEdit(@Nullable Player player) { if (player == null) { return ActionResult.success(); // Allow in main menu } if (!player.canUseGameMasterBlocks()) { return ActionResult.fail( Component.translatable("configured.error.no_permission") ); } return ActionResult.success(); } @Override public ActionResult loadWorldConfig(Path path) { try { loadFromFile(path); return ActionResult.success(); } catch (IOException e) { return ActionResult.fail( Component.literal("Failed to load: " + e.getMessage()) ); } } } ``` -------------------------------- ### Get Configuration File Name Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Returns the string filename used to identify the configuration file on disk. ```java String getFileName() ``` -------------------------------- ### Get Client-Side Configurations Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Retrieves all client-specific configurations for a given mod. Returns an empty set if no client configurations are found. ```java public Set getClientConfigs(String modId) { ModContext context = new ModContext(modId); Map> configs = ClientHandler.createConfigMap(context); return configs.getOrDefault(ConfigType.CLIENT, new HashSet<>()); } ``` -------------------------------- ### Check Developer Mode and Enable Remote Editing Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Example demonstrating how to check if developer mode is enabled and allow remote configuration editing. ```java // Check if developer mode is enabled if (Config.isDeveloperEnabled()) { // Allow remote config editing enableRemoteConfigEditing(); } ``` -------------------------------- ### Implement Custom Folder Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigEntry.md Example of a custom folder entry that implements the IConfigEntry interface. This class defines a folder within the configuration tree, which can contain other entries but does not hold a direct value itself. ```java public class CustomFolderEntry implements IConfigEntry { private final String name; private final List children; private final String translationKey; public CustomFolderEntry(String name, List children, String translationKey) { this.name = name; this.children = children; this.translationKey = translationKey; } @Override public List getChildren() { return new ArrayList<>(children); } @Override public boolean isRoot() { return false; } @Override public boolean isLeaf() { return false; // This is a folder } @Override public IConfigValue getValue() { return null; // Folders don't have values } @Override public String getEntryName() { return name; } @Nullable @Override public Component getTooltip() { return Component.literal("Folder: " + name); } @Nullable @Override public String getTranslationKey() { return translationKey; } } ``` -------------------------------- ### Implementation Example of IConfigValue Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Provides a concrete implementation of the IConfigValue interface for Integer types. This class manages default, initial, and current values, along with min/max bounds for validation and associated comments. ```java public class ConfigIntValue implements IConfigValue { private final Integer defaultValue; private final Integer initialValue; private Integer currentValue; private final Integer minValue; private final Integer maxValue; private final String name; private final Component comment; public ConfigIntValue(String name, Integer defaultVal, Integer minVal, Integer maxVal, Component comment) { this.defaultValue = defaultVal; this.initialValue = defaultVal; this.currentValue = defaultVal; this.minValue = minVal; this.maxValue = maxVal; this.name = name; this.comment = comment; } @Override public Integer get() { return currentValue; } @Override public Integer getDefault() { return defaultValue; } @Override public void set(Integer value) { this.currentValue = value; } @Override public boolean isValid(Integer value) { return value != null && value >= minValue && value <= maxValue; } @Override public boolean isDefault() { return Objects.equals(currentValue, defaultValue); } @Override public boolean isChanged() { return !Objects.equals(currentValue, initialValue); } @Override public void restore() { this.currentValue = defaultValue; } @Override public Component getComment() { return comment; } @Override public String getName() { return name; } @Override public Component getValidationHint() { return Component.literal( "Value must be between " + minValue + " and " + maxValue ); } @Override public boolean requiresWorldRestart() { return false; } @Override public boolean requiresGameRestart() { return false; } } ``` -------------------------------- ### Get Server-Side Configurations Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Retrieves all server-related configurations for a given mod, including SERVER, SERVER_SYNC, WORLD, and WORLD_SYNC types. Returns an empty set if none are found. ```java public Set getServerConfigs(String modId) { ModContext context = new ModContext(modId); Map> configs = ClientHandler.createConfigMap(context); Set serverConfigs = new HashSet<>(); serverConfigs.addAll(configs.getOrDefault(ConfigType.SERVER, new HashSet<>())); serverConfigs.addAll(configs.getOrDefault(ConfigType.SERVER_SYNC, new HashSet<>())); serverConfigs.addAll(configs.getOrDefault(ConfigType.WORLD, new HashSet<>())); serverConfigs.addAll(configs.getOrDefault(ConfigType.WORLD_SYNC, new HashSet<>())); return serverConfigs; } ``` -------------------------------- ### Get Registered Configuration Providers Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Returns the set of all registered configuration providers. This method automatically initializes the handler if it hasn't been already and returns a cached instance of the providers. ```java public static Set getProviders() ``` -------------------------------- ### Restricted GameMode Example Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/types.md Example demonstrating how to implement IAllowedEnums to restrict GameMode options. This ensures only specified enum values can be used. ```java public enum GameMode { SURVIVAL, CREATIVE, ADVENTURE, SPECTATOR } public class RestrictedGameMode implements IAllowedEnums { @Override public Set getAllowedValues() { return Set.of(GameMode.SURVIVAL, GameMode.CREATIVE); } } ``` -------------------------------- ### startEditing() Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md This method is called once when the player begins editing the configuration. It is intended for initialization tasks that need to be performed before editing commences. The default implementation does nothing. ```APIDOC ## startEditing() ### Description Called when the configuration begins being edited by the player. ### Notes Fired once when the config is first opened. Use for initialization tasks. ``` -------------------------------- ### Configuration Manager Initialization Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Shows how to initialize the configuration manager, noting that configuration is automatically loaded by Bootstrap and demonstrating how to log the config state. ```java public class ConfigurationManager { public static void initializeConfig() { // Configuration is automatically loaded by Bootstrap // This just shows how to access it logConfigState(); } public static void logConfigState() { System.out.println("=== Configured Mod Configuration ==="); System.out.println("Force Configured Menu: " + Config.isForceConfiguredMenu()); System.out.println("Include Folders in Search: " + Config.isIncludeFoldersInSearch()); System.out.println("Changed Value Formatting: " + Config.getChangedFormatting()); System.out.println("Developer Mode: " + Config.isDeveloperEnabled()); System.out.println("Broadcast Logs: " + Config.shouldBroadcastLogs()); System.out.println("Authorized Developers: " + Config.getDevelopers().size()); } } ``` -------------------------------- ### Get Name Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves the current entry name or key of this configuration value. ```java String getName() ``` -------------------------------- ### Open Config Selection Screen Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Initializes client handlers and opens the configuration selection screen for a given mod. Displays a message if no configurations are available. ```java public void openConfigScreen(String modId) { ClientHandler.init(); // Ensure providers are initialized ModContext context = new ModContext(modId); Map> configs = ClientHandler.createConfigMap(context); if (configs.isEmpty()) { Minecraft.getInstance().player.displayClientMessage( Component.literal("No configurations available"), false ); return; } Screen screen = ConfigScreenHelper.createSelectionScreen( Minecraft.getInstance().screen, Component.literal("Configuration"), configs ); Minecraft.getInstance().setScreen(screen); } ``` -------------------------------- ### Get Default Value Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves the default value as defined in the configuration specification. ```java T getDefault() ``` -------------------------------- ### Safely Open Config Screen with Error Handling Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Demonstrates how to safely open a configuration screen, including checks for config accessibility and player permissions. It also includes a fallback error message for unexpected exceptions. ```java public void safelyOpenConfigScreen(IModConfig config, Player player) { try { // Verify config is accessible if (config == null) { showError(player, "Config not found"); return; } // Check player permissions ActionResult permission = config.canPlayerEdit(player); if (!permission.asBoolean()) { showError(player, permission.message() .map(Component::getString) .orElse("No permission to edit config") ); return; } // Open screen Screen screen = ConfigScreenHelper.createSelectionScreen( Minecraft.getInstance().screen, Component.literal("Configuration"), config ); Minecraft.getInstance().setScreen(screen); } catch (Exception e) { showError(player, "Error opening config: " + e.getMessage()); Constants.LOG.error("Failed to open config screen", e); } } ``` ```java private void showError(Player player, String message) { player.displayClientMessage( Component.literal(message).withStyle(ChatFormatting.RED), false ); } ``` -------------------------------- ### Get Comment Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves an optional comment or description for this value, displayed as a tooltip in the configuration GUI. ```java @Nullable Component getComment() ``` -------------------------------- ### Bootstrap init() Method Signature Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Bootstrap.md The signature for the static init method, which is the main initialization entry point for the Configured mod. ```java public static void init() ``` -------------------------------- ### get() Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves the current value held by the IConfigValue. This value might be different from the default or persisted value. ```APIDOC ## get() ### Description Returns the currently held value. ### Method ```java T get() ``` ### Returns - The current value of type `T`. ### Throws - None ### Notes This value may differ from both the default and the persisted value. ``` -------------------------------- ### Get Translation Key Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves the translation key for localizing the value's display name, if available. ```java @Nullable String getTranslationKey() ``` -------------------------------- ### Restore Default Value Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Resets the current value to the default value, making get() equal to getDefault(). ```java void restore() ``` -------------------------------- ### Bootstrap init() Method Implementation Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Bootstrap.md The internal implementation of the init method. It loads the mod configuration by calling Config.load() with the platform's config path. This method handles the automatic creation of missing config files with default values. ```java public static void init() { Config.load(Services.PLATFORM.getConfigPath()); } ``` -------------------------------- ### Get Mod ID Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Returns the string mod ID associated with this configuration, identifying which mod it belongs to. ```java String getModId() ``` -------------------------------- ### Create Root Configuration Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Provides the entry point of the configuration tree, allowing traversal of the entire configuration structure. ```java IConfigEntry createRootEntry() ``` -------------------------------- ### Register Provider for Forge/NeoForge Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/integration-guide.md Add your configuration provider to the `configuredProviders` list in your `mods.toml` file for Forge or NeoForge. ```toml [[mods]] modId="mymod" displayName="My Mod" [modproperties.mymod] configuredProviders=["com.example.MyConfigProvider"] ``` -------------------------------- ### createRootEntry() Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Provides the entry point of the configuration tree for traversal and modification. ```APIDOC ## createRootEntry() ### Description Provides the entry point of the configuration tree for traversal. ### Method ```java IConfigEntry createRootEntry() ``` ### Returns - `IConfigEntry` - representing the root node of the config tree. ### Throws None ``` -------------------------------- ### Bootstrap.init() Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Bootstrap.md Initializes the Configured mod by loading configuration files. This method is called by the mod loader during the mod initialization phase. ```APIDOC ## Bootstrap.init() ### Description Main initialization entry point. Loads mod configuration from the config path. ### Method ```java public static void init() ``` ### Parameters None ### Called By Mod loader (Forge/Fabric/NeoForge) ### Side Effects Loads `configured-client.properties` (on client) or `configured-developer.properties` (on server) ### Internal Flow Example ```java public static void init() { Config.load(Services.PLATFORM.getConfigPath()); } ``` ### Related Classes - `Config` - Main configuration storage and accessors - `Services.PLATFORM` - Platform-specific service provider - `Constants` - Mod constants including logging ``` -------------------------------- ### Get Validation Hint Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves a hint to display when the value is invalid, shown to the user when isValid() returns false. ```java @Nullable Component getValidationHint() ``` -------------------------------- ### Get Authorized Developers List Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Retrieves an immutable list of UUIDs representing players authorized for developer access. ```java public static ImmutableList getDevelopers() ``` -------------------------------- ### ClientHandler.init() Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Initializes the client handler by discovering and caching all registered IModConfigProvider implementations. This method is called automatically on first use. ```APIDOC ## init() ### Description Initializes the client handler and loads all registered config providers. ### Method public static void init() ### Details - Discovers and caches all `IModConfigProvider` implementations. - Called automatically on first use. - Populates the internal providers cache. ``` -------------------------------- ### Load World Configuration from Path Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Loads a world configuration from the specified file path. This method may throw an IOException and fails by default. ```java default ActionResult loadWorldConfig(Path path) throws IOException { return ActionResult.fail(); } ``` -------------------------------- ### Create Multi-Config Selection Screen Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Use this method to create a screen that allows users to select from multiple configurations. It requires the parent screen, a title, and a map of configuration types to their associated configurations. ```java public static Screen createSelectionScreen( Screen parent, Component title, Map> configs) ``` -------------------------------- ### Implement IModConfig for Single Configuration File Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/integration-guide.md Represents a single configuration file and its settings. This implementation handles config type, file name, mod ID, root entry creation, updates, read-only status, default restoration, and player edit permissions. ```java import com.mrcrayfish.configured.api.*; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; public class MyModConfig implements IModConfig { private final MyConfigFile configFile; public MyModConfig(MyConfigFile configFile) { this.configFile = configFile; } @Override public ConfigType getType() { // Return appropriate type based on where config is stored return configFile.isWorldConfig() ? ConfigType.WORLD : ConfigType.CLIENT; } @Override public String getFileName() { return configFile.getFileName(); // e.g., "myconfig.json" } @Override public String getModId() { return configFile.getModId(); // e.g., "mymod" } @Override public IConfigEntry createRootEntry() { // Create root entry by parsing config structure return new MyRootEntry(configFile); } @Override public ActionResult update(IConfigEntry entry) { try { // Find all changed values Set> changedValues = getChangedValues(entry); if (changedValues.isEmpty()) { return ActionResult.success(); } // Apply changes to config changedValues.forEach(value -> { // Write value to your config system configFile.setValue(value.getName(), value.get()); }); // Save to disk configFile.save(); return ActionResult.success( Component.literal("Configuration saved") ); } catch (Exception e) { return ActionResult.fail( Component.literal("Failed to save: " + e.getMessage()) ); } } @Override public boolean isReadOnly() { return configFile.isReadOnly(); } @Override public Optional restoreDefaultsTask() { if (isReadOnly()) { return Optional.empty(); } return Optional.of(() -> { configFile.restoreDefaults(); try { configFile.save(); } catch (IOException e) { throw new RuntimeException(e); } }); } @Override public ActionResult canPlayerEdit(@Nullable Player player) { ExecutionContext context = new ExecutionContext(player); // Determine if player can edit based on config type if (context.isMainMenu()) { return ActionResult.success(); } if (context.isSingleplayer()) { return ActionResult.success(); } if (context.isPlayingOnRemoteServer() && context.isPlayerAnOperator()) { return ActionResult.success(); } return ActionResult.fail(Component.literal("No permission")); } } ``` -------------------------------- ### Open Config with Permission Check Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Opens a configuration screen only if the player has the necessary permissions to edit the configuration. It displays a message to the player if they lack permissions. ```java public void openConfigMenu(IModConfig config, Player player) { ExecutionContext context = new ExecutionContext(player); ActionResult canEdit = config.canPlayerEdit(player); if (!canEdit.asBoolean()) { player.displayClientMessage( Component.literal("Cannot edit this config"), false ); return; } Screen screen = ConfigScreenHelper.createSelectionScreen( Component.literal("Edit Configuration"), config ); Minecraft.getInstance().setScreen(screen); } ``` -------------------------------- ### Get Changed Formatting Setting Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Retrieves the `ChatFormatting` enum value used for text formatting of modified configuration values. ```java public static ChatFormatting getChangedFormatting() ``` -------------------------------- ### Get Display Name of Configuration Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigEntry.md Returns the user-facing display name for this configuration entry, used as a label in the GUI. ```java String getEntryName() ``` -------------------------------- ### ClientHandler.getProviders() Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Returns the set of all registered configuration providers. This method automatically initializes the handler if it hasn't been already. ```APIDOC ## getProviders() ### Description Returns the set of all registered configuration providers. ### Method public static Set getProviders() ### Returns - Set of all discovered `IModConfigProvider` instances. ### Notes - Automatically initializes if not already done. - Returns cached instance. ``` -------------------------------- ### Get Environment Restriction Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/types.md Retrieves the specific environment restriction for a ConfigType. Returns an empty Optional for types applicable to both client and server. ```java Optional getEnv() ``` -------------------------------- ### Open Multiple Configs Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Opens a selection screen for multiple configurations, grouped by ConfigType. This is useful when a mod manages configurations of different types (e.g., CLIENT, SERVER). ```java Map> configMap = new HashMap<>(); configMap.put(ConfigType.CLIENT, clientConfigs); configMap.put(ConfigType.SERVER, serverConfigs); Screen screen = ConfigScreenHelper.createSelectionScreen( previousScreen, Component.translatable("config.mymod.title"), configMap ); Minecraft.getInstance().setScreen(screen); ``` -------------------------------- ### Get Current Value Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigValue.md Retrieves the currently held value of type T. This value may differ from the default or persisted value. ```java T get() ``` -------------------------------- ### Get Configuration Type Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Returns the ConfigType enum value that determines where the configuration loads from and saves to (e.g., client, server, world). ```java ConfigType getType() ``` -------------------------------- ### Validate and Set Config Value Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/README.md Demonstrates how to validate a new value against a configuration entry's constraints before setting it. Provides feedback if the value is invalid. ```java IConfigValue brightness = (IConfigValue) value; int newBrightness = 150; if (brightness.isValid(newBrightness)) { brightness.set(newBrightness); } else { Component hint = brightness.getValidationHint(); System.err.println("Invalid: " + hint.getString()); } ``` -------------------------------- ### Get Translation Key for Configuration Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigEntry.md Returns the translation key used for localizing the entry's name in the GUI, if available. ```java @Nullable String getTranslationKey() ``` -------------------------------- ### Get Value of a Leaf Configuration Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigEntry.md Retrieves the configuration value holder for a leaf node. Returns null for branch nodes. ```java @Nullable IConfigValue getValue() ``` -------------------------------- ### Load Configuration Method Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Loads configuration settings from a specified file path. Creates missing files with default values. The specific file loaded depends on the environment (client or server). ```java public static void load(Path path) ``` -------------------------------- ### Get Children of a Configuration Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IConfigEntry.md Retrieves the immediate child entries of a configuration node. Returns an empty list for leaf nodes. ```java List getChildren() ``` -------------------------------- ### Key Binding for Mod List Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Sets up a key binding that, when pressed, opens the mod configuration screen. It checks for available configurations before opening the screen. ```java public class ConfigKeyHandler { public static void setupKeyBindings() { // Register the key binding ClientTickEvents.END_CLIENT_TICK.register(client -> { while (ClientHandler.KEY_OPEN_MOD_LIST.consumeClick()) { handleOpenModList(); } }); } private static void handleOpenModList() { // Open the mod configuration screen Minecraft minecraft = Minecraft.getInstance(); Screen currentScreen = minecraft.screen; // Get configs for current mod (example: focused mod) ModContext context = new ModContext("mymod"); Map> configs = ClientHandler.createConfigMap(context); if (!configs.isEmpty()) { Screen configScreen = ConfigScreenHelper.createSelectionScreen( currentScreen, Component.literal("Mod Configuration"), configs ); minecraft.setScreen(configScreen); } } } ``` -------------------------------- ### Open Config with Parent Screen Navigation Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Opens a configuration screen and ensures that the previous screen is automatically reopened when the configuration screen is closed. This is achieved by passing the current screen as the parent. ```java Screen parentScreen = Minecraft.getInstance().screen; Screen configScreen = ConfigScreenHelper.createSelectionScreen( parentScreen, Component.literal("Configuration"), config ); Minecraft.getInstance().setScreen(configScreen); // When player closes configScreen, parentScreen is automatically opened ``` -------------------------------- ### Load Configuration Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/Config.md Loads configuration settings from a specified file path. This method handles environment-specific configuration files (client or server) and creates default files if they don't exist. ```APIDOC ## load(Path path) ### Description Loads configuration from the specified path, creating default files if necessary. It selects the appropriate configuration file based on the environment (client or dedicated server). ### Method ```java public static void load(Path path) ``` ### Parameters #### Path Parameters - **path** (`Path`) - Required - The directory path where configuration files are located. ### Behavior - Creates missing config files with default values. - **CLIENT environment**: Loads `configured-client.properties`. - **DEDICATED_SERVER environment**: Loads `configured-developer.properties`. ``` -------------------------------- ### Get Total Config Count for Mod Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Calculates and returns the total number of configurations for a given mod by summing the sizes of all config sets. ```java public int getConfigCount(String modId) { ModContext context = new ModContext(modId); Map> configs = ClientHandler.createConfigMap(context); return configs.values() .stream() .mapToInt(Set::size) .sum(); } ``` -------------------------------- ### Get Translation Key for Configuration Name Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/IModConfig.md Retrieves the translation key used for localizing the configuration's display name. Returns null by default. ```java @Nullable default String getTranslationKey() { return null; } ``` -------------------------------- ### Create Multi-Mod Configuration Selection Screen Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md A helper method to create a unified configuration selection screen for multiple mods. It aggregates configurations from specified mod IDs. ```java public class MultiModConfigHelper { public static Screen createModConfigSelection(Screen parentScreen, String... modIds) { Map> allConfigs = new HashMap<>(); for (String modId : modIds) { ModContext context = new ModContext(modId); Map> modConfigs = ClientHandler.createConfigMap(context); // Merge into main map modConfigs.forEach((type, configs) -> { allConfigs.computeIfAbsent(type, k -> new LinkedHashSet<>()) .addAll(configs); }); } return ConfigScreenHelper.createSelectionScreen( parentScreen, Component.literal("Configuration Manager"), allConfigs ); } } ``` -------------------------------- ### Safely Get Configurations Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ClientHandler.md Handles potential exceptions during the process of retrieving and processing mod configurations. Logs errors if no config providers are registered or if loading fails. ```java public void safelyGetConfigs(String modId) { try { Set providers = ClientHandler.getProviders(); if (providers.isEmpty()) { Constants.LOG.warn("No config providers registered!"); return; } ModContext context = new ModContext(modId); Map> configs = ClientHandler.createConfigMap(context); for (Map.Entry> entry : configs.entrySet()) { System.out.println(entry.getKey() + ": " + entry.getValue().size() + " configs"); } } catch (Exception e) { Constants.LOG.error("Failed to load configs", e); } } ``` -------------------------------- ### Implement IModConfigProvider to Discover Configurations Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/integration-guide.md Implement this interface to allow Configured to discover all configurations for a given mod. Return an empty set if no configs exist, filter by the provided mod ID, and handle exceptions gracefully. ```java import com.mrcrayfish.configured.api.IModConfig; import com.mrcrayfish.configured.api.IModConfigProvider; import com.mrcrayfish.configured.api.ModContext; public class MyConfigProvider implements IModConfigProvider { @Override public Set getConfigurationsForMod(ModContext context) { // Get the mod ID String modId = context.modId(); // Load all configs for this mod from your system Set configs = new HashSet<>(); for (MyConfigFile file : MyConfigManager.getConfigFiles(modId)) { configs.add(new MyModConfig(file)); } return configs; } } ``` -------------------------------- ### Create Single Config Screen (Explicit Parent) Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Use this method to create a configuration screen for a single configuration with an explicitly defined parent screen. This is useful when you need precise control over the navigation flow. ```java public static Screen createSelectionScreen( Screen parent, Component title, IModConfig config) ``` -------------------------------- ### Open Single Config Screen Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/api-reference/ConfigScreenHelper.md Opens a configuration screen for a single mod's configuration. Ensure you have obtained the IModConfig instance for your mod. ```java IModConfig myConfig = getMyConfig(); Screen screen = ConfigScreenHelper.createSelectionScreen( Component.literal("My Mod Config"), myConfig ); Minecraft.getInstance().setScreen(screen); ``` -------------------------------- ### ExecutionContext Helper Methods Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/types.md Provides convenient methods to check the current execution environment, such as client/server status, player context, and game state. ```APIDOC ## ExecutionContext Helper Methods Helper methods to check the current execution environment. ### Methods - **isClient()** (`boolean`) - Running on Minecraft client - **isDedicatedServer()** (`boolean`) - Running on dedicated server - **isIntegratedServer()** (`boolean`) - Playing on integrated server - **isIntegratedServerOwnedByPlayer()** (`boolean`) - Current player owns the integrated server - **isSingleplayer()** (`boolean`) - Playing in singleplayer - **isPlayingOnLan()** (`boolean`) - Playing on LAN - **isMainMenu()** (`boolean`) - In main menu (no world loaded) - **isPlayingGame()** (`boolean`) - Game is active (world loaded) - **isPlayerAnOperator()** (`boolean`) - Player has operator privileges - **isDeveloperPlayer()** (`boolean`) - Player is in developer list - **isPlayingOnRemoteServer()** (`boolean`) - Connected to remote/dedicated server - **isConfiguredInstalledRemotely()** (`boolean`) - Configured mod installed on server - **isLocalPlayer()** (`boolean`) - Player is the local client player ### Usage Example ```java ExecutionContext context = new ExecutionContext(player); if (context.isSingleplayer()) { // Allow editing in singleplayer return ActionResult.success(); } else if (context.isPlayingOnRemoteServer() && context.isPlayerAnOperator()) { // Allow operators on remote servers return ActionResult.success(); } else { return ActionResult.fail(); } ``` ``` -------------------------------- ### Implement Folder Entry Source: https://github.com/mrcrayfish/configured/blob/multiloader/26.1.2/_autodocs/integration-guide.md Create a custom folder entry by extending IConfigEntry. This is used for grouping other configuration entries. ```java public class MyFolderEntry implements IConfigEntry { private final String name; private final List children; private final String translationKey; public MyFolderEntry(String name, List children) { this.name = name; this.children = children; this.translationKey = "config.mymod." + name; } @Override public List getChildren() { return new ArrayList<>(children); } @Override public boolean isRoot() { return false; } @Override public boolean isLeaf() { return false; } @Override public IConfigValue getValue() { return null; // Folders don't have values } @Override public String getEntryName() { return name; } @Override public Component getTooltip() { return null; } @Override public String getTranslationKey() { return translationKey; } } ```