Browse Source

Adjust lithium compat to also support RoadRunner

malte0811 3 năm trước cách đây
mục cha
commit
a71ef9ef15

+ 32 - 16
common/src/main/java/malte0811/ferritecore/mixin/config/FerriteMixinConfig.java

@@ -15,31 +15,23 @@ 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;
+    private static final boolean HAS_ROADRUNNER;
 
     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;
+        HAS_LITHIUM = hasClass("me.jellysquid.mods.lithium.common.LithiumMod");
+        HAS_ROADRUNNER = hasClass("me.jellysquid.mods.lithium.common.RoadRunner");
     }
     private String prefix = null;
     private final FerriteConfig.Option enableOption;
-    private final boolean disableWithLithium;
+    private final LithiumSupportState lithiumState;
 
-    protected FerriteMixinConfig(FerriteConfig.Option enableOption, boolean disableWithLithium) {
+    protected FerriteMixinConfig(FerriteConfig.Option enableOption, LithiumSupportState lithiumCompat) {
         this.enableOption = enableOption;
-        this.disableWithLithium = disableWithLithium;
+        this.lithiumState = lithiumCompat;
     }
 
     protected FerriteMixinConfig(FerriteConfig.Option enableOption) {
-        this(enableOption, false);
+        this(enableOption, LithiumSupportState.NO_CONFLICT);
     }
 
     @Override
@@ -48,7 +40,7 @@ public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
         if (!enableOption.isEnabled()) {
             LOGGER.warn("Mixin " + mixinClassName + " is disabled by config");
             return false;
-        } else if (disableWithLithium && HAS_LITHIUM) {
+        } else if (!this.lithiumState.shouldApply()) {
             LOGGER.warn("Mixin " + mixinClassName + " is disabled automatically as lithium is installed");
             return false;
         } else {
@@ -75,4 +67,28 @@ public abstract class FerriteMixinConfig implements IMixinConfigPlugin {
 
     @Override
     public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {}
+
+    private static boolean hasClass(String name) {
+        try {
+            // This does *not* load the class!
+            MixinService.getService().getBytecodeProvider().getClassNode(name);
+            return true;
+        } catch (ClassNotFoundException | IOException e) {
+            return false;
+        }
+    }
+
+    protected enum LithiumSupportState {
+        NO_CONFLICT,
+        INCOMPATIBLE,
+        APPLY_IF_ROADRUNNER;
+
+        private boolean shouldApply() {
+            return switch (this) {
+                case NO_CONFLICT -> true;
+                case INCOMPATIBLE -> !HAS_LITHIUM;
+                case APPLY_IF_ROADRUNNER -> !HAS_LITHIUM || HAS_ROADRUNNER;
+            };
+        }
+    }
 }

+ 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, true);
+        super(FerriteConfig.THREADING_DETECTOR, LithiumSupportState.APPLY_IF_ROADRUNNER);
     }
 }

+ 1 - 0
forge/src/main/resources/roadrunner.overrides.properties

@@ -0,0 +1 @@
+mixin.alloc.blockstate = false