diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/config/CommonModConfig.java b/common/src/main/java/dev/ithundxr/createnumismatics/config/CClient.java
similarity index 54%
rename from common/src/main/java/dev/ithundxr/createnumismatics/config/CommonModConfig.java
rename to common/src/main/java/dev/ithundxr/createnumismatics/config/CClient.java
index d280e537..b467d8a8 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/config/CommonModConfig.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/config/CClient.java
@@ -18,15 +18,21 @@
package dev.ithundxr.createnumismatics.config;
-import dev.ithundxr.createnumismatics.content.backend.Coin;
+import com.simibubi.create.foundation.config.ConfigBase;
-public class CommonModConfig {
- public static int starterSpur = 0;
- public static int starterBevel = 0;
- public static int starterSprocket = 0;
- public static int starterCog = 0;
- public static int starterCrown = 0;
- public static int starterSun = 0;
+@SuppressWarnings("unused")
+public class CClient extends ConfigBase {
- public static Coin currency = null;
+ public final ConfigGroup client = group(0, "client", Comments.client);
+
+ // Based off of https://github.com/Layers-of-Railways/Railway/blob/68713f0fbb20080b7e207c070b1595bdbbc1bc00/common/src/main/java/com/railwayteam/railways/config/CClient.java
+
+ @Override
+ public String getName() {
+ return "client";
+ }
+
+ private static class Comments {
+ static final String client = "Client-only settings - If you're looking for general settings, look inside your worlds serverconfig folder!";
+ }
}
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/config/CCommon.java b/common/src/main/java/dev/ithundxr/createnumismatics/config/CCommon.java
new file mode 100644
index 00000000..0c233ff5
--- /dev/null
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/config/CCommon.java
@@ -0,0 +1,43 @@
+/*
+ * Numismatics
+ * Copyright (c) 2024 The Railways Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package dev.ithundxr.createnumismatics.config;
+
+import com.simibubi.create.foundation.config.ConfigBase;
+import dev.ithundxr.createnumismatics.content.backend.Coin;
+
+@SuppressWarnings("unused")
+public class CCommon extends ConfigBase {
+
+ public final ConfigGroup coins = group(0, "coins", Comments.coins);
+
+ public final ConfigEnum defaultCoin = e(Coin.SPUR, "defaultCoin", Comments.defaultCoin);
+
+ // Based off of https://github.com/Layers-of-Railways/Railway/blob/68713f0fbb20080b7e207c070b1595bdbbc1bc00/common/src/main/java/com/railwayteam/railways/config/CCommon.java
+
+ @Override
+ public String getName() {
+ return "common";
+ }
+
+ private static class Comments {
+ static final String coins = "Coin settings";
+
+ static final String defaultCoin = "The default coin to be used in UI related displays";
+ }
+}
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/config/CServer.java b/common/src/main/java/dev/ithundxr/createnumismatics/config/CServer.java
new file mode 100644
index 00000000..afd3d75a
--- /dev/null
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/config/CServer.java
@@ -0,0 +1,55 @@
+/*
+ * Numismatics
+ * Copyright (c) 2024 The Railways Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package dev.ithundxr.createnumismatics.config;
+
+import com.simibubi.create.foundation.config.ConfigBase;
+import dev.ithundxr.createnumismatics.content.backend.Coin;
+
+@SuppressWarnings("unused")
+public class CServer extends ConfigBase {
+
+ public final ConfigGroup coins = group(0, "coins", Comments.coins);
+
+ public final ConfigGroup starter_currency = group(1, "starter_currency", Comments.starterMoney);
+
+ public final ConfigInt starter_spurs = i(0, 0, "starter_spurs");
+ public final ConfigInt starter_bevels = i(0, 0, "starter_bevels");
+ public final ConfigInt starter_sprockets = i(0, 0, "starter_sprockets");
+ public final ConfigInt starter_cogs = i(0, 0, "starter_cogs");
+ public final ConfigInt starter_crowns = i(0, 0, "starter_crowns");
+ public final ConfigInt starter_suns = i(0, 0, "starter_suns");
+
+
+ //public final ConfigGroup misc = group(0, "misc", Comments.misc);
+
+ // Based off of https://github.com/Layers-of-Railways/Railway/blob/68713f0fbb20080b7e207c070b1595bdbbc1bc00/common/src/main/java/com/railwayteam/railways/config/CServer.java
+
+ @Override
+ public String getName() {
+ return "server";
+ }
+
+ private static class Comments {
+ static final String coins = "Coin settings";
+
+ static final String starterMoney = "How much of this coin type should players receive in their bank account on first join";;
+
+ static final String misc = "Miscellaneous settings";
+ }
+}
\ No newline at end of file
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/config/NumismaticsConfig.java b/common/src/main/java/dev/ithundxr/createnumismatics/config/NumismaticsConfig.java
new file mode 100644
index 00000000..55d9ad13
--- /dev/null
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/config/NumismaticsConfig.java
@@ -0,0 +1,140 @@
+/*
+ * Numismatics
+ * Copyright (c) 2024 The Railways Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package dev.ithundxr.createnumismatics.config;
+
+import com.simibubi.create.foundation.config.ConfigBase;
+import net.minecraftforge.common.ForgeConfigSpec;
+import net.minecraftforge.fml.config.ModConfig;
+import org.apache.commons.lang3.NotImplementedException;
+import org.apache.commons.lang3.tuple.Pair;
+import org.jetbrains.annotations.ApiStatus;
+
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Supplier;
+
+@SuppressWarnings("unused")
+public class NumismaticsConfig {
+ @ApiStatus.Internal
+ public static final Map CONFIGS = new EnumMap<>(ModConfig.Type.class);
+
+ //private static CClient client;
+ private static CCommon common;
+ private static CServer server;
+
+// public static CClient client() {
+// return client;
+// }
+
+ public static CCommon common() {
+ return common;
+ }
+
+ public static CServer server() {
+ return server;
+ }
+
+ public static ConfigBase byType(ModConfig.Type type) {
+ return CONFIGS.get(type);
+ }
+
+ private static T register(Supplier factory, ModConfig.Type side) {
+ Pair specPair = new ForgeConfigSpec.Builder().configure(builder -> {
+ T config = factory.get();
+ config.registerAll(builder);
+ return config;
+ });
+
+ T config = specPair.getLeft();
+ config.specification = specPair.getRight();
+ CONFIGS.put(side, config);
+ return config;
+ }
+
+ @ApiStatus.Internal
+ public static void registerCommon() {
+ //client = register(CClient::new, ModConfig.Type.CLIENT);
+ common = register(CCommon::new, ModConfig.Type.COMMON);
+ server = register(CServer::new, ModConfig.Type.SERVER);
+ }
+
+ public static void onLoad(ModConfig modConfig) {
+ for (ConfigBase config : CONFIGS.values())
+ if (config.specification == modConfig
+ .getSpec())
+ config.onLoad();
+ }
+
+ public static void onReload(ModConfig modConfig) {
+ for (ConfigBase config : CONFIGS.values())
+ if (config.specification == modConfig
+ .getSpec())
+ config.onReload();
+ }
+
+ private static class TomlGroup {
+ private final Map subgroups = new HashMap<>();
+ private final Map entries = new HashMap<>();
+ private final String path;
+
+ private static TomlGroup root() {
+ return new TomlGroup("");
+ }
+
+ private TomlGroup(String path) {
+ this.path = path;
+ }
+
+ public boolean isRoot() {
+ return path.isEmpty();
+ }
+
+ public void add(String key, String value) {
+ if (!isRoot())
+ throw new NotImplementedException();
+
+ String[] pieces = key.split("\\.");
+ String subKey = pieces[pieces.length - 1];
+ TomlGroup targetedGroup = this;
+ for (int i = 0; i < pieces.length - 1; i++) {
+ targetedGroup = targetedGroup.getOrCreateSubGroup(pieces[i]);
+ }
+ targetedGroup.entries.put(subKey, value);
+ }
+
+ private TomlGroup getOrCreateSubGroup(String subKey) {
+ return subgroups.computeIfAbsent(subKey, (sk) -> new TomlGroup(path.isEmpty() ? sk : path + "." + sk));
+ }
+
+ private void write(StringBuilder b) {
+ if (!isRoot()) {
+ b.append("\n[").append(path).append("]");
+ }
+
+ for (Map.Entry entry : entries.entrySet()) {
+ b.append("\n").append(entry.getKey()).append(" = ").append(entry.getValue());
+ }
+
+ for (TomlGroup subGroup : subgroups.values()) {
+ subGroup.write(b);
+ }
+ }
+ }
+}
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/Coin.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/Coin.java
index d916bc6a..5a67ba56 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/Coin.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/Coin.java
@@ -23,7 +23,7 @@
import com.simibubi.create.foundation.gui.AllIcons;
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Couple;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.registry.NumismaticsIcons;
import dev.ithundxr.createnumismatics.registry.NumismaticsItems;
import dev.ithundxr.createnumismatics.util.TextUtils;
@@ -130,8 +130,7 @@ public String getTranslationKey() {
}
public Coin getDescription() {
- if (CommonModConfig.currency == null) return SPUR;
- return this.value < CommonModConfig.currency.value ? SPUR : CommonModConfig.currency;
+ return this.value < NumismaticsConfig.common().defaultCoin.get().value ? SPUR : NumismaticsConfig.common().defaultCoin.get();
}
public ItemStack asStack() {
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/GlobalBankManager.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/GlobalBankManager.java
index 4cf34d14..dfb6b6e8 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/GlobalBankManager.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/backend/GlobalBankManager.java
@@ -19,7 +19,7 @@
package dev.ithundxr.createnumismatics.content.backend;
import dev.ithundxr.createnumismatics.Numismatics;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.BankAccount.Type;
import dev.ithundxr.createnumismatics.util.Utils;
import net.minecraft.server.MinecraftServer;
@@ -101,12 +101,12 @@ public BankAccount getOrCreateAccount(@NotNull UUID uuid, Type type) {
BankAccount account = new BankAccount(uuid, type);
if (type == Type.PLAYER) {
- account.deposit(Coin.SPUR, CommonModConfig.starterSpur);
- account.deposit(Coin.BEVEL, CommonModConfig.starterBevel);
- account.deposit(Coin.SPROCKET, CommonModConfig.starterSprocket);
- account.deposit(Coin.COG, CommonModConfig.starterCog);
- account.deposit(Coin.CROWN, CommonModConfig.starterCrown);
- account.deposit(Coin.SUN, CommonModConfig.starterSun);
+ account.deposit(Coin.SPUR, NumismaticsConfig.server().starter_spurs.get());
+ account.deposit(Coin.BEVEL, NumismaticsConfig.server().starter_bevels.get());
+ account.deposit(Coin.SPROCKET, NumismaticsConfig.server().starter_sprockets.get());
+ account.deposit(Coin.COG, NumismaticsConfig.server().starter_cogs.get());
+ account.deposit(Coin.CROWN, NumismaticsConfig.server().starter_crowns.get());
+ account.deposit(Coin.SUN, NumismaticsConfig.server().starter_suns.get());
}
accounts.put(uuid, account);
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/bank/BankScreen.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/bank/BankScreen.java
index 5dd52622..b68a18a9 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/bank/BankScreen.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/bank/BankScreen.java
@@ -27,7 +27,7 @@
import com.simibubi.create.foundation.gui.widget.IconButton;
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Couple;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.registry.NumismaticsBlocks;
import dev.ithundxr.createnumismatics.registry.NumismaticsGuiTextures;
@@ -94,11 +94,11 @@ protected void renderBg(@NotNull GuiGraphics graphics, float partialTick, int mo
graphics.drawCenteredString(font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF);
- Couple cogsAndSpurs = CommonModConfig.currency.convert(menu.contentHolder.getBalance());
+ Couple cogsAndSpurs = NumismaticsConfig.common().defaultCoin.get().convert(menu.contentHolder.getBalance());
int cogs = cogsAndSpurs.getFirst();
int spurs = cogsAndSpurs.getSecond();
Component balanceLabel = Components.translatable("gui.numismatics.bank_terminal.balance",
- TextUtils.formatInt(cogs), CommonModConfig.currency.getName(cogs), spurs);
+ TextUtils.formatInt(cogs), NumismaticsConfig.common().defaultCoin.get().getName(cogs), spurs);
graphics.drawCenteredString(font, balanceLabel, x + (background.width - 8) / 2, y + 21, 0xFFFFFF);
}
}
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorBlockEntity.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorBlockEntity.java
index 55a9aefd..69a8a081 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorBlockEntity.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorBlockEntity.java
@@ -24,7 +24,7 @@
import com.simibubi.create.foundation.utility.Couple;
import com.simibubi.create.foundation.utility.Lang;
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.content.backend.behaviours.SliderStylePriceBehaviour;
import dev.ithundxr.createnumismatics.content.backend.trust_list.TrustListMenu;
@@ -107,11 +107,11 @@ public void addCoins(int totalPrice) {
@Override
public boolean addToTooltip(List tooltip, boolean isPlayerSneaking) {
- Couple cogsAndSpurs = CommonModConfig.currency.convert(price.getTotalPrice());
+ Couple cogsAndSpurs = NumismaticsConfig.common().defaultCoin.get().convert(price.getTotalPrice());
int cogs = cogsAndSpurs.getFirst();
int spurs = cogsAndSpurs.getSecond();
MutableComponent balanceLabel = Components.translatable("block.numismatics.brass_depositor.tooltip.price",
- TextUtils.formatInt(cogs), CommonModConfig.currency.getName(cogs), spurs);
+ TextUtils.formatInt(cogs), NumismaticsConfig.common().defaultCoin.get().getName(cogs), spurs);
Lang.builder()
.add(balanceLabel.withStyle(Coin.closest(price.getTotalPrice()).rarity.color))
.forGoggles(tooltip);
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorScreen.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorScreen.java
index ef777c08..0ac9efcb 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorScreen.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/depositor/BrassDepositorScreen.java
@@ -28,7 +28,7 @@
import com.simibubi.create.foundation.gui.widget.ScrollInput;
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Couple;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.content.backend.behaviours.SliderStylePriceConfigurationPacket;
import dev.ithundxr.createnumismatics.registry.NumismaticsBlocks;
@@ -130,11 +130,11 @@ protected void renderBg(@NotNull GuiGraphics graphics, float partialTick, int mo
graphics.drawCenteredString(font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF);
- Couple cogsAndSpurs = CommonModConfig.currency.convert(menu.contentHolder.getTotalPrice());
+ Couple cogsAndSpurs = NumismaticsConfig.common().defaultCoin.get().convert(menu.contentHolder.getTotalPrice());
int cogs = cogsAndSpurs.getFirst();
int spurs = cogsAndSpurs.getSecond();
Component balanceLabel = Components.translatable("block.numismatics.brass_depositor.tooltip.price",
- TextUtils.formatInt(cogs), CommonModConfig.currency.getName(cogs), spurs);
+ TextUtils.formatInt(cogs), NumismaticsConfig.common().defaultCoin.get().getName(cogs), spurs);
graphics.drawCenteredString(font, balanceLabel, x + (background.width - 8) / 2, y + 21, 0xFFFFFF);
}
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorBlockEntity.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorBlockEntity.java
index 8fa93cec..0d14da3f 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorBlockEntity.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorBlockEntity.java
@@ -31,7 +31,7 @@
import dan200.computercraft.api.ComputerCraftTags;
import dev.ithundxr.createnumismatics.Numismatics;
import dev.ithundxr.createnumismatics.compat.computercraft.ComputerCraftProxy;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.BankAccount;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.content.backend.Trusted;
@@ -341,11 +341,11 @@ public boolean addToTooltip(List tooltip, boolean isPlayerSneaking) {
}
}
- Couple cogsAndSpurs = CommonModConfig.currency.convert(getTotalPrice());
+ Couple cogsAndSpurs = NumismaticsConfig.common().defaultCoin.get().convert(getTotalPrice());
int cogs = cogsAndSpurs.getFirst();
int spurs = cogsAndSpurs.getSecond();
MutableComponent balanceLabel = Components.translatable("block.numismatics.vendor.tooltip.price",
- TextUtils.formatInt(cogs), CommonModConfig.currency.getName(cogs), spurs);
+ TextUtils.formatInt(cogs), NumismaticsConfig.common().defaultCoin.get().getName(cogs), spurs);
// Selling/Buying
Lang.builder()
diff --git a/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorScreen.java b/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorScreen.java
index 464bc1b6..b6dd2429 100644
--- a/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorScreen.java
+++ b/common/src/main/java/dev/ithundxr/createnumismatics/content/vendor/VendorScreen.java
@@ -30,7 +30,7 @@
import com.simibubi.create.foundation.utility.Components;
import com.simibubi.create.foundation.utility.Couple;
import dev.ithundxr.createnumismatics.base.client.rendering.GuiBlockEntityRenderBuilder;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
import dev.ithundxr.createnumismatics.content.backend.Coin;
import dev.ithundxr.createnumismatics.content.backend.behaviours.SliderStylePriceConfigurationPacket;
import dev.ithundxr.createnumismatics.content.vendor.VendorBlockEntity.Mode;
@@ -166,11 +166,11 @@ protected void renderBg(@NotNull GuiGraphics graphics, float partialTick, int mo
graphics.drawCenteredString(font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF);
- Couple cogsAndSpurs = CommonModConfig.currency.convert(menu.contentHolder.getTotalPrice());
+ Couple cogsAndSpurs = NumismaticsConfig.common().defaultCoin.get().convert(menu.contentHolder.getTotalPrice());
int cogs = cogsAndSpurs.getFirst();
int spurs = cogsAndSpurs.getSecond();
Component balanceLabel = Components.translatable("block.numismatics.brass_depositor.tooltip.price",
- TextUtils.formatInt(cogs), CommonModConfig.currency.getName(cogs), spurs);
+ TextUtils.formatInt(cogs), NumismaticsConfig.common().defaultCoin.get().getName(cogs), spurs);
graphics.drawCenteredString(font, balanceLabel, x + (background.width - 8) / 2, y + 21, 0xFFFFFF);
}
diff --git a/fabric/src/main/java/dev/ithundxr/createnumismatics/config/fabric/NumismaticsConfigImpl.java b/fabric/src/main/java/dev/ithundxr/createnumismatics/config/fabric/NumismaticsConfigImpl.java
new file mode 100644
index 00000000..e43625d6
--- /dev/null
+++ b/fabric/src/main/java/dev/ithundxr/createnumismatics/config/fabric/NumismaticsConfigImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Numismatics
+ * Copyright (c) 2024 The Railways Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package dev.ithundxr.createnumismatics.config.fabric;
+
+import com.simibubi.create.foundation.config.ConfigBase;
+import dev.ithundxr.createnumismatics.Numismatics;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
+import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry;
+import fuzs.forgeconfigapiport.api.config.v2.ModConfigEvents;
+import net.minecraftforge.fml.config.ModConfig;
+
+import java.util.Map;
+
+public class NumismaticsConfigImpl {
+ public static void register() {
+ NumismaticsConfig.registerCommon();
+
+ for (Map.Entry pair : NumismaticsConfig.CONFIGS.entrySet())
+ ForgeConfigRegistry.INSTANCE.register(Numismatics.MOD_ID, pair.getKey(), pair.getValue().specification);
+
+ ModConfigEvents.loading(Numismatics.MOD_ID).register(NumismaticsConfig::onLoad);
+ ModConfigEvents.reloading(Numismatics.MOD_ID).register(NumismaticsConfig::onReload);
+ }
+}
diff --git a/fabric/src/main/java/dev/ithundxr/createnumismatics/configuration/FabricModConfig.java b/fabric/src/main/java/dev/ithundxr/createnumismatics/configuration/FabricModConfig.java
deleted file mode 100644
index f6c1c360..00000000
--- a/fabric/src/main/java/dev/ithundxr/createnumismatics/configuration/FabricModConfig.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Numismatics
- * Copyright (c) 2024 The Railways Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package dev.ithundxr.createnumismatics.configuration;
-
-import com.electronwill.nightconfig.core.file.CommentedFileConfig;
-import com.electronwill.nightconfig.core.io.WritingMode;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
-import dev.ithundxr.createnumismatics.content.backend.Coin;
-import net.fabricmc.loader.api.FabricLoader;
-
-import java.nio.file.Path;
-
-public class FabricModConfig {
- public static void loadConfig() {
- Path configPath = FabricLoader.getInstance().getConfigDir().resolve("numismatics-common.toml");
- CommentedFileConfig configData = CommentedFileConfig.builder(configPath)
- .sync()
- .autosave()
- .writingMode(WritingMode.REPLACE)
- .build();
- configData.load();
-
- if (!configData.contains("starter.spur")) configData.set("starter.spur", 0);
- if (!configData.contains("starter.bevel")) configData.set("starter.bevel", 0);
- if (!configData.contains("starter.sprocket")) configData.set("starter.sprocket", 0);
- if (!configData.contains("starter.cog")) configData.set("starter.cog", 0);
- if (!configData.contains("starter.crown")) configData.set("starter.crown", 0);
- if (!configData.contains("starter.sun")) configData.set("starter.sun", 0);
-
- CommonModConfig.starterSpur = configData.get("starter.spur");
- CommonModConfig.starterBevel = configData.get("starter.bevel");
- CommonModConfig.starterSprocket = configData.get("starter.sprocket");
- CommonModConfig.starterCog = configData.get("starter.cog");
- CommonModConfig.starterCrown = configData.get("starter.crown");
- CommonModConfig.starterSun = configData.get("starter.sun");
-
- if (!configData.contains("value.spur")) configData.set("value.spur", 1);
- if (!configData.contains("value.bevel")) configData.set("value.bevel", 8);
- if (!configData.contains("value.sprocket")) configData.set("value.sprocket", 16);
- if (!configData.contains("value.cog")) configData.set("value.cog", 64);
- if (!configData.contains("value.crown")) configData.set("value.crown", 512);
- if (!configData.contains("value.sun")) configData.set("value.sun", 4096);
-
- Coin.SPUR.setValue(configData.get("value.spur"));
- Coin.BEVEL.setValue(configData.get("value.bevel"));
- Coin.SPROCKET.setValue(configData.get("value.sprocket"));
- Coin.COG.setValue(configData.get("value.cog"));
- Coin.CROWN.setValue(configData.get("value.crown"));
- Coin.SUN.setValue(configData.get("value.sun"));
-
- if (!configData.contains("general.currency")) configData.set("general.currency", "COG");
- CommonModConfig.currency = Coin.valueOf(configData.get("general.currency"));
- }
-}
diff --git a/fabric/src/main/java/dev/ithundxr/createnumismatics/fabric/NumismaticsImpl.java b/fabric/src/main/java/dev/ithundxr/createnumismatics/fabric/NumismaticsImpl.java
index 44a04ca6..22b23af9 100644
--- a/fabric/src/main/java/dev/ithundxr/createnumismatics/fabric/NumismaticsImpl.java
+++ b/fabric/src/main/java/dev/ithundxr/createnumismatics/fabric/NumismaticsImpl.java
@@ -20,7 +20,7 @@
import com.mojang.brigadier.CommandDispatcher;
import dev.ithundxr.createnumismatics.Numismatics;
-import dev.ithundxr.createnumismatics.configuration.FabricModConfig;
+import dev.ithundxr.createnumismatics.config.fabric.NumismaticsConfigImpl;
import dev.ithundxr.createnumismatics.events.fabric.CommonEventsFabric;
import dev.ithundxr.createnumismatics.registry.commands.arguments.EnumArgument;
import net.fabricmc.api.ModInitializer;
@@ -37,8 +37,8 @@ public class NumismaticsImpl implements ModInitializer {
@Override
public void onInitialize() {
Numismatics.init();
+ NumismaticsConfigImpl.register();
CommonEventsFabric.init();
- FabricModConfig.loadConfig();
ArgumentTypeRegistry.registerArgumentType(new ResourceLocation(Numismatics.MOD_ID, "enum"), EnumArgument.class, new EnumArgument.Info());
}
diff --git a/forge/src/main/java/dev/ithundxr/createnumismatics/config/forge/NumismaticsConfigImpl.java b/forge/src/main/java/dev/ithundxr/createnumismatics/config/forge/NumismaticsConfigImpl.java
new file mode 100644
index 00000000..c2cb195a
--- /dev/null
+++ b/forge/src/main/java/dev/ithundxr/createnumismatics/config/forge/NumismaticsConfigImpl.java
@@ -0,0 +1,55 @@
+/*
+ * Numismatics
+ * Copyright (c) 2024 The Railways Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+package dev.ithundxr.createnumismatics.config.forge;
+
+import com.simibubi.create.foundation.config.ConfigBase;
+import dev.ithundxr.createnumismatics.config.NumismaticsConfig;
+import net.minecraftforge.eventbus.api.SubscribeEvent;
+import net.minecraftforge.fml.ModLoadingContext;
+import net.minecraftforge.fml.common.Mod;
+import net.minecraftforge.fml.config.ModConfig;
+import net.minecraftforge.fml.event.config.ModConfigEvent;
+
+import java.util.Map;
+
+@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
+public class NumismaticsConfigImpl {
+ public static void register(ModLoadingContext context) {
+ NumismaticsConfig.registerCommon();
+
+ for (Map.Entry pair : NumismaticsConfig.CONFIGS.entrySet())
+ context.registerConfig(pair.getKey(), pair.getValue().specification);
+ }
+
+ @SubscribeEvent
+ public static void onLoad(ModConfigEvent.Loading event) {
+ for (ConfigBase config : NumismaticsConfig.CONFIGS.values())
+ if (config.specification == event.getConfig()
+ .getSpec())
+ config.onLoad();
+ }
+
+ @SubscribeEvent
+ public static void onReload(ModConfigEvent.Reloading event) {
+ for (ConfigBase config : NumismaticsConfig.CONFIGS.values())
+ if (config.specification == event.getConfig()
+ .getSpec())
+ config.onReload();
+ }
+}
diff --git a/forge/src/main/java/dev/ithundxr/createnumismatics/configuration/ForgeModConfig.java b/forge/src/main/java/dev/ithundxr/createnumismatics/configuration/ForgeModConfig.java
deleted file mode 100644
index e8946eac..00000000
--- a/forge/src/main/java/dev/ithundxr/createnumismatics/configuration/ForgeModConfig.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Numismatics
- * Copyright (c) 2024 The Railways Team
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package dev.ithundxr.createnumismatics.configuration;
-
-import com.electronwill.nightconfig.core.file.CommentedFileConfig;
-import com.electronwill.nightconfig.core.io.WritingMode;
-import dev.ithundxr.createnumismatics.config.CommonModConfig;
-import dev.ithundxr.createnumismatics.content.backend.Coin;
-import net.minecraftforge.common.ForgeConfigSpec;
-import net.minecraftforge.fml.ModLoadingContext;
-import net.minecraftforge.fml.config.ModConfig;
-
-import java.nio.file.Paths;
-
-public class ForgeModConfig {
- private static final ForgeConfigSpec.Builder COMMON_BUILDER = new ForgeConfigSpec.Builder();
-
- public static final ForgeConfigSpec.IntValue STARTER_SPUR;
- public static final ForgeConfigSpec.IntValue STARTER_BEVEL;
- public static final ForgeConfigSpec.IntValue STARTER_SPROCKET;
- public static final ForgeConfigSpec.IntValue STARTER_COG;
- public static final ForgeConfigSpec.IntValue STARTER_CROWN;
- public static final ForgeConfigSpec.IntValue STARTER_SUN;
-
- public static final ForgeConfigSpec.IntValue SPUR_VALUE;
- public static final ForgeConfigSpec.IntValue BEVEL_VALUE;
- public static final ForgeConfigSpec.IntValue SPROCKET_VALUE;
- public static final ForgeConfigSpec.IntValue COG_VALUE;
- public static final ForgeConfigSpec.IntValue CROWN_VALUE;
- public static final ForgeConfigSpec.IntValue SUN_VALUE;
-
- public static final ForgeConfigSpec.ConfigValue CURRENCY;
-
- static {
- COMMON_BUILDER.comment("Numismatics configuration file").push("general");
- CURRENCY = COMMON_BUILDER.comment("The default currency").define("currency", "COG");
-
- COMMON_BUILDER.pop();
- COMMON_BUILDER.comment("The number of coins added when a player first looks at their bank account").push("starter");
- STARTER_SPUR = COMMON_BUILDER.comment("The number of spurs added when a player first looks at their bank account").defineInRange("spur", 0, 0, Integer.MAX_VALUE);
- STARTER_BEVEL = COMMON_BUILDER.comment("The number of bevels added when a player first looks at their bank account").defineInRange("bevel", 0, 0, Integer.MAX_VALUE);
- STARTER_SPROCKET = COMMON_BUILDER.comment("The number of sprockets added when a player first looks at their bank account").defineInRange("sprocket", 0, 0, Integer.MAX_VALUE);
- STARTER_COG = COMMON_BUILDER.comment("The number of cogs added when a player first looks at their bank account").defineInRange("cog", 0, 0, Integer.MAX_VALUE);
- STARTER_CROWN = COMMON_BUILDER.comment("The number of crowns added when a player first looks at their bank account").defineInRange("crown", 0, 0, Integer.MAX_VALUE);
- STARTER_SUN = COMMON_BUILDER.comment("The number of suns added when a player first looks at their bank account").defineInRange("sun", 0, 0, Integer.MAX_VALUE);
-
- COMMON_BUILDER.pop();
- COMMON_BUILDER.comment("The value of each coins in spurs").push("value");
- SPUR_VALUE = COMMON_BUILDER.defineInRange("spur", 1, 0, Integer.MAX_VALUE);
- BEVEL_VALUE = COMMON_BUILDER.defineInRange("bevel", 8, 0, Integer.MAX_VALUE);
- SPROCKET_VALUE = COMMON_BUILDER.defineInRange("sprocket", 16, 0, Integer.MAX_VALUE);
- COG_VALUE = COMMON_BUILDER.defineInRange("cog", 64, 0, Integer.MAX_VALUE);
- CROWN_VALUE = COMMON_BUILDER.defineInRange("crown", 512, 0, Integer.MAX_VALUE);
- SUN_VALUE = COMMON_BUILDER.defineInRange("sun", 4096, 0, Integer.MAX_VALUE);
-
- COMMON_BUILDER.pop();
-
- ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, COMMON_BUILDER.build());
- }
-
- public static void loadConfig() {
- final CommentedFileConfig configData = CommentedFileConfig.builder(Paths.get("config/" + "numismatics" + "-common.toml"))
- .sync()
- .autosave()
- .writingMode(WritingMode.REPLACE)
- .build();
- configData.load();
- COMMON_BUILDER.build().setConfig(configData);
-
- CommonModConfig.starterSpur = STARTER_SPUR.get();
- CommonModConfig.starterBevel = STARTER_BEVEL.get();
- CommonModConfig.starterSprocket = STARTER_SPROCKET.get();
- CommonModConfig.starterCog = STARTER_COG.get();
- CommonModConfig.starterCrown = STARTER_CROWN.get();
- CommonModConfig.starterSun = STARTER_SUN.get();
-
- Coin.SPUR.setValue(SPUR_VALUE.get());
- Coin.BEVEL.setValue(BEVEL_VALUE.get());
- Coin.SPROCKET.setValue(SPROCKET_VALUE.get());
- Coin.COG.setValue(COG_VALUE.get());
- Coin.CROWN.setValue(CROWN_VALUE.get());
- Coin.SUN.setValue(SUN_VALUE.get());
-
- CommonModConfig.currency = Coin.valueOf(CURRENCY.get());
- }
-}
diff --git a/forge/src/main/java/dev/ithundxr/createnumismatics/forge/NumismaticsImpl.java b/forge/src/main/java/dev/ithundxr/createnumismatics/forge/NumismaticsImpl.java
index 77dfb626..a526d586 100644
--- a/forge/src/main/java/dev/ithundxr/createnumismatics/forge/NumismaticsImpl.java
+++ b/forge/src/main/java/dev/ithundxr/createnumismatics/forge/NumismaticsImpl.java
@@ -20,7 +20,7 @@
import com.mojang.brigadier.CommandDispatcher;
import dev.ithundxr.createnumismatics.Numismatics;
-import dev.ithundxr.createnumismatics.configuration.ForgeModConfig;
+import dev.ithundxr.createnumismatics.config.forge.NumismaticsConfigImpl;
import dev.ithundxr.createnumismatics.multiloader.Env;
import dev.ithundxr.createnumismatics.registry.commands.arguments.EnumArgument;
import dev.ithundxr.createnumismatics.registry.forge.NumismaticsCreativeModeTabsImpl;
@@ -33,6 +33,7 @@
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModList;
+import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
@@ -53,6 +54,7 @@ public NumismaticsImpl() {
eventBus = FMLJavaModLoadingContext.get().getModEventBus();
NumismaticsCreativeModeTabsImpl.register(eventBus);
Numismatics.init();
+ NumismaticsConfigImpl.register(ModLoadingContext.get());
//noinspection Convert2MethodRef
Env.CLIENT.runIfCurrent(() -> () -> NumismaticsClientImpl.init());
eventBus.addListener(NumismaticsImpl::registerArgumentTypes);
@@ -67,7 +69,6 @@ private static void registerArgumentTypes(RegisterEvent event) {
}
public static void onCommonSetup(final FMLCommonSetupEvent event) {
- ForgeModConfig.loadConfig();
event.enqueueWork(Numismatics::postRegistrationInit);
}