diff --git a/src/main/java/vazkii/quark/base/module/ModuleLoader.java b/src/main/java/vazkii/quark/base/module/ModuleLoader.java index bfe2a15c73..af0febcc26 100644 --- a/src/main/java/vazkii/quark/base/module/ModuleLoader.java +++ b/src/main/java/vazkii/quark/base/module/ModuleLoader.java @@ -6,9 +6,6 @@ import vazkii.quark.base.Quark; import vazkii.quark.base.block.IQuarkBlock; import vazkii.quark.base.item.IQuarkItem; -import vazkii.quark.base.module.config.ConfigFlagManager; -import vazkii.zeta.event.ZRegister; -import vazkii.zeta.event.bus.LoadEvent; import vazkii.zeta.module.ZetaModule; //TODO ZETA: im in the process of stripping this class for parts @@ -17,30 +14,8 @@ public final class ModuleLoader { public static final ModuleLoader INSTANCE = new ModuleLoader(); - //private ConfigResolver config; - public Runnable onConfigReloadJEI; - private ModuleLoader() { } - public void start() { - //config = new ConfigResolver(); - //config.makeSpec(); - } - - public ConfigFlagManager getConfigFlagManager() { - return Quark.ZETA.weirdConfigSingleton.getConfigFlagManager(); - } - - @LoadEvent - public void register(ZRegister event) { - } - - public void configChanged() { - //if (onConfigReloadJEI != null) - // onConfigReloadJEI.run(); - //config.configChanged(); - } - //tempting to push this method directly through to Quark.ZETA.modules... //but i think it's more appropriate to have this stored in a configuration class @Deprecated @@ -71,12 +46,4 @@ else if(i instanceof BlockItem bi) { return true; } - /** - * Meant only to be called internally. - */ - public void initJEICompat(Runnable jeiRunnable) { - onConfigReloadJEI = jeiRunnable; - onConfigReloadJEI.run(); - } - } diff --git a/src/main/java/vazkii/quark/base/proxy/CommonProxy.java b/src/main/java/vazkii/quark/base/proxy/CommonProxy.java index d573b68383..3ce515d796 100644 --- a/src/main/java/vazkii/quark/base/proxy/CommonProxy.java +++ b/src/main/java/vazkii/quark/base/proxy/CommonProxy.java @@ -100,7 +100,7 @@ public void setup(ZCommonSetup event) { @LoadEvent public void register(ZRegister heck) { - Quark.ZETA.weirdConfigSingleton.getConfigFlagManager().registerConfigBoundElements(); + Quark.ZETA.configManager.getConfigFlagManager().registerConfigBoundElements(); } //forge event @@ -118,14 +118,13 @@ public void setConfigGuiSaving(boolean saving) { lastConfigChange = Quark.ZETA.ticker_SHOULD_NOT_BE_HERE.ticksInGame; } - //TODO: mess, find a better spot for this + //TODO: probably find a better spot for this? It's not *only* fired when the + // config file is externally changed, but also when it's changed through config GUI, + // which means we roundtrip through the on-disk representation for no good reason public void handleQuarkConfigChange() { //ModuleLoader.INSTANCE.configChanged(); - Quark.ZETA.weirdConfigSingleton.runDatabindings(Quark.ZETA.configInternals); - //Quark.ZETA.weirdConfigSingleton.getConfigFlagManager().clear(); + Quark.ZETA.configManager.onReload(); Quark.ZETA.loadBus.fire(new ZConfigChanged()); - if(ModuleLoader.INSTANCE.onConfigReloadJEI != null) - ModuleLoader.INSTANCE.onConfigReloadJEI.run(); EntitySpawnHandler.refresh(); SyncedFlagHandler.sendFlagInfoToPlayers(); } diff --git a/src/main/java/vazkii/quark/integration/jei/QuarkJeiPlugin.java b/src/main/java/vazkii/quark/integration/jei/QuarkJeiPlugin.java index 6082f259f8..8f3e0995e4 100644 --- a/src/main/java/vazkii/quark/integration/jei/QuarkJeiPlugin.java +++ b/src/main/java/vazkii/quark/integration/jei/QuarkJeiPlugin.java @@ -88,7 +88,7 @@ public void onRuntimeAvailable(@Nonnull final IJeiRuntime jeiRuntime) { if (!disabledItems.isEmpty()) jeiRuntime.getIngredientManager().removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, disabledItems); - ModuleLoader.INSTANCE.initJEICompat(() -> { + Quark.ZETA.configManager.setJeiReloadListener(z -> { if(ModuleLoader.INSTANCE.isModuleEnabled(DiamondRepairModule.class)) Minecraft.getInstance().submitAsync(() -> hideAnvilRepairRecipes(jeiRuntime.getRecipeManager())); diff --git a/src/main/java/vazkii/zeta/Zeta.java b/src/main/java/vazkii/zeta/Zeta.java index 3bba7d3767..0f134becea 100644 --- a/src/main/java/vazkii/zeta/Zeta.java +++ b/src/main/java/vazkii/zeta/Zeta.java @@ -8,7 +8,7 @@ import vazkii.zeta.client.ClientTicker; import vazkii.zeta.config.IZetaConfigInternals; import vazkii.zeta.config.SectionDefinition; -import vazkii.zeta.config.WeirdConfigSingleton; +import vazkii.zeta.config.ConfigManager; import vazkii.zeta.event.bus.IZetaLoadEvent; import vazkii.zeta.event.bus.IZetaPlayEvent; import vazkii.zeta.event.bus.LoadEvent; @@ -51,7 +51,7 @@ public Zeta(String modid, Logger log) { public final ZetaRegistry registry; public final DyeablesRegistry dyeables; //TODO: move into ZetaRegistry? - public WeirdConfigSingleton weirdConfigSingleton; //Should probably split this up into various parts + public ConfigManager configManager; //This could do with being split up into various pieces public IZetaConfigInternals configInternals; //TODO: move to ZetaClient. Some bits of the server *do* actually need this for some raisin (config code) @@ -61,11 +61,14 @@ public void loadModules(Iterable categories, ModuleFinder finder, modules.initCategories(categories); modules.load(finder); - this.weirdConfigSingleton = new WeirdConfigSingleton(this, rootPojo); - this.configInternals = makeConfigInternals(weirdConfigSingleton.getRootConfig()); + //The reason why there's a circular dependency between configManager and configInternals: + // - ConfigManager determines the shape and layout of the config file + // - The platform-specific configInternals loads the actual values, from the platform-specfic config file + // - Only then can ConfigManager do the initial config load - //the initial config load (TODO: might need to find a better spot for this) - weirdConfigSingleton.runDatabindings(configInternals); + this.configManager = new ConfigManager(this, rootPojo); + this.configInternals = makeConfigInternals(configManager.getRootConfig()); + this.configManager.onReload(); } public abstract ZetaSide getSide(); diff --git a/src/main/java/vazkii/zeta/client/config/screen/ZetaConfigHomeScreen.java b/src/main/java/vazkii/zeta/client/config/screen/ZetaConfigHomeScreen.java index 7eb6caad4b..55b5347a95 100644 --- a/src/main/java/vazkii/zeta/client/config/screen/ZetaConfigHomeScreen.java +++ b/src/main/java/vazkii/zeta/client/config/screen/ZetaConfigHomeScreen.java @@ -36,7 +36,7 @@ protected void init() { super.init(); List categories = z.modules.getInhabitedCategories(); - @Nullable SectionDefinition generalSection = z.weirdConfigSingleton.getGeneralSection(); + @Nullable SectionDefinition generalSection = z.configManager.getGeneralSection(); int buttonCount = categories.size(); if(generalSection != null) @@ -57,8 +57,8 @@ protected void init() { if(i < categories.size()) { //a category button ZetaCategory category = categories.get(i); - ValueDefinition categoryEnabled = z.weirdConfigSingleton.getCategoryEnabledOption(category); - SectionDefinition categorySection = z.weirdConfigSingleton.getCategorySection(category); + ValueDefinition categoryEnabled = z.configManager.getCategoryEnabledOption(category); + SectionDefinition categorySection = z.configManager.getCategorySection(category); bWidth -= 20; //room for the checkbox Button mainButton = addRenderableWidget(new CategoryButton(zc, x, y, bWidth, 20, componentFor(categorySection), category.icon.get(), diff --git a/src/main/java/vazkii/zeta/config/WeirdConfigSingleton.java b/src/main/java/vazkii/zeta/config/ConfigManager.java similarity index 90% rename from src/main/java/vazkii/zeta/config/WeirdConfigSingleton.java rename to src/main/java/vazkii/zeta/config/ConfigManager.java index fa1b6ef52e..91454fc4f5 100644 --- a/src/main/java/vazkii/zeta/config/WeirdConfigSingleton.java +++ b/src/main/java/vazkii/zeta/config/ConfigManager.java @@ -16,14 +16,15 @@ import vazkii.zeta.module.ZetaModule; import vazkii.zeta.module.ZetaModuleManager; -//TODO: find somewhere better to put this, better data structure etc -public class WeirdConfigSingleton { +public class ConfigManager { private final Zeta z; private final ConfigFlagManager cfm = new ConfigFlagManager(); private final SectionDefinition rootConfig; //for updating the values of @Config annotations to match the current state of the config + // and other "listening for config load" purposes private final List> databindings = new ArrayList<>(); + private Consumer onConfigReloadJEI; //ummmmmmm i think my abstraction isn't very good private final @Nullable SectionDefinition generalSection; @@ -36,7 +37,7 @@ public class WeirdConfigSingleton { //state private final Set enabledCategories = new HashSet<>(); - public WeirdConfigSingleton(Zeta z, Object rootPojo) { + public ConfigManager(Zeta z, Object rootPojo) { this.z = z; ZetaModuleManager modules = z.modules; @@ -100,7 +101,7 @@ public SectionDefinition getRootConfig() { return rootConfig; } - // bad bad bad + // mapping between internal and external representations of the config (?) public @Nullable SectionDefinition getGeneralSection() { return generalSection; @@ -140,13 +141,21 @@ public boolean isCategoryEnabled(ZetaCategory cat) { return enabledCategories.contains(cat); } - //ummm + // ummm public ConfigFlagManager getConfigFlagManager() { return cfm; } - public void runDatabindings(IZetaConfigInternals internals) { + public void onReload() { + IZetaConfigInternals internals = z.configInternals; databindings.forEach(c -> c.accept(internals)); + + if(onConfigReloadJEI != null) + onConfigReloadJEI.accept(internals); + } + + public void setJeiReloadListener(Consumer consumer) { + this.onConfigReloadJEI = consumer; } } diff --git a/src/main/java/vazkii/zeta/module/ZetaModule.java b/src/main/java/vazkii/zeta/module/ZetaModule.java index 36eb093f1e..4b0ee1148d 100644 --- a/src/main/java/vazkii/zeta/module/ZetaModule.java +++ b/src/main/java/vazkii/zeta/module/ZetaModule.java @@ -3,11 +3,9 @@ import java.util.List; import java.util.Set; -import com.google.common.collect.Lists; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.loading.FMLEnvironment; -import vazkii.quark.base.module.ModuleLoader; import vazkii.quark.base.module.hint.HintManager; import vazkii.quark.base.module.hint.HintObject; import vazkii.zeta.Zeta; @@ -15,6 +13,7 @@ import vazkii.zeta.event.bus.PlayEvent; public class ZetaModule { + public Zeta zeta; public ZetaCategory category = null; public String displayName = ""; @@ -45,7 +44,7 @@ public final void setEnabled(Zeta z, boolean willEnable) { configEnabled = willEnable; //TODO: i messed up the category enabled stuff, Its Weird now - if(z.weirdConfigSingleton != null && !z.weirdConfigSingleton.isCategoryEnabled(category)) + if(z.configManager != null && !z.configManager.isCategoryEnabled(category)) willEnable = false; disabledByOverlap = false; @@ -80,7 +79,7 @@ private void setEnabledAndManageSubscriptions(Zeta z, boolean nowEnabled) { @PlayEvent public final void addAnnotationHints(ZGatherHints event) { if(annotationHints == null) - annotationHints = HintManager.gatherHintAnnotations(ModuleLoader.INSTANCE.getConfigFlagManager(), this); + annotationHints = HintManager.gatherHintAnnotations(zeta.configManager.getConfigFlagManager(), this); for(HintObject hint : annotationHints) hint.apply(event); diff --git a/src/main/java/vazkii/zeta/module/ZetaModuleManager.java b/src/main/java/vazkii/zeta/module/ZetaModuleManager.java index 7296a01e77..b3aa2c936a 100644 --- a/src/main/java/vazkii/zeta/module/ZetaModuleManager.java +++ b/src/main/java/vazkii/zeta/module/ZetaModuleManager.java @@ -148,6 +148,7 @@ private ZetaModule constructAndSetup(TentativeModule t) { LEGACY_actuallySubscribe = true; } + module.zeta = z; module.category = t.category(); module.displayName = t.displayName();