From 4b1c187d64ff06f98f8501fa72b9ed471c9cf4aa Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Fri, 8 May 2020 12:55:52 +0200 Subject: [PATCH] Config watching - Fixed client and common config not being picked up by the configwatcher, thus not reacting to changes --- src/main/java/com/simibubi/create/Create.java | 4 +-- .../simibubi/create/config/AllConfigs.java | 34 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index ed162dd78..255e8c0f3 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -63,11 +63,10 @@ public class Create { modEventBus.addListener(AllConfigs::onLoad); modEventBus.addListener(AllConfigs::onReload); CreateClient.addListeners(modEventBus); + AllConfigs.registerClientCommon(); } public static void init(final FMLCommonSetupEvent event) { - AllConfigs.registerAll(); - schematicReceiver = new ServerSchematicLoader(); redstoneLinkNetworkHandler = new RedstoneLinkNetworkHandler(); torquePropagator = new TorquePropagator(); @@ -77,6 +76,7 @@ public class Create { AllTriggers.register(); AllWorldFeatures.reload(); + AllConfigs.registerServer(); } public static void serverStarting(FMLServerStartingEvent event) { diff --git a/src/main/java/com/simibubi/create/config/AllConfigs.java b/src/main/java/com/simibubi/create/config/AllConfigs.java index 79d4f3b70..0b05583d4 100644 --- a/src/main/java/com/simibubi/create/config/AllConfigs.java +++ b/src/main/java/com/simibubi/create/config/AllConfigs.java @@ -1,7 +1,8 @@ package com.simibubi.create.config; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.function.Supplier; import org.apache.commons.lang3.tuple.Pair; @@ -13,11 +14,11 @@ import net.minecraftforge.fml.config.ModConfig.Type; public class AllConfigs { - static List> configs = new ArrayList<>(); + static Map configs = new HashMap<>(); - public static CClient CLIENT = register(CClient::new, ModConfig.Type.CLIENT); - public static CCommon COMMON = register(CCommon::new, ModConfig.Type.COMMON); - public static CServer SERVER = register(CServer::new, ModConfig.Type.SERVER); + public static CClient CLIENT; + public static CCommon COMMON; + public static CServer SERVER; private static T register(Supplier factory, ModConfig.Type side) { Pair specPair = new ForgeConfigSpec.Builder().configure(builder -> { @@ -28,24 +29,31 @@ public class AllConfigs { T config = specPair.getLeft(); config.specification = specPair.getRight(); - configs.add(Pair.of(config, side)); + configs.put(config, side); return config; } - public static void registerAll() { - ModLoadingContext ctx = ModLoadingContext.get(); - for (Pair pair : configs) - ctx.registerConfig(pair.getValue(), pair.getKey().specification); + public static void registerClientCommon() { + CLIENT = register(CClient::new, ModConfig.Type.CLIENT); + COMMON = register(CCommon::new, ModConfig.Type.COMMON); + for (Entry pair : configs.entrySet()) + if (pair.getValue() != Type.SERVER) + ModLoadingContext.get().registerConfig(pair.getValue(), pair.getKey().specification); + } + + public static void registerServer() { + SERVER = register(CServer::new, ModConfig.Type.SERVER); + ModLoadingContext.get().registerConfig(configs.get(SERVER), SERVER.specification); } public static void onLoad(ModConfig.Loading event) { - for (Pair pair : configs) + for (Entry pair : configs.entrySet()) if (pair.getKey().specification == event.getConfig().getSpec()) pair.getKey().onLoad(); } public static void onReload(ModConfig.Reloading event) { - for (Pair pair : configs) + for (Entry pair : configs.entrySet()) if (pair.getKey().specification == event.getConfig().getSpec()) pair.getKey().onReload(); }