Skip to content

Commit fea4771

Browse files
committed
Fix mods with Mixin not getting loaded
1 parent 1104fd1 commit fea4771

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'eclipse'
44
sourceCompatibility = '1.6'
55
targetCompatibility = '1.6'
66

7-
version = '0.0.1'
7+
version = '0.1.0'
88

99
repositories {
1010
mavenCentral()

src/main/java/com/simon816/sponge/bootstrap/Bootstrap.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public static void main(String[] args) {
5555
private static void removeFromSysArgs() {
5656
// Remove SpongeCoremod from args as we load it ourselves
5757
List<String> coreModsArgs = new ArrayList<String>(Arrays.asList(System.getProperty("fml.coreMods.load", "").split(",")));
58-
while (coreModsArgs.contains(COREMOD)) {
59-
coreModsArgs.remove(COREMOD);
58+
while (coreModsArgs.remove(COREMOD)) {
6059
}
6160
StringBuilder coreMods = new StringBuilder();
6261
for (String cm : coreModsArgs) {
@@ -181,10 +180,27 @@ public static class PostFMLTweaker extends SimpleTweaker {
181180
@Override
182181
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
183182
// Mixin system already loaded early so don't load twice
184-
List<?> tweakClasses = (List<?>) Launch.blackboard.get("TweakClasses");
183+
@SuppressWarnings("unchecked")
184+
List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses");
185+
boolean duplicateMixin = false;
185186
while (tweakClasses.remove("org.spongepowered.asm.launch.MixinTweaker")) {
187+
duplicateMixin = true;
188+
}
189+
// Another mod is using mixin system
190+
if (duplicateMixin) {
191+
try {
192+
// This feels wrong but it works
193+
// For some reason 'register' gets called before 'preInit'
194+
// even though MixinTweaker calls preInit in constructor
195+
Class<?> c = Class.forName("org.spongepowered.asm.launch.MixinBootstrap");
196+
Field init = c.getDeclaredField("initialised");
197+
init.setAccessible(true);
198+
init.set(null, true);
199+
tweakClasses.add("org.spongepowered.asm.launch.MixinTweaker");
200+
} catch (Exception e) {
201+
e.printStackTrace();
202+
}
186203
}
187-
System.out.println(Launch.blackboard);
188204
}
189205
}
190206

0 commit comments

Comments
 (0)