refactor: configuration (again)#13
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the configuration system by migrating all E418.getConfig() calls to the new static Config API, introduces a ConfigLoader for reading and writing the JSON config, and removes the old ModConfig instance from E418.
- Replaced all mixin and core usage of
E418.getConfig()with staticConfigmethods. - Added
ConfigLoaderto handle loading and saving the on-disk JSON configuration. - Reworked
Configinto a dynamic, field-based structure and updated initialization inE418.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| common/src/main/java/ru/maxthetomas/e418/mixin/common/StructureManagerMixin.java | Switched isEmptyWorld calls to Config.isEmptyWorld |
| common/src/main/java/ru/maxthetomas/e418/mixin/common/ServerLevelMixin.java | Updated spawn logic to use Config.isEmptyWorld |
| common/src/main/java/ru/maxthetomas/e418/mixin/common/EntityMixin.java | Use Config.isEmptyWorld in entity tick removal |
| common/src/main/java/ru/maxthetomas/e418/mixin/client/WorldOpenFlowsMixin.java | Use Config.shouldSkipBackupScreen instead of old config call |
| common/src/main/java/ru/maxthetomas/e418/mixin/client/GameRendererMixin.java | Switched debug check to Config.isDebug |
| common/src/main/java/ru/maxthetomas/e418/mixin/client/DebugScreenOverlayMixin.java | Updated debug overlay logic to use Config.isDebug |
| common/src/main/java/ru/maxthetomas/e418/mixin/client/CreateWorldScreenMixin.java | Replaced E418.getConfig().shouldSkipBackupScreen with Config |
| common/src/main/java/ru/maxthetomas/e418/event/engine/RandomEventManager.java | Cleaned up imports and indentation; removed unused Config import |
| common/src/main/java/ru/maxthetomas/e418/config/ConfigLoader.java | New loader to read/write the e418.json configuration |
| common/src/main/java/ru/maxthetomas/e418/config/Config.java | Replaced old codec with dynamic field registry and static getters |
| common/src/main/java/ru/maxthetomas/e418/condition/Conditions.java | Updated debug condition registration to use Config.isDebug |
| common/src/main/java/ru/maxthetomas/e418/behaviour/impl/ExecuteCommandBehaviour.java | Changed debug check to Config.isDebug before suppressing output |
| common/src/main/java/ru/maxthetomas/e418/E418.java | Initialize config via ConfigLoader and remove old ModConfig |
Comments suppressed due to low confidence (2)
common/src/main/java/ru/maxthetomas/e418/config/Config.java:24
- [nitpick] The field name 'shouldSkipDebugScreen' (skip_debug_screen) and the method 'shouldSkipBackupScreen' use different terminology (debug vs backup). Consider renaming one for consistency and clarity.
public static Value<Boolean> shouldSkipDebugScreen = field("skip_debug_screen", Codec.BOOL, true);
common/src/main/java/ru/maxthetomas/e418/config/ConfigLoader.java:19
- Consider adding unit tests for ConfigLoader.loadConfig and Config.serializeConfig/deserializeConfig to verify correct handling of valid, invalid, and missing configuration files.
public static void loadConfig() {
| } | ||
| public static boolean deserializeConfig(JsonObject object) { | ||
| return CONFIG_VALUES.stream().map(v -> | ||
| v.deserializeFromMapAndUpdate(object)).anyMatch(v -> !v); |
There was a problem hiding this comment.
The logic in deserializeConfig is inverted: anyMatch(v -> !v) returns true if any deserialization failed, but the caller treats true as success. Consider using allMatch(v -> v) or negating the result to correctly reflect overall success.
| v.deserializeFromMapAndUpdate(object)).anyMatch(v -> !v); | |
| v.deserializeFromMapAndUpdate(object)).allMatch(v -> v); |
|
|
||
| var result = Config.deserializeConfig(configJson.getAsJsonObject()); | ||
| if (!result) { | ||
| LOGGER.warn("Error while config deserizalization!"); |
There was a problem hiding this comment.
Fix spelling in log message: 'deserizalization' should be 'deserialization'.
| LOGGER.warn("Error while config deserizalization!"); | |
| LOGGER.warn("Error while config deserialization!"); |
| ResourceLocation.fromNamespaceAndPath(E418.MOD_ID, "unlabirynth") | ||
| ), Optional.of(Map.of())); | ||
| /** | ||
| * Serialzies a config into a JSON object. |
There was a problem hiding this comment.
Correct spelling in Javadoc: 'Serialzies' should be 'Serializes'.
| * Serialzies a config into a JSON object. | |
| * Serializes a config into a JSON object. |
| @@ -6,19 +6,17 @@ | |||
| import net.minecraft.server.level.ServerPlayer; | |||
| import org.slf4j.Logger; | |||
| import ru.maxthetomas.e418.E418; | |||
There was a problem hiding this comment.
This import 'E418' is unused and can be removed to clean up dependencies.
| import ru.maxthetomas.e418.E418; |
No description provided.