diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/GeneralConfig.java b/loader-common/src/main/java/org/cyclops/cyclopscore/GeneralConfig.java new file mode 100644 index 0000000000..5b28c05085 --- /dev/null +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/GeneralConfig.java @@ -0,0 +1,39 @@ +package org.cyclops.cyclopscore; + +import org.cyclops.cyclopscore.config.ConfigurablePropertyCommon; +import org.cyclops.cyclopscore.config.ModConfigLocation; +import org.cyclops.cyclopscore.config.extendedconfig.DummyConfigCommon; +import org.cyclops.cyclopscore.helper.ModBaseCommon; + +import java.util.UUID; + +/** + * A config with general options for this mod. + * @author rubensworks + * + */ +public class GeneralConfig extends DummyConfigCommon> { + + @ConfigurablePropertyCommon(category = "core", comment = "If an anonymous mod startup analytics request may be sent to our analytics service.") + public static boolean analytics = true; + + @ConfigurablePropertyCommon(category = "core", comment = "The anonymous id used by the analytics service.") + public static String anonymousAnalyticsID = UUID.randomUUID().toString(); + + @ConfigurablePropertyCommon(category = "core", comment = "If the version checker should be enabled.") + public static boolean versionChecker = true; + + @ConfigurablePropertyCommon(category = "general", comment = "When in a dev environment, if a button should be added to the main menu to open a dev world (shift-click creates a new world).", configLocation = ModConfigLocation.CLIENT) + public static boolean devWorldButton = true; + + @ConfigurablePropertyCommon(category = "general", comment = "When in a dev environment, if music should be disabled at startup.", configLocation = ModConfigLocation.CLIENT) + public static boolean devDisableMusic = true; + + /** + * Create a new instance. + */ + public GeneralConfig(ModBaseCommon mod) { + super(mod, "general"); + } + +} diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/CyclopsCoreMainFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/CyclopsCoreFabric.java similarity index 68% rename from loader-fabric/src/main/java/org/cyclops/cyclopscore/CyclopsCoreMainFabric.java rename to loader-fabric/src/main/java/org/cyclops/cyclopscore/CyclopsCoreFabric.java index 3f95c205b7..358aa8925e 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/CyclopsCoreMainFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/CyclopsCoreFabric.java @@ -1,6 +1,7 @@ package org.cyclops.cyclopscore; import net.fabricmc.api.ModInitializer; +import org.cyclops.cyclopscore.config.ConfigHandler; import org.cyclops.cyclopscore.helper.CyclopsCoreInstance; import org.cyclops.cyclopscore.init.ModBaseFabric; import org.cyclops.cyclopscore.proxy.ClientProxyFabric; @@ -12,14 +13,14 @@ * The main mod class of CyclopsCore. * @author rubensworks */ -public class CyclopsCoreMainFabric extends ModBaseFabric implements ModInitializer { +public class CyclopsCoreFabric extends ModBaseFabric implements ModInitializer { /** * The unique instance of this mod. */ - public static CyclopsCoreMainFabric _instance; + public static CyclopsCoreFabric _instance; - public CyclopsCoreMainFabric() { + public CyclopsCoreFabric() { super(Reference.MOD_ID, (instance) -> { _instance = instance; CyclopsCoreInstance.MOD = instance; @@ -35,4 +36,11 @@ protected IClientProxyCommon constructClientProxy() { protected ICommonProxyCommon constructCommonProxy() { return new CommonProxyFabric(); } + + @Override + protected void onConfigsRegister(ConfigHandler configHandler) { + super.onConfigsRegister(configHandler); + + configHandler.addConfigurable(new GeneralConfig(this)); + } } diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldFabricRegistrar.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldFabricRegistrar.java index 0ef949173b..4623f5aec0 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldFabricRegistrar.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldFabricRegistrar.java @@ -4,7 +4,8 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.TitleScreen; import net.minecraft.sounds.SoundSource; -import org.cyclops.cyclopscore.CyclopsCoreMainFabric; +import org.cyclops.cyclopscore.GeneralConfig; +import org.cyclops.cyclopscore.helper.IModHelpers; /** * @author rubensworks @@ -12,8 +13,12 @@ public class GuiMainMenuExtensionDevWorldFabricRegistrar { public static void afterInit(Minecraft minecraft, Screen screen, int scaledWidth, int scaledHeight) { // Add a button to the main menu and disable music if we're in a dev environment - if (CyclopsCoreMainFabric._instance.getModHelpers().getMinecraftHelpers().isDevEnvironment()) { + if (IModHelpers.get().getMinecraftHelpers().isDevEnvironment() && GeneralConfig.devWorldButton) { GuiMainMenuExtensionDevWorld.onMainMenuInit(minecraft, screen); + } + + // And disable music + if (IModHelpers.get().getMinecraftHelpers().isDevEnvironment() && GeneralConfig.devDisableMusic) { if (screen instanceof TitleScreen) { Minecraft.getInstance().options.getSoundSourceOptionInstance(SoundSource.MUSIC).set(0.0); } diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/helper/MinecraftHelpersFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/helper/MinecraftHelpersFabric.java index e7241fc0e4..3e24288b13 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/helper/MinecraftHelpersFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/helper/MinecraftHelpersFabric.java @@ -4,7 +4,7 @@ import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.impl.FabricLoaderImpl; import net.minecraft.client.Minecraft; -import org.cyclops.cyclopscore.CyclopsCoreMainFabric; +import org.cyclops.cyclopscore.CyclopsCoreFabric; import org.cyclops.cyclopscore.Reference; /** @@ -20,7 +20,7 @@ public boolean isDevEnvironment() { @Override public boolean isMinecraftInitialized() { - return CyclopsCoreMainFabric._instance.isLoaded(); + return CyclopsCoreFabric._instance.isLoaded(); } @Override diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/item/ItemInformationProviderFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/item/ItemInformationProviderFabric.java index 5a75d464c3..4b30d9215c 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/item/ItemInformationProviderFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/item/ItemInformationProviderFabric.java @@ -4,7 +4,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import org.cyclops.cyclopscore.CyclopsCoreMainFabric; +import org.cyclops.cyclopscore.CyclopsCoreFabric; import java.util.List; @@ -15,7 +15,7 @@ public class ItemInformationProviderFabric extends ItemInformationProviderCommon { public static void onTooltip(ItemStack itemStack, Item.TooltipContext tooltipContext, TooltipFlag tooltipFlag, List lines) { if (ITEMS_INFO.contains(itemStack.getItem())) { - CyclopsCoreMainFabric._instance.getModHelpers().getL10NHelpers().addOptionalInfo(lines, itemStack.getDescriptionId()); + CyclopsCoreFabric._instance.getModHelpers().getL10NHelpers().addOptionalInfo(lines, itemStack.getDescriptionId()); } } } diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/ClientProxyFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/ClientProxyFabric.java index 3daeb63a2b..810426e794 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/ClientProxyFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/ClientProxyFabric.java @@ -2,7 +2,7 @@ import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; -import org.cyclops.cyclopscore.CyclopsCoreMainFabric; +import org.cyclops.cyclopscore.CyclopsCoreFabric; import org.cyclops.cyclopscore.client.gui.GuiMainMenuExtensionDevWorldFabricRegistrar; import org.cyclops.cyclopscore.init.ModBaseFabric; import org.cyclops.cyclopscore.item.ItemInformationProviderFabric; @@ -21,7 +21,7 @@ public ClientProxyFabric() { @Override public ModBaseFabric getMod() { - return CyclopsCoreMainFabric._instance; + return CyclopsCoreFabric._instance; } @Override diff --git a/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/CommonProxyFabric.java b/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/CommonProxyFabric.java index 6d29e19fab..c802afab33 100644 --- a/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/CommonProxyFabric.java +++ b/loader-fabric/src/main/java/org/cyclops/cyclopscore/proxy/CommonProxyFabric.java @@ -1,6 +1,6 @@ package org.cyclops.cyclopscore.proxy; -import org.cyclops.cyclopscore.CyclopsCoreMainFabric; +import org.cyclops.cyclopscore.CyclopsCoreFabric; import org.cyclops.cyclopscore.init.ModBaseFabric; /** @@ -12,7 +12,7 @@ public class CommonProxyFabric extends CommonProxyComponentFabric { @Override public ModBaseFabric getMod() { - return CyclopsCoreMainFabric._instance; + return CyclopsCoreFabric._instance; } } diff --git a/loader-fabric/src/main/resources/fabric.mod.json b/loader-fabric/src/main/resources/fabric.mod.json index 2ceeb68a37..b96e748c77 100644 --- a/loader-fabric/src/main/resources/fabric.mod.json +++ b/loader-fabric/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "environment": "*", "entrypoints": { "main": [ - "org.cyclops.cyclopscore.CyclopsCoreMainFabric" + "org.cyclops.cyclopscore.CyclopsCoreFabric" ], "client": [ "org.cyclops.cyclopscore.CyclopsCoreClientFabric" diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/CyclopsCoreForge.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/CyclopsCoreForge.java index 187c8098f1..e5479ca92f 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/CyclopsCoreForge.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/CyclopsCoreForge.java @@ -1,6 +1,7 @@ package org.cyclops.cyclopscore; import net.minecraftforge.fml.common.Mod; +import org.cyclops.cyclopscore.config.ConfigHandler; import org.cyclops.cyclopscore.helper.CyclopsCoreInstance; import org.cyclops.cyclopscore.init.ModBaseForge; import org.cyclops.cyclopscore.proxy.ClientProxyForge; @@ -37,4 +38,11 @@ protected IClientProxyCommon constructClientProxy() { protected ICommonProxyCommon constructCommonProxy() { return new CommonProxyForge(); } + + @Override + protected void onConfigsRegister(ConfigHandler configHandler) { + super.onConfigsRegister(configHandler); + + configHandler.addConfigurable(new GeneralConfig(this)); + } } diff --git a/loader-forge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldForgeRegistrar.java b/loader-forge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldForgeRegistrar.java index ef251e35a8..2215651683 100644 --- a/loader-forge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldForgeRegistrar.java +++ b/loader-forge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldForgeRegistrar.java @@ -7,7 +7,8 @@ import net.minecraftforge.client.event.ScreenEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import org.cyclops.cyclopscore.CyclopsCoreForge; +import org.cyclops.cyclopscore.GeneralConfig; +import org.cyclops.cyclopscore.helper.IModHelpers; @Mod.EventBusSubscriber(Dist.CLIENT) public class GuiMainMenuExtensionDevWorldForgeRegistrar { @@ -15,8 +16,12 @@ public class GuiMainMenuExtensionDevWorldForgeRegistrar { @SubscribeEvent public static void onMainMenuInit(ScreenEvent.Init.Pre event) { // Add a button to the main menu and disable music if we're in a dev environment - if (CyclopsCoreForge._instance.getModHelpers().getMinecraftHelpers().isDevEnvironment()) { + if (IModHelpers.get().getMinecraftHelpers().isDevEnvironment() && GeneralConfig.devWorldButton) { GuiMainMenuExtensionDevWorld.onMainMenuInit(event.getScreen().getMinecraft(), event.getScreen()); + } + + // And disable music + if (IModHelpers.get().getMinecraftHelpers().isDevEnvironment() && GeneralConfig.devDisableMusic) { if (event.getScreen() instanceof TitleScreen) { Minecraft.getInstance().options.getSoundSourceOptionInstance(SoundSource.MUSIC).set(0.0); } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/CyclopsCore.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/CyclopsCore.java index 7b2d571c4a..2a03a25b19 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/CyclopsCore.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/CyclopsCore.java @@ -149,7 +149,9 @@ protected boolean hasDefaultCreativeModeTab() { @Override public void onConfigsRegister(ConfigHandler configHandler) { - configHandler.addConfigurable(new GeneralConfig()); + super.onConfigsRegister(configHandler); + + configHandler.addConfigurable(new GeneralConfig(this)); // Capabilities configHandler.addConfigurable(new FluidHandlerItemCapacityConfig()); diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/GeneralConfig.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/GeneralConfig.java deleted file mode 100644 index c8a9e7d8fb..0000000000 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/GeneralConfig.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.cyclops.cyclopscore; - -import net.neoforged.fml.config.ModConfig; -import org.cyclops.cyclopscore.config.ConfigurableProperty; -import org.cyclops.cyclopscore.config.extendedconfig.DummyConfigCommon; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; -import org.cyclops.cyclopscore.init.ModBase; -import org.cyclops.cyclopscore.tracking.Analytics; -import org.cyclops.cyclopscore.tracking.Versions; - -import java.util.UUID; - -/** - * A config with general options for this mod. - * @author rubensworks - * - */ -public class GeneralConfig extends DummyConfigCommon> { - - @ConfigurableProperty(category = "core", comment = "Set 'true' to enable development debug mode. This will result in a lower performance!", requiresMcRestart = true) - public static boolean debug = false; - - @ConfigurableProperty(category = "core", comment = "If the recipe loader should crash when finding invalid recipes.", requiresMcRestart = true) - public static boolean crashOnInvalidRecipe = false; - - @ConfigurableProperty(category = "core", comment = "If mod compatibility loader should crash hard if errors occur in that process.", requiresMcRestart = true) - public static boolean crashOnModCompatCrash = false; - - @ConfigurableProperty(category = "core", comment = "If an anonymous mod startup analytics request may be sent to our analytics service.") - public static boolean analytics = true; - - @ConfigurableProperty(category = "core", comment = "The anonymous id used by the analytics service.") - public static String anonymousAnalyticsID = UUID.randomUUID().toString(); - - @ConfigurableProperty(category = "core", comment = "If the version checker should be enabled.") - public static boolean versionChecker = true; - - @ConfigurableProperty(category = "general", comment = "If a button should be added to the main menu to open a dev world (shift-click creates a new world).", configLocation = ModConfig.Type.CLIENT) - public static boolean devWorldButton = MinecraftHelpers.isDevEnvironment(); - - @ConfigurableProperty(category = "general", comment = "If music should be disabled at startup.", configLocation = ModConfig.Type.CLIENT) - public static boolean devDisableMusic = MinecraftHelpers.isDevEnvironment(); - - /** - * Create a new instance. - */ - public GeneralConfig() { - super(CyclopsCore._instance, "general"); - } - - @Override - public void onRegistered() { - getMod().putGenericReference(ModBase.REFKEY_CRASH_ON_INVALID_RECIPE, GeneralConfig.crashOnInvalidRecipe); - getMod().putGenericReference(ModBase.REFKEY_CRASH_ON_MODCOMPAT_CRASH, GeneralConfig.crashOnModCompatCrash); - - if(analytics) { - Analytics.registerMod(getMod(), Reference.GA_TRACKING_ID); - } - if(versionChecker) { - Versions.registerMod(getMod(), CyclopsCore._instance, "https://raw.githubusercontent.com/CyclopsMC/Versions/master/" + getMod().getModHelpers().getMinecraftHelpers().getMinecraftVersionMajorMinor() + "/CyclopsCore.txt"); - } - } - -} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/GeneralConfigNeoForge.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/GeneralConfigNeoForge.java new file mode 100644 index 0000000000..cada6ab597 --- /dev/null +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/GeneralConfigNeoForge.java @@ -0,0 +1,24 @@ +package org.cyclops.cyclopscore; + +import org.cyclops.cyclopscore.init.ModBase; +import org.cyclops.cyclopscore.tracking.Analytics; +import org.cyclops.cyclopscore.tracking.Versions; + +/** + * @author rubensworks + */ +public class GeneralConfigNeoForge extends GeneralConfig { + public GeneralConfigNeoForge() { + super(CyclopsCore._instance); + } + + @Override + public void onRegistered() { + if(analytics) { + Analytics.registerMod((ModBase) getMod(), Reference.GA_TRACKING_ID); + } + if(versionChecker) { + Versions.registerMod((ModBase) getMod(), CyclopsCore._instance, "https://raw.githubusercontent.com/CyclopsMC/Versions/master/" + getMod().getModHelpers().getMinecraftHelpers().getMinecraftVersionMajorMinor() + "/CyclopsCore.txt"); + } + } +} diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldNeoForgeRegistrar.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldNeoForgeRegistrar.java index f25ff9753b..d6f5f2f6a6 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldNeoForgeRegistrar.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/client/gui/GuiMainMenuExtensionDevWorldNeoForgeRegistrar.java @@ -8,6 +8,7 @@ import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.client.event.ScreenEvent; import org.cyclops.cyclopscore.GeneralConfig; +import org.cyclops.cyclopscore.helper.IModHelpers; @EventBusSubscriber(Dist.CLIENT) public class GuiMainMenuExtensionDevWorldNeoForgeRegistrar { @@ -15,12 +16,12 @@ public class GuiMainMenuExtensionDevWorldNeoForgeRegistrar { @SubscribeEvent public static void onMainMenuInit(ScreenEvent.Init.Pre event) { // Add a button to the main menu if we're in a dev environment - if (GeneralConfig.devWorldButton) { + if (IModHelpers.get().getMinecraftHelpers().isDevEnvironment() && GeneralConfig.devWorldButton) { GuiMainMenuExtensionDevWorld.onMainMenuInit(event.getScreen().getMinecraft(), event.getScreen()); } // And disable music - if (GeneralConfig.devDisableMusic) { + if (IModHelpers.get().getMinecraftHelpers().isDevEnvironment() && GeneralConfig.devDisableMusic) { if (event.getScreen() instanceof TitleScreen) { Minecraft.getInstance().options.getSoundSourceOptionInstance(SoundSource.MUSIC).set(0.0); }