ported and updated cloth /config and added basic ram allocation checking
This commit is contained in:
@@ -16,7 +16,12 @@ neoForge {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url "https://maven.shedaniel.me/" }
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly "me.shedaniel.cloth:cloth-config-neoforge:18.0.145"
|
||||||
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
|
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
|
// 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'
|
compileOnly group: 'io.github.llamalad7', name: 'mixinextras-common', version: '0.3.5'
|
||||||
|
12
common/src/main/java/com/vaporvee/loadsupport/Allocated.java
Normal file
12
common/src/main/java/com/vaporvee/loadsupport/Allocated.java
Normal file
@@ -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));
|
||||||
|
}
|
||||||
|
}
|
@@ -1,18 +1,29 @@
|
|||||||
package com.vaporvee.loadsupport;
|
package com.vaporvee.loadsupport;
|
||||||
|
|
||||||
import com.vaporvee.loadsupport.platform.Services;
|
import com.vaporvee.loadsupport.platform.Services;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
|
|
||||||
public class CommonClass {
|
public class CommonClass {
|
||||||
public static void init() {
|
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()) {
|
if (Services.PLATFORM.isEnvServer()) {
|
||||||
Constants.LOG.info(Constants.MOD_ID + " is a client mod only!");
|
Constants.LOG.info(Constants.MOD_ID + " is a client mod only!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Constants.LOG.info("Loading Load Support mod.");
|
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!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -8,4 +8,5 @@ public class Constants {
|
|||||||
public static final String MOD_ID = "loadsupport";
|
public static final String MOD_ID = "loadsupport";
|
||||||
public static final String MOD_NAME = "LoadSupport";
|
public static final String MOD_NAME = "LoadSupport";
|
||||||
public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME);
|
public static final Logger LOG = LoggerFactory.getLogger(MOD_NAME);
|
||||||
|
public static final float GIGABYTE = 1073741824f;
|
||||||
}
|
}
|
12
common/src/main/java/com/vaporvee/loadsupport/LSConfig.java
Normal file
12
common/src/main/java/com/vaporvee/loadsupport/LSConfig.java
Normal file
@@ -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.";
|
||||||
|
}
|
@@ -1,24 +1,17 @@
|
|||||||
package com.vaporvee.loadsupport.platform;
|
package com.vaporvee.loadsupport.platform;
|
||||||
|
|
||||||
import com.vaporvee.loadsupport.Constants;
|
import com.vaporvee.loadsupport.Constants;
|
||||||
|
import com.vaporvee.loadsupport.platform.services.IConfig;
|
||||||
import com.vaporvee.loadsupport.platform.services.IPlatformHelper;
|
import com.vaporvee.loadsupport.platform.services.IPlatformHelper;
|
||||||
|
|
||||||
import java.util.ServiceLoader;
|
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 {
|
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);
|
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
|
public static final IConfig CONFIG = load(IConfig.class);
|
||||||
// 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 <T> T load(Class<T> clazz) {
|
public static <T> T load(Class<T> clazz) {
|
||||||
|
|
||||||
final T loadedService = ServiceLoader.load(clazz)
|
final T loadedService = ServiceLoader.load(clazz)
|
||||||
|
@@ -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();
|
||||||
|
}
|
@@ -1,14 +1,12 @@
|
|||||||
package com.vaporvee.loadsupport.platform.services;
|
package com.vaporvee.loadsupport.platform.services;
|
||||||
|
|
||||||
public interface IPlatformHelper {
|
public interface IPlatformHelper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the current platform
|
* Gets the name of the current platform
|
||||||
*
|
*
|
||||||
* @return The name of the current platform.
|
* @return The name of the current platform.
|
||||||
*/
|
*/
|
||||||
String getPlatformName();
|
String getPlatformName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a mod with the given id is loaded.
|
* Checks if a mod with the given id is loaded.
|
||||||
*
|
*
|
||||||
|
@@ -2,6 +2,10 @@ plugins {
|
|||||||
id 'multiloader-loader'
|
id 'multiloader-loader'
|
||||||
id 'fabric-loom'
|
id 'fabric-loom'
|
||||||
}
|
}
|
||||||
|
repositories {
|
||||||
|
maven { url "https://maven.shedaniel.me/" }
|
||||||
|
maven { url "https://maven.terraformersmc.com/releases/" }
|
||||||
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||||
mappings loom.layered {
|
mappings loom.layered {
|
||||||
@@ -10,6 +14,10 @@ dependencies {
|
|||||||
}
|
}
|
||||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${fabric_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 {
|
loom {
|
||||||
|
@@ -6,13 +6,6 @@ public class LoadSupport implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
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();
|
CommonClass.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,6 @@ public class MixinTitleScreen {
|
|||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "init()V")
|
@Inject(at = @At("HEAD"), method = "init()V")
|
||||||
private void init(CallbackInfo info) {
|
private void init(CallbackInfo info) {
|
||||||
Constants.LOG.info("Mixin MC title Type: {}", Minecraft.getInstance().getVersionType());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
com.vaporvee.loadsupport.platform.LSConfigFabric
|
@@ -3,6 +3,16 @@ plugins {
|
|||||||
id 'net.neoforged.moddev'
|
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 {
|
neoForge {
|
||||||
version = neoforge_version
|
version = neoforge_version
|
||||||
// Automatically enable neoforge AccessTransformers if the file exists
|
// Automatically enable neoforge AccessTransformers if the file exists
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package com.vaporvee.loadsupport;
|
package com.vaporvee.loadsupport;
|
||||||
|
|
||||||
|
|
||||||
|
import com.vaporvee.loadsupport.platform.Services;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
|
|
||||||
@@ -8,14 +9,6 @@ import net.neoforged.fml.common.Mod;
|
|||||||
public class LoadSupport {
|
public class LoadSupport {
|
||||||
|
|
||||||
public LoadSupport(IEventBus eventBus) {
|
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();
|
CommonClass.init();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
com.vaporvee.loadsupport.platform.LSConfigNeoForge
|
Reference in New Issue
Block a user