Skip to content

Commit

Permalink
Adjust lithium compat to also support RoadRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
malte0811 committed Apr 10, 2022
1 parent da1247a commit a71ef9e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,23 @@
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
Expand All @@ -48,7 +40,7 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
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 {
Expand All @@ -75,4 +67,28 @@ public void preApply(String targetClassName, ClassNode targetClass, String mixin

@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;
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

public class Config extends FerriteMixinConfig {
public Config() {
super(FerriteConfig.THREADING_DETECTOR, true);
super(FerriteConfig.THREADING_DETECTOR, LithiumSupportState.APPLY_IF_ROADRUNNER);
}
}
1 change: 1 addition & 0 deletions forge/src/main/resources/roadrunner.overrides.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mixin.alloc.blockstate = false

0 comments on commit a71ef9e

Please sign in to comment.