Skip to content

refactor: configuration (again)#13

Merged
5w14 merged 2 commits into
developmentfrom
dev/config-refactor-AGAIN
Jul 16, 2025
Merged

refactor: configuration (again)#13
5w14 merged 2 commits into
developmentfrom
dev/config-refactor-AGAIN

Conversation

@5w14
Copy link
Copy Markdown
Owner

@5w14 5w14 commented Jul 16, 2025

No description provided.

@5w14 5w14 changed the base branch from master to development July 16, 2025 17:19
@5w14 5w14 requested a review from Copilot July 16, 2025 20:00
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 static Config methods.
  • Added ConfigLoader to handle loading and saving the on-disk JSON configuration.
  • Reworked Config into a dynamic, field-based structure and updated initialization in E418.

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);
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
v.deserializeFromMapAndUpdate(object)).anyMatch(v -> !v);
v.deserializeFromMapAndUpdate(object)).allMatch(v -> v);

Copilot uses AI. Check for mistakes.

var result = Config.deserializeConfig(configJson.getAsJsonObject());
if (!result) {
LOGGER.warn("Error while config deserizalization!");
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spelling in log message: 'deserizalization' should be 'deserialization'.

Suggested change
LOGGER.warn("Error while config deserizalization!");
LOGGER.warn("Error while config deserialization!");

Copilot uses AI. Check for mistakes.
ResourceLocation.fromNamespaceAndPath(E418.MOD_ID, "unlabirynth")
), Optional.of(Map.of()));
/**
* Serialzies a config into a JSON object.
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct spelling in Javadoc: 'Serialzies' should be 'Serializes'.

Suggested change
* Serialzies a config into a JSON object.
* Serializes a config into a JSON object.

Copilot uses AI. Check for mistakes.
@@ -6,19 +6,17 @@
import net.minecraft.server.level.ServerPlayer;
import org.slf4j.Logger;
import ru.maxthetomas.e418.E418;
Copy link

Copilot AI Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import 'E418' is unused and can be removed to clean up dependencies.

Suggested change
import ru.maxthetomas.e418.E418;

Copilot uses AI. Check for mistakes.
@illersaver illersaver marked this pull request as ready for review July 16, 2025 20:02
@CaptainSqrBeard CaptainSqrBeard marked this pull request as draft July 16, 2025 20:03
@5w14 5w14 marked this pull request as ready for review July 16, 2025 20:07
@5w14 5w14 merged commit dde9c1e into development Jul 16, 2025
@5w14 5w14 deleted the dev/config-refactor-AGAIN branch July 16, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants