fixed not getting the correct allocated memory

This commit is contained in:
2024-10-05 20:41:19 +02:00
parent f4c4842188
commit 0e270085f9
4 changed files with 8 additions and 6 deletions

View File

@@ -9,7 +9,7 @@ yarn_mappings=1.21.1+build.3
loader_version=0.16.5 loader_version=0.16.5
# Mod Properties # Mod Properties
mod_version=1.0.0-fabric-1.21.1 mod_version=1.1.0-fabric-1.21.1
maven_group=com.vaporvee.loadsupport maven_group=com.vaporvee.loadsupport
archives_base_name=loadsupport archives_base_name=loadsupport

View File

@@ -16,7 +16,8 @@ public class LoadSupportClient implements ClientModInitializer {
public void onInitializeClient() { public void onInitializeClient() {
AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new); AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(LSConfig.class).getConfig(); config = AutoConfig.getConfigHolder(LSConfig.class).getConfig();
allocatedMemoryInGB = Runtime.getRuntime().totalMemory() / 1073741824f; // Hardcoded value for GB allocatedMemoryInGB = Runtime.getRuntime().maxMemory() / 1073741824f; // Hardcoded value for GB
allocatedMemoryInGB = Math.round(allocatedMemoryInGB * 10) / 10f;
LoadSupport.logger.info(String.format("Allocated Memory: %.1f GB", allocatedMemoryInGB)); LoadSupport.logger.info(String.format("Allocated Memory: %.1f GB", allocatedMemoryInGB));
ScreenEvents.BEFORE_INIT.register(LoadSupportClient::beforeWindowInit); ScreenEvents.BEFORE_INIT.register(LoadSupportClient::beforeWindowInit);
} }
@@ -24,7 +25,7 @@ public class LoadSupportClient implements ClientModInitializer {
public static String[] getWarningMessage(){ public static String[] getWarningMessage(){
return new String[]{config.errorTitle, config.errorDescription return new String[]{config.errorTitle, config.errorDescription
.replace("{minMemory}", String.valueOf(config.minMemory)) .replace("{minMemory}", String.valueOf(config.minMemory))
.replace("{currentMemory}", String.format("%.1f", allocatedMemoryInGB))}; .replace("{currentMemory}", String.valueOf(allocatedMemoryInGB))};
}; };
private static void beforeWindowInit(MinecraftClient minecraftClient, Screen screen, int i, int i1) { private static void beforeWindowInit(MinecraftClient minecraftClient, Screen screen, int i, int i1) {
if(config.minMemory > allocatedMemoryInGB){ if(config.minMemory > allocatedMemoryInGB){

View File

@@ -34,7 +34,7 @@ mod_name=Load Support
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=Apache License 2.0 mod_license=Apache License 2.0
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=1.0.0-neoforge-1.21.1 mod_version=1.1.0-neoforge-1.21.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View File

@@ -34,7 +34,8 @@ public class LoadSupport
{ {
AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new); AutoConfig.register(LSConfig.class, Toml4jConfigSerializer::new);
config = AutoConfig.getConfigHolder(LSConfig.class).getConfig(); config = AutoConfig.getConfigHolder(LSConfig.class).getConfig();
allocatedMemoryInGB = Runtime.getRuntime().totalMemory() / 1073741824f; // Hardcoded value for GB allocatedMemoryInGB = Runtime.getRuntime().maxMemory() / 1073741824f; // Hardcoded value for GB
allocatedMemoryInGB = Math.round(allocatedMemoryInGB * 10) / 10f;
LoadSupport.logger.info(String.format("Allocated Memory: %.1f GB", allocatedMemoryInGB)); LoadSupport.logger.info(String.format("Allocated Memory: %.1f GB", allocatedMemoryInGB));
ScreenEvents.BEFORE_INIT.register(LoadSupport::beforeWindowInit); ScreenEvents.BEFORE_INIT.register(LoadSupport::beforeWindowInit);
} }
@@ -52,6 +53,6 @@ public class LoadSupport
public static String[] getWarningMessage(){ public static String[] getWarningMessage(){
return new String[]{config.errorTitle, config.errorDescription return new String[]{config.errorTitle, config.errorDescription
.replace("{minMemory}", String.valueOf(config.minMemory)) .replace("{minMemory}", String.valueOf(config.minMemory))
.replace("{currentMemory}", String.format("%.1f", allocatedMemoryInGB))}; .replace("{currentMemory}", String.valueOf(allocatedMemoryInGB))};
}; };
} }