From bd177ae0bc18717899d5be245521b9f9866eb471 Mon Sep 17 00:00:00 2001 From: bombcar Date: Fri, 31 Dec 2021 22:37:18 -0600 Subject: [PATCH 1/5] add an early low memory error to GTNH --- gradle.properties | 10 +-- .../core/launch/CodeChickenCorePlugin.java | 65 ++++++++++++++++++- .../codechicken/core/launch/DepLoader.java | 2 +- 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6f45dd6..55f3a6d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,15 +15,15 @@ autoUpdateBuildScript = false minecraftVersion = 1.7.10 forgeVersion = 10.13.4.1614 -# Select a username for testing your mod with breakpoints. You may leave this empty for a random user name each time you +# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you # restart Minecraft in development. Choose this dependent on your mod: # Do you need consistent player progressing (for example Thaumcraft)? -> Select a name # Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty -developmentEnvironmentUserName = "Developer" +developmentEnvironmentUserName = Developer # Define a source file of your project with: # public static final String VERSION = "GRADLETOKEN_VERSION"; -# The string's content will be replaced with your mods version when compiled. You should use this to specify your mod's +# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's # version in @Mod([...], version = VERSION, [...]) # Leave these properties empty to skip individual token replacements replaceGradleTokenInFile = CodeChickenCoreModContainer.java @@ -32,7 +32,7 @@ gradleTokenModName = GRADLETOKEN_MODNAME gradleTokenVersion = GRADLETOKEN_VERSION gradleTokenGroupName = -# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise you can +# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can # leave this property empty. # Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api apiPackage = @@ -48,7 +48,7 @@ mixinPlugin = # Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail! mixinsPackage = # Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin! -# This parameter is for legacy compatability only +# This parameter is for legacy compatibility only # Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin coreModClass = core.launch.CodeChickenCorePlugin # If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class diff --git a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java index 5ff5ebf..d572898 100644 --- a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java +++ b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java @@ -1,9 +1,12 @@ package codechicken.core.launch; -import java.awt.Desktop; +import java.awt.*; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.text.CharacterIterator; +import java.text.NumberFormat; +import java.text.StringCharacterIterator; import java.util.List; import java.util.Map; import java.util.jar.Attributes; @@ -16,6 +19,7 @@ import javax.swing.event.HyperlinkEvent; import javax.swing.event.HyperlinkListener; import codechicken.core.asm.*; +import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.CoreModManager; import cpw.mods.fml.common.versioning.DefaultArtifactVersion; @@ -91,6 +95,64 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook } } + public static long parseSize(String text) { + double d = Double.parseDouble(text.replaceAll("[GMK]B?$", "")); + long l = Math.round(d * 1024 * 1024 * 1024L); + switch (text.replaceAll("\\d?","").toUpperCase().charAt(0)) { + default: l /= 1024; + case 'K': l /= 1024; + case 'M': l /= 1024; + case 'G': return l; + } + } + + public static String humanReadableByteCountBin(long bytes) { + long absB = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes); + if (absB < 1024) { + return bytes + " B"; + } + long value = absB; + CharacterIterator ci = new StringCharacterIterator("KMGTPE"); + for (int i = 40; i >= 0 && absB > 0xfffccccccccccccL >> i; i -= 10) { + value >>= 10; + ci.next(); + } + value *= Long.signum(bytes); + return String.format("%.1f %ciB", value / 1024.0, ci.current()); + } + + public static void systemCheck(String minRAM) { + long minBytes = parseSize(minRAM); + if (Runtime.getRuntime().maxMemory() < minBytes) { + String err = "You should have at least " + minRAM + "of RAM but you have only allocated " + humanReadableByteCountBin(Runtime.getRuntime().maxMemory()) + "."; + logger.error(err); + + JEditorPane ep = new JEditorPane("text/html", + "" + + err + + "
GTNH seriously won't run without enough RAM. See the Wiki for details." + + "
Recommended values are between 4GB and 6GB. Check your launcher's JVM arguments." + + ""); + + ep.setEditable(false); + ep.setOpaque(false); + ep.addHyperlinkListener(new HyperlinkListener() + { + @Override + public void hyperlinkUpdate(HyperlinkEvent event) { + try { + if (event.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) + Desktop.getDesktop().browse(event.getURL().toURI()); + } catch (Exception ignored) {} + } + }); + + if (!GraphicsEnvironment.isHeadless()) + JOptionPane.showMessageDialog(null, ep, "lol nope", JOptionPane.ERROR_MESSAGE); + FMLCommonHandler.instance().exitJava(-99, true); + } + } + @Override public String[] getASMTransformerClass() { versionCheck(mcVersion, "CodeChickenCore"); @@ -124,6 +186,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook @Override public Void call() { CodeChickenCoreModContainer.loadConfig(); + systemCheck(CodeChickenCoreModContainer.config.getTag("minRAM").getValue("3GB")); TweakTransformer.load(); scanCodeChickenMods(); diff --git a/src/main/java/codechicken/core/launch/DepLoader.java b/src/main/java/codechicken/core/launch/DepLoader.java index c4f46b5..bf4e7d7 100644 --- a/src/main/java/codechicken/core/launch/DepLoader.java +++ b/src/main/java/codechicken/core/launch/DepLoader.java @@ -186,7 +186,7 @@ public class DepLoader implements IFMLLoadingPlugin, IFMLCallHook { } }); - JOptionPane.showMessageDialog(null, ep, "A download error has occured", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, ep, "A download error has occurred", JOptionPane.ERROR_MESSAGE); } } From 6aa549db9ac6b567cb7e4f36a9ca8622ec088155 Mon Sep 17 00:00:00 2001 From: bombcar Date: Fri, 31 Dec 2021 22:41:20 -0600 Subject: [PATCH 2/5] typo --- .../java/codechicken/core/launch/CodeChickenCorePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java index d572898..00bd76d 100644 --- a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java +++ b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java @@ -124,7 +124,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook public static void systemCheck(String minRAM) { long minBytes = parseSize(minRAM); if (Runtime.getRuntime().maxMemory() < minBytes) { - String err = "You should have at least " + minRAM + "of RAM but you have only allocated " + humanReadableByteCountBin(Runtime.getRuntime().maxMemory()) + "."; + String err = "You should have at least " + minRAM + " of RAM but you have only allocated " + humanReadableByteCountBin(Runtime.getRuntime().maxMemory()) + "."; logger.error(err); JEditorPane ep = new JEditorPane("text/html", From 3adeff110faf6b353829901f9ea07cfa974f6537 Mon Sep 17 00:00:00 2001 From: bombcar Date: Sat, 1 Jan 2022 01:37:59 -0600 Subject: [PATCH 3/5] update exit code --- .../java/codechicken/core/launch/CodeChickenCorePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java index 00bd76d..4dc82e5 100644 --- a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java +++ b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java @@ -149,7 +149,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook if (!GraphicsEnvironment.isHeadless()) JOptionPane.showMessageDialog(null, ep, "lol nope", JOptionPane.ERROR_MESSAGE); - FMLCommonHandler.instance().exitJava(-99, true); + FMLCommonHandler.instance().exitJava(-98, true); } } From 352301c8eaad5144175147e78333afec8f9363bd Mon Sep 17 00:00:00 2001 From: bombcar Date: Sat, 1 Jan 2022 01:49:42 -0600 Subject: [PATCH 4/5] use GB instead of GiB --- .../java/codechicken/core/launch/CodeChickenCorePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java index 4dc82e5..40d7c1e 100644 --- a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java +++ b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java @@ -118,7 +118,7 @@ public class CodeChickenCorePlugin implements IFMLLoadingPlugin, IFMLCallHook ci.next(); } value *= Long.signum(bytes); - return String.format("%.1f %ciB", value / 1024.0, ci.current()); + return String.format("%.1f %cB", value / 1024.0, ci.current()); } public static void systemCheck(String minRAM) { From 0fc1466f9c4e3d10f6572a22bd1d51737992d9b9 Mon Sep 17 00:00:00 2001 From: bombcar Date: Sat, 1 Jan 2022 01:50:58 -0600 Subject: [PATCH 5/5] remove unused import --- src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java index 40d7c1e..284b84d 100644 --- a/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java +++ b/src/main/java/codechicken/core/launch/CodeChickenCorePlugin.java @@ -5,7 +5,6 @@ import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.text.CharacterIterator; -import java.text.NumberFormat; import java.text.StringCharacterIterator; import java.util.List; import java.util.Map;