ported and updated cloth /config and added basic ram allocation checking
This commit is contained in:
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;
|
||||
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
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;
|
||||
|
||||
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> T load(Class<T> 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;
|
||||
|
||||
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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user