diff --git a/common/build.gradle b/common/build.gradle index 24540d2..56bb2c4 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -16,7 +16,12 @@ neoForge { } } +repositories { + maven { url "https://maven.shedaniel.me/" } +} + dependencies { + compileOnly "me.shedaniel.cloth:cloth-config-neoforge:18.0.145" compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5' // fabric and neoforge both bundle mixinextras, so it is safe to use it in common compileOnly group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5' diff --git a/common/src/main/java/com/vaporvee/loadsupport/Allocated.java b/common/src/main/java/com/vaporvee/loadsupport/Allocated.java new file mode 100644 index 0000000..327edc7 --- /dev/null +++ b/common/src/main/java/com/vaporvee/loadsupport/Allocated.java @@ -0,0 +1,12 @@ +package com.vaporvee.loadsupport; + +public class Allocated { + public static float memoryInGB; + public static void init(){ + memoryInGB = Runtime.getRuntime().maxMemory() / Constants.GIGABYTE; + memoryInGB = Math.round(Allocated.memoryInGB * 10) / 10f; + } + public static void printAllocated() { + Constants.LOG.info(String.format("Allocated Memory: %.1f GB", memoryInGB)); + } +} diff --git a/common/src/main/java/com/vaporvee/loadsupport/CommonClass.java b/common/src/main/java/com/vaporvee/loadsupport/CommonClass.java index e500a67..70eae69 100644 --- a/common/src/main/java/com/vaporvee/loadsupport/CommonClass.java +++ b/common/src/main/java/com/vaporvee/loadsupport/CommonClass.java @@ -1,18 +1,29 @@ package com.vaporvee.loadsupport; import com.vaporvee.loadsupport.platform.Services; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.item.Items; public class CommonClass { public static void init() { - // Constants.LOG.info("Hello from Common init on {}! we are currently in a {} environment!", Services.PLATFORM.getPlatformName(), Services.PLATFORM.getEnvironmentName()); - // Constants.LOG.info("The ID for diamonds is {}", BuiltInRegistries.ITEM.getKey(Items.DIAMOND)); - // if (Services.PLATFORM.isModLoaded("loadsupport")) if (Services.PLATFORM.isEnvServer()) { Constants.LOG.info(Constants.MOD_ID + " is a client mod only!"); return; } Constants.LOG.info("Loading Load Support mod."); + Allocated.init(); + Allocated.printAllocated(); + Services.CONFIG.InitConfig(); + } + public static void checkConfig(LSConfig config) { + Constants.LOG.info("Load config test!"); + if (config != null) { + if(config.minMemory > Allocated.memoryInGB){ + System.setProperty("java.awt.headless", "false"); + Constants.LOG.info("Not enough memory! Allocated memory in GB is {} but set in config is {}", + Allocated.memoryInGB, config.minMemory); + //create jframe window + } + } else { + Constants.LOG.info("Load config is null!"); + } } } \ No newline at end of file diff --git a/common/src/main/java/com/vaporvee/loadsupport/Constants.java b/common/src/main/java/com/vaporvee/loadsupport/Constants.java index d068a68..5d87f42 100644 --- a/common/src/main/java/com/vaporvee/loadsupport/Constants.java +++ b/common/src/main/java/com/vaporvee/loadsupport/Constants.java @@ -8,4 +8,5 @@ public class Constants { public static final String MOD_ID = "loadsupport"; public static final String MOD_NAME = "LoadSupport"; public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME); + public static final float GIGABYTE = 1073741824f; } \ No newline at end of file diff --git a/common/src/main/java/com/vaporvee/loadsupport/LSConfig.java b/common/src/main/java/com/vaporvee/loadsupport/LSConfig.java new file mode 100644 index 0000000..d9b446d --- /dev/null +++ b/common/src/main/java/com/vaporvee/loadsupport/LSConfig.java @@ -0,0 +1,12 @@ +package com.vaporvee.loadsupport; + +import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.annotation.Config; + +@Config(name = Constants.MOD_ID) +public class LSConfig implements ConfigData { + boolean startSound = true; + float minMemory = 4.0f; + String errorTitle = "Error: Not enough Java memory!"; + String errorDescription = "Please allocate at least {minMemory} GB of Java memory to your Minecraft Instance! You have currently {currentMemory} GB allocated."; +} diff --git a/common/src/main/java/com/vaporvee/loadsupport/platform/Services.java b/common/src/main/java/com/vaporvee/loadsupport/platform/Services.java index 436b9fe..c820d75 100644 --- a/common/src/main/java/com/vaporvee/loadsupport/platform/Services.java +++ b/common/src/main/java/com/vaporvee/loadsupport/platform/Services.java @@ -1,24 +1,17 @@ package com.vaporvee.loadsupport.platform; import com.vaporvee.loadsupport.Constants; +import com.vaporvee.loadsupport.platform.services.IConfig; import com.vaporvee.loadsupport.platform.services.IPlatformHelper; import java.util.ServiceLoader; -// Service loaders are a built-in Java feature that allow us to locate implementations of an interface that vary from one -// environment to another. In the context of MultiLoader we use this feature to access a mock API in the common code that -// is swapped out for the platform specific implementation at runtime. public class Services { - // In this example we provide a platform helper which provides information about what platform the mod is running on. - // For example this can be used to check if the code is running on Forge vs Fabric, or to ask the modloader if another - // mod is loaded. public static final IPlatformHelper PLATFORM = load(IPlatformHelper.class); - // This code is used to load a service for the current environment. Your implementation of the service must be defined - // manually by including a text file in META-INF/services named with the fully qualified class name of the service. - // Inside the file you should write the fully qualified class name of the implementation to load for the platform. For - // example our file on Forge points to ForgePlatformHelper while Fabric points to FabricPlatformHelper. + public static final IConfig CONFIG = load(IConfig.class); + public static T load(Class clazz) { final T loadedService = ServiceLoader.load(clazz) diff --git a/common/src/main/java/com/vaporvee/loadsupport/platform/services/IConfig.java b/common/src/main/java/com/vaporvee/loadsupport/platform/services/IConfig.java new file mode 100644 index 0000000..46c6109 --- /dev/null +++ b/common/src/main/java/com/vaporvee/loadsupport/platform/services/IConfig.java @@ -0,0 +1,10 @@ +package com.vaporvee.loadsupport.platform.services; + +import com.vaporvee.loadsupport.LSConfig; + +public interface IConfig { + /** + * Initializes config on available platforms + */ + void InitConfig(); +} diff --git a/common/src/main/java/com/vaporvee/loadsupport/platform/services/IPlatformHelper.java b/common/src/main/java/com/vaporvee/loadsupport/platform/services/IPlatformHelper.java index d232689..cebffbc 100644 --- a/common/src/main/java/com/vaporvee/loadsupport/platform/services/IPlatformHelper.java +++ b/common/src/main/java/com/vaporvee/loadsupport/platform/services/IPlatformHelper.java @@ -1,14 +1,12 @@ package com.vaporvee.loadsupport.platform.services; public interface IPlatformHelper { - /** * Gets the name of the current platform * * @return The name of the current platform. */ String getPlatformName(); - /** * Checks if a mod with the given id is loaded. * diff --git a/fabric/build.gradle b/fabric/build.gradle index f4fde12..40d05fe 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -2,6 +2,10 @@ plugins { id 'multiloader-loader' id 'fabric-loom' } +repositories { + maven { url "https://maven.shedaniel.me/" } + maven { url "https://maven.terraformersmc.com/releases/" } +} dependencies { minecraft "com.mojang:minecraft:${minecraft_version}" mappings loom.layered { @@ -10,6 +14,10 @@ dependencies { } modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_version}" + implementation 'com.moandjiezana.toml:toml4j:0.7.2' + modApi("me.shedaniel.cloth:cloth-config-fabric:18.0.145") { + exclude(group: "net.fabricmc.fabric-api") + } } loom { diff --git a/fabric/src/main/java/com/vaporvee/loadsupport/LoadSupport.java b/fabric/src/main/java/com/vaporvee/loadsupport/LoadSupport.java index d0dce3d..106d0e6 100644 --- a/fabric/src/main/java/com/vaporvee/loadsupport/LoadSupport.java +++ b/fabric/src/main/java/com/vaporvee/loadsupport/LoadSupport.java @@ -6,13 +6,6 @@ public class LoadSupport implements ModInitializer { @Override public void onInitialize() { - - // This method is invoked by the Fabric mod loader when it is ready - // to load your mod. You can access Fabric and Common code in this - // project. - - // Use Fabric to bootstrap the Common mod. - Constants.LOG.info("Hello Fabric world!"); CommonClass.init(); } } diff --git a/fabric/src/main/java/com/vaporvee/loadsupport/mixin/MixinTitleScreen.java b/fabric/src/main/java/com/vaporvee/loadsupport/mixin/MixinTitleScreen.java index 8d7f3ab..ec73678 100644 --- a/fabric/src/main/java/com/vaporvee/loadsupport/mixin/MixinTitleScreen.java +++ b/fabric/src/main/java/com/vaporvee/loadsupport/mixin/MixinTitleScreen.java @@ -13,6 +13,6 @@ public class MixinTitleScreen { @Inject(at = @At("HEAD"), method = "init()V") private void init(CallbackInfo info) { - Constants.LOG.info("Mixin MC title Type: {}", Minecraft.getInstance().getVersionType()); + } } \ No newline at end of file diff --git a/fabric/src/main/java/com/vaporvee/loadsupport/platform/LSConfigFabric.java b/fabric/src/main/java/com/vaporvee/loadsupport/platform/LSConfigFabric.java new file mode 100644 index 0000000..f0b6bd0 --- /dev/null +++ b/fabric/src/main/java/com/vaporvee/loadsupport/platform/LSConfigFabric.java @@ -0,0 +1,20 @@ +package com.vaporvee.loadsupport.platform; + +import com.vaporvee.loadsupport.CommonClass; +import com.vaporvee.loadsupport.Constants; +import com.vaporvee.loadsupport.LSConfig; +import com.vaporvee.loadsupport.platform.services.IConfig; +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.annotation.Config; +import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; + +@Config(name = Constants.MOD_ID) +public class LSConfigFabric implements IConfig { + public static LSConfig config; + @Override + public void InitConfig() { + AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new); + config = AutoConfig.getConfigHolder(LSConfig.class).getConfig(); + CommonClass.checkConfig(config); + } +} diff --git a/fabric/src/main/resources/META-INF/services/com.vaporvee.loadsupport.platform.services.IConfig b/fabric/src/main/resources/META-INF/services/com.vaporvee.loadsupport.platform.services.IConfig new file mode 100644 index 0000000..d0b1133 --- /dev/null +++ b/fabric/src/main/resources/META-INF/services/com.vaporvee.loadsupport.platform.services.IConfig @@ -0,0 +1 @@ +com.vaporvee.loadsupport.platform.LSConfigFabric \ No newline at end of file diff --git a/neoforge/build.gradle b/neoforge/build.gradle index ddf9484..396014e 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -3,6 +3,16 @@ plugins { id 'net.neoforged.moddev' } +repositories { + mavenCentral() + maven { url "https://maven.shedaniel.me/" } +} + +dependencies { + implementation 'com.moandjiezana.toml:toml4j:0.7.2' + implementation "me.shedaniel.cloth:cloth-config-neoforge:18.0.145" +} + neoForge { version = neoforge_version // Automatically enable neoforge AccessTransformers if the file exists diff --git a/neoforge/src/main/java/com/vaporvee/loadsupport/LoadSupport.java b/neoforge/src/main/java/com/vaporvee/loadsupport/LoadSupport.java index 76b65e1..98b1e1b 100644 --- a/neoforge/src/main/java/com/vaporvee/loadsupport/LoadSupport.java +++ b/neoforge/src/main/java/com/vaporvee/loadsupport/LoadSupport.java @@ -1,6 +1,7 @@ package com.vaporvee.loadsupport; +import com.vaporvee.loadsupport.platform.Services; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.common.Mod; @@ -8,14 +9,6 @@ import net.neoforged.fml.common.Mod; public class LoadSupport { public LoadSupport(IEventBus eventBus) { - - // This method is invoked by the NeoForge mod loader when it is ready - // to load your mod. You can access NeoForge and Common code in this - // project. - - // Use NeoForge to bootstrap the Common mod. - Constants.LOG.info("Hello NeoForge world!"); CommonClass.init(); - } } \ No newline at end of file diff --git a/neoforge/src/main/java/com/vaporvee/loadsupport/platform/LSConfigNeoForge.java b/neoforge/src/main/java/com/vaporvee/loadsupport/platform/LSConfigNeoForge.java new file mode 100644 index 0000000..93b23ec --- /dev/null +++ b/neoforge/src/main/java/com/vaporvee/loadsupport/platform/LSConfigNeoForge.java @@ -0,0 +1,20 @@ +package com.vaporvee.loadsupport.platform; + +import com.vaporvee.loadsupport.CommonClass; +import com.vaporvee.loadsupport.Constants; +import com.vaporvee.loadsupport.LSConfig; +import com.vaporvee.loadsupport.platform.services.IConfig; +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.annotation.Config; +import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer; + +@Config(name = Constants.MOD_ID) +public class LSConfigNeoForge implements IConfig { + public static LSConfig config; + @Override + public void InitConfig() { + AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new); + config = AutoConfig.getConfigHolder(LSConfig.class).getConfig(); + CommonClass.checkConfig(config); + } +} diff --git a/neoforge/src/main/resources/META-INF/services/com.vaporvee.loadsupport.platform.services.IConfig b/neoforge/src/main/resources/META-INF/services/com.vaporvee.loadsupport.platform.services.IConfig new file mode 100644 index 0000000..4104dc8 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/services/com.vaporvee.loadsupport.platform.services.IConfig @@ -0,0 +1 @@ +com.vaporvee.loadsupport.platform.LSConfigNeoForge \ No newline at end of file