Skip to content

Commit

Permalink
Register serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBunnyDc committed Sep 22, 2024
1 parent b8bbad3 commit 1f69915
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
22 changes: 21 additions & 1 deletion XPlat/src/main/java/de/wonejo/wuidebook/WuidebookCommonMod.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package de.wonejo.wuidebook;

import de.wonejo.wuidebook.api.compat.WuidebookImplementation;
import de.wonejo.wuidebook.api.config.ConfigFile;
import de.wonejo.wuidebook.api.config.ConfigManager;
import de.wonejo.wuidebook.api.util.Constants;
import de.wonejo.wuidebook.api.util.McEnvironment;
import de.wonejo.wuidebook.impl.config.serializer.*;
import de.wonejo.wuidebook.impl.config.serializer.color.ColorConfigSerializer;
import de.wonejo.wuidebook.impl.service.ModServices;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -15,7 +21,7 @@ public class WuidebookCommonMod {
private static final Logger LOGGER = LogManager.getLogger();
private static final WuidebookCommonMod INSTANCE = new WuidebookCommonMod();
private static Path CONFIG_DIRECTORY = ModServices.ABSTRACTION.getConfigPath();

private final ConfigManager configManager = ConfigManager.get();

private WuidebookCommonMod () {}

Expand All @@ -34,6 +40,20 @@ public void setup () {
}

private void setupConfigAPI (@NotNull List<WuidebookImplementation> pImplementation) {
this.configManager.registerSerializer(Constants.CFG_STR_SERIALIZER, new StringCfgSerializer());
this.configManager.registerSerializer(Constants.CFG_INT_SERIALIZER, new IntCfgSerializer());
this.configManager.registerSerializer(Constants.CFG_FLOAT_SERIALIZER, new FloatCfgSerializer());
this.configManager.registerSerializer(Constants.CFG_DOUBLE_SERIALIZER, new DoubleCfgSerializer());
this.configManager.registerSerializer(Constants.CFG_BOOL_SERIALIZER, new BooleanCfgSerializer());
this.configManager.registerSerializer(Constants.CFG_LIST_SERIALIZER, new ListCfgSerializer<>());
this.configManager.registerSerializer(Constants.CFG_COLOR_SERIALIZER, new ColorConfigSerializer());

for ( WuidebookImplementation impl : pImplementation ) {
impl.onRegisterConfigSerializer(this.configManager);
impl.onRegisterConfigFiles(this.configManager);
}

this.configManager.getFileList(McEnvironment.COMMON).forEach(ConfigFile::loadFile);
}

public static Path getConfigDirectory() {
Expand Down
11 changes: 11 additions & 0 deletions XPlat/src/main/java/de/wonejo/wuidebook/api/util/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package de.wonejo.wuidebook.api.util;

import net.minecraft.resources.ResourceLocation;

public class Constants {
public static final String MOD_ID = "wuidebook";

public static final ResourceLocation CFG_STR_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_str_cfg");
public static final ResourceLocation CFG_INT_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_int_cfg");
public static final ResourceLocation CFG_FLOAT_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_float_cfg");
public static final ResourceLocation CFG_DOUBLE_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_double_cfg");
public static final ResourceLocation CFG_BOOL_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_bool_cfg");
public static final ResourceLocation CFG_LIST_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_list_cfg");
public static final ResourceLocation CFG_COLOR_SERIALIZER = ResourceLocationUtils.wuidebook("wuidebook_color_cfg");

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package de.wonejo.wuidebook.api.util;

import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;

public class ResourceLocationUtils {

@NotNull
public static ResourceLocation minecraft (String pPath) {
return ResourceLocation.withDefaultNamespace(pPath);
}

@NotNull
public static ResourceLocation wuidebook ( String pPath ) {
return ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, pPath);
}

@NotNull
public static ResourceLocation common ( String pPath ) {
return ResourceLocation.fromNamespaceAndPath("c", pPath);
}

}

0 comments on commit 1f69915

Please sign in to comment.