Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Fix compatibility with VanillaFIX and Phosphor-Forge
Browse files Browse the repository at this point in the history
 - Update SpongeMixin version to 8.1-SNAPSHOT
 - Properly reload Mixin on MixinLoader.java
  • Loading branch information
EverNife committed Sep 28, 2020
1 parent 6314e80 commit 31b8530
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'idea'
apply plugin: 'maven'

group = 'io.github.crucible'
version = '1.12.2-1.0.3a'
version = '1.12.2-1.0.4a'

archivesBaseName = "[0]Grimoire"

Expand Down Expand Up @@ -44,7 +44,7 @@ repositories {
}

dependencies {
shade("org.spongepowered:mixin:0.8-SNAPSHOT") {
shade("org.spongepowered:mixin:0.8.1-SNAPSHOT") {
exclude module: "launchwrapper"
exclude module: 'guava'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
import org.spongepowered.asm.mixin.transformer.MixinProcessor;
import org.spongepowered.asm.mixin.transformer.Proxy;

import java.lang.reflect.Field;
Expand All @@ -36,7 +36,6 @@ public class MixinLoader {
@Inject(method = "loadMods", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/LoadController;transition(Lnet/minecraftforge/fml/common/LoaderState;Z)V", ordinal = 1), remap = false)
private void beforeConstructingMods(CallbackInfo ci) {
// Add all mods to class loader

for (ModContainer mod : mods) {
try {
modClassLoader.addFile(mod.getSource());
Expand All @@ -47,14 +46,27 @@ private void beforeConstructingMods(CallbackInfo ci) {

Grimoire.instance.loadAllMixins();//Add all configs

//Reload the Mixin!
Proxy mixinProxy = (Proxy) Launch.classLoader.getTransformers().stream().filter(transformer -> transformer instanceof Proxy).findFirst().get();
try {
//This will very likely break on the next major mixin release.
Class mixinTransformerClass = Class.forName("org.spongepowered.asm.mixin.transformer.MixinTransformer");

Field transformerField = Proxy.class.getDeclaredField("transformer");
transformerField.setAccessible(true);
IMixinTransformer transformer = (IMixinTransformer) transformerField.get(mixinProxy);
Object transformer = transformerField.get(mixinProxy);

//Get MixinProcessor from MixinTransformer
Field processorField = mixinTransformerClass.getDeclaredField("processor");
processorField.setAccessible(true);
Object processor = processorField.get(transformer);

Method selectConfigsMethod = MixinProcessor.class.getDeclaredMethod("selectConfigs", MixinEnvironment.class);
selectConfigsMethod.setAccessible(true);
selectConfigsMethod.invoke(processor, MixinEnvironment.getCurrentEnvironment());

transformer.audit(MixinEnvironment.getCurrentEnvironment());
Method prepareConfigsMethod = MixinProcessor.class.getDeclaredMethod("prepareConfigs", MixinEnvironment.class);
prepareConfigsMethod.setAccessible(true);
prepareConfigsMethod.invoke(processor, MixinEnvironment.getCurrentEnvironment());
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/mixins/mixins.grimoire.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"server": [],
"client": [],
"compatibilityLevel": "JAVA_8",
"minVersion": "0.7.11",
"minVersion": "0.8.0",
"target": "@env(PREINIT)",
"refmap":"grimoire.refmap.json"
}

0 comments on commit 31b8530

Please sign in to comment.