Skip to content

Commit d101e75

Browse files
committed
Fix sponge metadata not loading
Also improve mixin hack.
1 parent b84ecb2 commit d101e75

File tree

2 files changed

+34
-39
lines changed

2 files changed

+34
-39
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
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.6.2'
7+
version = '0.6.3'
88

99
repositories {
1010
mavenCentral()
@@ -28,7 +28,7 @@ dependencies {
2828
compile 'net.minecraftforge:forge:1.12.2-14.23.0.2486:universal'
2929
}
3030

31-
project.ext.supportedVersions = ["1.8.9", "1.10.2", "1.11", "1.11.2", "1.12", "1.12.1", "1.12.2"]
31+
project.ext.supportedVersions = ["1.11.2", "1.12", "1.12.1", "1.12.2"]
3232

3333
task setSupportedVersions(type: Copy) {
3434
from(sourceSets.main.java.srcDirs)

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

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.List;
2121
import java.util.Map;
2222
import java.util.Scanner;
23-
import java.util.jar.Attributes;
23+
import java.util.Set;
2424

2525
public class Bootstrap {
2626

@@ -84,8 +84,8 @@ private static void findAndLoadJars() {
8484
@Override
8585
public boolean accept(File pathname) {
8686
String fn = pathname.getName().toLowerCase();
87-
return fn.endsWith(".jar") && (fn.contains("forge") || fn.contains("ftbserver"))
88-
&& fn.contains("-universal") && supportedVersion(fn);
87+
return fn.endsWith(".jar") && (fn.contains("forge") || fn.contains("ftbserver"))
88+
&& fn.contains("-universal") && supportedVersion(fn);
8989
}
9090
});
9191
spongeJar = findJar(new File(rootDir, "mods"), "sponge", new FileFilter() {
@@ -185,54 +185,49 @@ public void injectIntoClassLoader(LaunchClassLoader classLoader) {
185185
System.arraycopy(rootPlugins, 0, rootPlugins2, 0, rootPlugins.length);
186186
rootPlugins2[rootPlugins.length] = COREMOD;
187187
rootPluginsField.set(null, rootPlugins2);
188-
mixinHackLookAwayNow();
188+
stopMixinReInjection();
189189
logger.info("SpongeCoremod successfully injected into FML");
190190
} catch (Exception e) {
191191
e.printStackTrace();
192192
}
193193
}
194194

195-
private void mixinHackLookAwayNow() throws ReflectiveOperationException {
196-
if (spongeJar == null) { // In dev environment
197-
return;
198-
}
199-
// Stop mixin from trying to load spongeforge for a second time
200-
Class<?> attrClass = Class.forName("org.spongepowered.asm.launch.platform.MainAttributes");
201-
Method mOf = attrClass.getMethod("of", File.class);
202-
mOf.setAccessible(true);
203-
Object inst = mOf.invoke(null, spongeJar);
204-
Field fAttr = attrClass.getDeclaredField("attributes");
205-
fAttr.setAccessible(true);
206-
Attributes attr = (Attributes) fAttr.get(inst);
207-
attr.remove(new Attributes.Name("FMLCorePlugin"));
195+
private void stopMixinReInjection() throws ReflectiveOperationException {
196+
Class<?> agentCls = Class.forName("org.spongepowered.asm.launch.platform.MixinPlatformAgentFML");
197+
Field fcoreMods = agentCls.getDeclaredField("loadedCoreMods");
198+
fcoreMods.setAccessible(true);
199+
@SuppressWarnings("unchecked")
200+
Set<String> loadedCoreMods = (Set<String>) fcoreMods.get(null);
201+
loadedCoreMods.add(COREMOD);
208202
}
203+
209204
}
210205

211206
public static class PostFMLTweaker extends SimpleTweaker {
212207

213208
@Override
214209
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
215-
// Mixin system already loaded early so don't load twice
216-
@SuppressWarnings("unchecked")
217-
List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses");
218-
boolean duplicateMixin = false;
219-
while (tweakClasses.remove("org.spongepowered.asm.launch.MixinTweaker")) {
220-
duplicateMixin = true;
221-
}
222-
// Another mod is using mixin system
223-
if (duplicateMixin) {
224-
try {
225-
// This feels wrong but it works
226-
// For some reason 'register' gets called before 'preInit'
227-
// even though MixinTweaker calls preInit in constructor
228-
Class<?> c = Class.forName("org.spongepowered.asm.launch.MixinBootstrap");
229-
Field init = c.getDeclaredField("initialised");
230-
init.setAccessible(true);
231-
init.set(null, true);
232-
tweakClasses.add("org.spongepowered.asm.launch.MixinTweaker");
233-
} catch (Exception e) {
234-
e.printStackTrace();
210+
// Fix location of jar file
211+
try {
212+
Field fPlugins = CoreModManager.class.getDeclaredField("loadPlugins");
213+
fPlugins.setAccessible(true);
214+
@SuppressWarnings("unchecked")
215+
List<Object> plugins = (List<Object>) fPlugins.get(null);
216+
for (Object plugin : plugins) {
217+
if (plugin.getClass().getName().equals("net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper")) {
218+
Field fName = plugin.getClass().getDeclaredField("name");
219+
fName.setAccessible(true);
220+
String name = (String) fName.get(plugin);
221+
if ("SpongeCoremod".equals(name)) {
222+
Field fLocation = plugin.getClass().getDeclaredField("location");
223+
fLocation.setAccessible(true);
224+
fLocation.set(plugin, (File) spongeJar);
225+
break;
226+
}
227+
}
235228
}
229+
} catch (Exception e) {
230+
e.printStackTrace();
236231
}
237232
}
238233
}

0 commit comments

Comments
 (0)