Skip to content

Commit

Permalink
Move GeneralConfig to common
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Aug 12, 2024
1 parent d06293d commit e2c2927
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -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<ModBaseCommon<?>> {

@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");
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,14 +13,14 @@
* The main mod class of CyclopsCore.
* @author rubensworks
*/
public class CyclopsCoreMainFabric extends ModBaseFabric<CyclopsCoreMainFabric> implements ModInitializer {
public class CyclopsCoreFabric extends ModBaseFabric<CyclopsCoreFabric> 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;
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
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
*/
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -20,7 +20,7 @@ public boolean isDevEnvironment() {

@Override
public boolean isMinecraftInitialized() {
return CyclopsCoreMainFabric._instance.isLoaded();
return CyclopsCoreFabric._instance.isLoaded();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,7 +15,7 @@
public class ItemInformationProviderFabric extends ItemInformationProviderCommon {
public static void onTooltip(ItemStack itemStack, Item.TooltipContext tooltipContext, TooltipFlag tooltipFlag, List<Component> lines) {
if (ITEMS_INFO.contains(itemStack.getItem())) {
CyclopsCoreMainFabric._instance.getModHelpers().getL10NHelpers().addOptionalInfo(lines, itemStack.getDescriptionId());
CyclopsCoreFabric._instance.getModHelpers().getL10NHelpers().addOptionalInfo(lines, itemStack.getDescriptionId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,7 +21,7 @@ public ClientProxyFabric() {

@Override
public ModBaseFabric<?> getMod() {
return CyclopsCoreMainFabric._instance;
return CyclopsCoreFabric._instance;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -12,7 +12,7 @@ public class CommonProxyFabric extends CommonProxyComponentFabric {

@Override
public ModBaseFabric<?> getMod() {
return CyclopsCoreMainFabric._instance;
return CyclopsCoreFabric._instance;
}

}
2 changes: 1 addition & 1 deletion loader-fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"environment": "*",
"entrypoints": {
"main": [
"org.cyclops.cyclopscore.CyclopsCoreMainFabric"
"org.cyclops.cyclopscore.CyclopsCoreFabric"
],
"client": [
"org.cyclops.cyclopscore.CyclopsCoreClientFabric"
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
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 {

@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@
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 {

@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);
}
Expand Down

0 comments on commit e2c2927

Please sign in to comment.