Răsfoiți Sursa

Disable ThreadingDetector Mixin when Lithium is present
Lithium completely removes the ThreadingDetector functionality, so it's
both faster and has lower memory usage than FCs (fully functional)
implementation

malte0811 3 ani în urmă
părinte
comite
e21c878481

+ 27 - 1
common/src/main/java/malte0811/ferritecore/mixin/config/FerriteMixinConfig.java

@@ -6,17 +6,40 @@ import org.apache.logging.log4j.Logger;
 import org.objectweb.asm.tree.ClassNode;
 import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
 import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
+import org.spongepowered.asm.service.MixinService;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Set;
 
 public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
     protected static final Logger LOGGER = LogManager.getLogger("ferritecore-mixin");
+    private static final boolean HAS_LITHIUM;
+
+    static {
+        boolean hasLithium;
+        try {
+            // This does *not* load the class!
+            MixinService.getService()
+                    .getBytecodeProvider()
+                    .getClassNode("me.jellysquid.mods.lithium.common.LithiumMod");
+            hasLithium = true;
+        } catch (ClassNotFoundException | IOException e) {
+            hasLithium = false;
+        }
+        HAS_LITHIUM = hasLithium;
+    }
     private String prefix = null;
     private final FerriteConfig.Option enableOption;
+    private final boolean disableWithLithium;
 
-    protected FerriteMixinConfig(FerriteConfig.Option enableOption) {
+    protected FerriteMixinConfig(FerriteConfig.Option enableOption, boolean disableWithLithium) {
         this.enableOption = enableOption;
+        this.disableWithLithium = disableWithLithium;
+    }
+
+    protected FerriteMixinConfig(FerriteConfig.Option enableOption) {
+        this(enableOption, false);
     }
 
     @Override
@@ -25,6 +48,9 @@ public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
         if (!enableOption.isEnabled()) {
             LOGGER.warn("Mixin " + mixinClassName + " is disabled by config");
             return false;
+        } else if (disableWithLithium && HAS_LITHIUM) {
+            LOGGER.warn("Mixin " + mixinClassName + " is disabled automatically as lithium is installed");
+            return false;
         } else {
             return true;
         }

+ 1 - 1
common/src/main/java/malte0811/ferritecore/mixin/threaddetec/Config.java

@@ -5,6 +5,6 @@ import malte0811.ferritecore.mixin.config.FerriteMixinConfig;
 
 public class Config extends FerriteMixinConfig {
     public Config() {
-        super(FerriteConfig.THREADING_DETECTOR);
+        super(FerriteConfig.THREADING_DETECTOR, true);
     }
 }