mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-11-11 13:04:05 +01:00
Config watching
- Fixed client and common config not being picked up by the configwatcher, thus not reacting to changes
This commit is contained in:
parent
995357c32e
commit
4b1c187d64
@ -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) {
|
||||
|
@ -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<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 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 extends ConfigBase> T register(Supplier<T> factory, ModConfig.Type side) {
|
||||
Pair<T, ForgeConfigSpec> 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<ConfigBase, Type> 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<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) {
|
||||
for (Pair<ConfigBase, Type> pair : configs)
|
||||
for (Entry<ConfigBase, Type> pair : configs.entrySet())
|
||||
if (pair.getKey().specification == event.getConfig().getSpec())
|
||||
pair.getKey().onLoad();
|
||||
}
|
||||
|
||||
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())
|
||||
pair.getKey().onReload();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user