Skip to content

Commit

Permalink
Replaced ForgeConfigApiPort with PortingLib config module
Browse files Browse the repository at this point in the history
  • Loading branch information
shurik204 committed Jan 27, 2024
1 parent a36ae2f commit f6a6e32
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {

modRuntimeOnly("me.shedaniel:RoughlyEnoughItems-fabric:${property("rei_version")}")
// Forge Config API port
modImplementation(include("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:8.0.0")) {}
modRuntimeOnly(include("fuzs.forgeconfigapiport:forgeconfigapiport-fabric:${property("forge_cfg_version")}")) {}

modImplementation("icyllis.modernui:ModernUI-Core:${property("modernui_core_version")}") {
exclude("org.apache.logging.log4j", "log4j-core")
Expand Down Expand Up @@ -103,7 +103,7 @@ dependencies {
modImplementation(include("me.shurik:simple-chunk-manager:0.2.7")) {}

modImplementation(include("io.github.fabricators_of_create.Porting-Lib:base:${property("porting_lib_version")}")) {}
modImplementation(include("io.github.fabricators_of_create.Porting-Lib:models:${property("porting_lib_version")}")) {}
modImplementation(include("io.github.fabricators_of_create.Porting-Lib:config:${property("porting_lib_version")}")) {}

// modImplementation "curse.maven:gregtechceu-modern-890405:${gtceu_file_id}"

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ trinkets_version = 3.7.0
# for Trinkets - https://modrinth.com/mod/cardinal-components-api/versions
cca_version = 5.2.1

forge_cfg_version=8.0.0

# https://www.curseforge.com/minecraft/mc-mods/jade/files
jade_file_id = 4973433
gtceu_file_id = 5000339
Expand Down
69 changes: 34 additions & 35 deletions src/main/java/sonar/fluxnetworks/FluxConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package sonar.fluxnetworks;

import com.google.common.collect.Lists;
import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry;
import fuzs.forgeconfigapiport.api.config.v2.ModConfigEvents;
import io.github.fabricators_of_create.porting_lib.config.*;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.config.IConfigSpec;
import net.minecraftforge.fml.config.ModConfig;
import sonar.fluxnetworks.common.util.EnergyUtils;

import javax.annotation.Nonnull;
Expand All @@ -17,47 +13,51 @@
public class FluxConfig {

private static final Client CLIENT_CONFIG;
private static final ForgeConfigSpec CLIENT_SPEC;
private static final ModConfigSpec CLIENT_SPEC;

private static final Common COMMON_CONFIG;
private static final ForgeConfigSpec COMMON_SPEC;
private static final ModConfigSpec COMMON_SPEC;

private static final Server SERVER_CONFIG;
private static final ForgeConfigSpec SERVER_SPEC;
private static final ModConfigSpec SERVER_SPEC;

static {
ForgeConfigSpec.Builder builder;
ModConfigSpec.Builder builder;

if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
builder = new ForgeConfigSpec.Builder();
builder = new ModConfigSpec.Builder();
CLIENT_CONFIG = new Client(builder);
CLIENT_SPEC = builder.build();
} else {
CLIENT_CONFIG = null;
CLIENT_SPEC = null;
}

builder = new ForgeConfigSpec.Builder();
builder = new ModConfigSpec.Builder();
COMMON_CONFIG = new Common(builder);
COMMON_SPEC = builder.build();

builder = new ForgeConfigSpec.Builder();
builder = new ModConfigSpec.Builder();
SERVER_CONFIG = new Server(builder);
SERVER_SPEC = builder.build();
}

static void init() {
ModConfigEvents.reloading(FluxNetworks.MODID).register(FluxConfig::reload);
ConfigEvents.RELOADING.register(FluxConfig::reload);

if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
ForgeConfigRegistry.INSTANCE.register(FluxNetworks.MODID, ModConfig.Type.CLIENT, CLIENT_SPEC);
ConfigRegistry.registerConfig(FluxNetworks.MODID, ConfigType.CLIENT, CLIENT_SPEC);
}
ForgeConfigRegistry.INSTANCE.register(FluxNetworks.MODID, ModConfig.Type.COMMON, COMMON_SPEC);
ForgeConfigRegistry.INSTANCE.register(FluxNetworks.MODID, ModConfig.Type.SERVER, SERVER_SPEC);
ConfigRegistry.registerConfig(FluxNetworks.MODID, ConfigType.COMMON, COMMON_SPEC);
ConfigRegistry.registerConfig(FluxNetworks.MODID, ConfigType.SERVER, SERVER_SPEC);
}

static void reload(@Nonnull ModConfig config) {
final IConfigSpec<?> spec = config.getSpec();
if (config.getModId() != FluxNetworks.MODID) {
return;
}

final ModConfigSpec spec = config.getSpec();
if (spec == CLIENT_SPEC) {
CLIENT_CONFIG.load();
FluxNetworks.LOGGER.debug("Client config loaded");
Expand All @@ -81,10 +81,10 @@ static void reload(@Nonnull ModConfig config) {
@Environment(EnvType.CLIENT)
private static class Client {

private final ForgeConfigSpec.BooleanValue mEnableButtonSound;
private final ForgeConfigSpec.BooleanValue mEnableGuiDebug;
private final ModConfigSpec.BooleanValue mEnableButtonSound;
private final ModConfigSpec.BooleanValue mEnableGuiDebug;

private Client(@Nonnull ForgeConfigSpec.Builder builder) {
private Client(@Nonnull ModConfigSpec.Builder builder) {
builder.push("gui");
mEnableButtonSound = builder
.comment("Enable navigation buttons sound when pressing it")
Expand All @@ -105,16 +105,15 @@ private void load() {

private static class Common {

private final ForgeConfigSpec.BooleanValue
private final ModConfigSpec.BooleanValue
mEnableJadeBasicInfo,
mEnableJadeAdvancedInfo,
mEnableJadeSneaking;

// private final ForgeConfigSpec.BooleanValue mEnableGTCEU;
// private final ModConfigSpec.BooleanValue mEnableGTCEU;

private Common(@Nonnull ForgeConfigSpec.Builder builder) {
builder.comment("Most configs are moved to /serverconfig/fluxnetworks-server.toml",
"Copy to /defaultconfig/fluxnetworks-server.toml for modpacks")
private Common(@Nonnull ModConfigSpec.Builder builder) {
builder.comment("Most configs are moved to /serverconfig/fluxnetworks-server.toml")
.define("placeholder", true);

builder.comment("Jade")
Expand All @@ -128,7 +127,7 @@ private Common(@Nonnull ForgeConfigSpec.Builder builder) {
.translation(FluxNetworks.MODID + ".config." + "enableJadeAdvancedInfo")
.define("enableJadeAdvancedInfo", true);
mEnableJadeSneaking = builder
.comment("Displays Advanced Info when sneaking only")
.comment("Display Advanced Info only when sneaking")
.translation(FluxNetworks.MODID + ".config." + "enableJadeSneaking")
.define("enableJadeSneaking", true);

Expand Down Expand Up @@ -158,23 +157,23 @@ private void load() {
private static class Server {

// networks
private final ForgeConfigSpec.IntValue mMaximumPerPlayer;
private final ForgeConfigSpec.IntValue mSuperAdminRequiredPermission;
private final ForgeConfigSpec.BooleanValue mEnableSuperAdmin;
private final ModConfigSpec.IntValue mMaximumPerPlayer;
private final ModConfigSpec.IntValue mSuperAdminRequiredPermission;
private final ModConfigSpec.BooleanValue mEnableSuperAdmin;

// general
private final ForgeConfigSpec.BooleanValue mEnableFluxRecipe;
private final ForgeConfigSpec.BooleanValue mEnableChunkLoading;
//private final ForgeConfigSpec.BooleanValue mChunkLoadingRequiresSuperAdmin;
private final ModConfigSpec.BooleanValue mEnableFluxRecipe;
private final ModConfigSpec.BooleanValue mEnableChunkLoading;
//private final ModConfigSpec.BooleanValue mChunkLoadingRequiresSuperAdmin;

// blacklist
private final ForgeConfigSpec.ConfigValue<List<String>> mBlockBlacklistStrings, mItemBlackListStrings;
private final ModConfigSpec.ConfigValue<List<String>> mBlockBlacklistStrings, mItemBlackListStrings;

// energy
private final ForgeConfigSpec.LongValue mDefaultLimit, mBasicCapacity, mBasicTransfer, mHerculeanCapacity,
private final ModConfigSpec.LongValue mDefaultLimit, mBasicCapacity, mBasicTransfer, mHerculeanCapacity,
mHerculeanTransfer, mGargantuanCapacity, mGargantuanTransfer;

private Server(@Nonnull ForgeConfigSpec.Builder builder) {
private Server(@Nonnull ModConfigSpec.Builder builder) {
builder.push("networks");
mMaximumPerPlayer = builder
.comment("Maximum networks each player can have. Super admin can bypass this limit. -1 = no limit",
Expand Down

0 comments on commit f6a6e32

Please sign in to comment.