Config watching

- Fixed client and common config not being picked up by the configwatcher, thus not reacting to changes
This commit is contained in:
simibubi 2020-05-08 12:55:52 +02:00
parent 995357c32e
commit 4b1c187d64
2 changed files with 23 additions and 15 deletions

View file

@ -63,11 +63,10 @@ public class Create {
modEventBus.addListener(AllConfigs::onLoad); modEventBus.addListener(AllConfigs::onLoad);
modEventBus.addListener(AllConfigs::onReload); modEventBus.addListener(AllConfigs::onReload);
CreateClient.addListeners(modEventBus); CreateClient.addListeners(modEventBus);
AllConfigs.registerClientCommon();
} }
public static void init(final FMLCommonSetupEvent event) { public static void init(final FMLCommonSetupEvent event) {
AllConfigs.registerAll();
schematicReceiver = new ServerSchematicLoader(); schematicReceiver = new ServerSchematicLoader();
redstoneLinkNetworkHandler = new RedstoneLinkNetworkHandler(); redstoneLinkNetworkHandler = new RedstoneLinkNetworkHandler();
torquePropagator = new TorquePropagator(); torquePropagator = new TorquePropagator();
@ -77,6 +76,7 @@ public class Create {
AllTriggers.register(); AllTriggers.register();
AllWorldFeatures.reload(); AllWorldFeatures.reload();
AllConfigs.registerServer();
} }
public static void serverStarting(FMLServerStartingEvent event) { public static void serverStarting(FMLServerStartingEvent event) {

View file

@ -1,7 +1,8 @@
package com.simibubi.create.config; package com.simibubi.create.config;
import java.util.ArrayList; import java.util.HashMap;
import java.util.List; import java.util.Map;
import java.util.Map.Entry;
import java.util.function.Supplier; import java.util.function.Supplier;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@ -13,11 +14,11 @@ import net.minecraftforge.fml.config.ModConfig.Type;
public class AllConfigs { public class AllConfigs {
static List<Pair<ConfigBase, ModConfig.Type>> configs = new ArrayList<>(); static Map<ConfigBase, ModConfig.Type> configs = new HashMap<>();
public static CClient CLIENT = register(CClient::new, ModConfig.Type.CLIENT); public static CClient CLIENT;
public static CCommon COMMON = register(CCommon::new, ModConfig.Type.COMMON); public static CCommon COMMON;
public static CServer SERVER = register(CServer::new, ModConfig.Type.SERVER); public static CServer SERVER;
private static <T extends ConfigBase> T register(Supplier<T> factory, ModConfig.Type side) { private static <T extends ConfigBase> T register(Supplier<T> factory, ModConfig.Type side) {
Pair<T, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(builder -> { Pair<T, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(builder -> {
@ -28,24 +29,31 @@ public class AllConfigs {
T config = specPair.getLeft(); T config = specPair.getLeft();
config.specification = specPair.getRight(); config.specification = specPair.getRight();
configs.add(Pair.of(config, side)); configs.put(config, side);
return config; return config;
} }
public static void registerAll() { public static void registerClientCommon() {
ModLoadingContext ctx = ModLoadingContext.get(); CLIENT = register(CClient::new, ModConfig.Type.CLIENT);
for (Pair<ConfigBase, Type> pair : configs) COMMON = register(CCommon::new, ModConfig.Type.COMMON);
ctx.registerConfig(pair.getValue(), pair.getKey().specification); for (Entry<ConfigBase, Type> 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) { public static void onLoad(ModConfig.Loading event) {
for (Pair<ConfigBase, Type> pair : configs) for (Entry<ConfigBase, Type> pair : configs.entrySet())
if (pair.getKey().specification == event.getConfig().getSpec()) if (pair.getKey().specification == event.getConfig().getSpec())
pair.getKey().onLoad(); pair.getKey().onLoad();
} }
public static void onReload(ModConfig.Reloading event) { public static void onReload(ModConfig.Reloading event) {
for (Pair<ConfigBase, Type> pair : configs) for (Entry<ConfigBase, Type> pair : configs.entrySet())
if (pair.getKey().specification == event.getConfig().getSpec()) if (pair.getKey().specification == event.getConfig().getSpec())
pair.getKey().onReload(); pair.getKey().onReload();
} }