Fix InvalidMixinException before 1.15-snapshot. (#115)

This commit is contained in:
ZekerZhayard authored and GitHub committed 2020-09-02 12:30:25 +08:00
1 parent 67fbcf5cec
commit 2dd69e08da
3 files changed
+83 -4

No files matched your search

+1 -4
View File
@@ -15,9 +15,6 @@
"environment": "client",
"mixins": [
{
"config": "mixins.customskinloader.json",
"environment": "client"
}
"mixins.customskinloader.json"
]
}
@@ -10,6 +10,7 @@
"MixinTileEntitySkull"
],
"refmap": "mixins.customskinloader.refmap.json",
"plugin": "customskinloader.fabric.MixinConfigPlugin",
"injectors": {
"defaultRequire": 1
}
@@ -0,0 +1,81 @@
package customskinloader.fabric;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Set;
import org.apache.commons.io.IOUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
public class MixinConfigPlugin implements IMixinConfigPlugin {
@Override
public void onLoad(String mixinPackage) {
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (!mixinClassName.equals("customskinloader.mixin.MixinThreadDownloadImageData")) {
return true;
}
// ProcessTask didn't exist in ThreadDownloadImageData before 1.15-snapshot, Mixin shouldn't apply this.
try (InputStream is = this.getClass().getResourceAsStream("/" + targetClassName.replace(".", "/") + ".class")) {
if (is == null) {
return true;
}
ClassNode cn = new ClassNode();
new ClassReader(IOUtils.toByteArray(is)).accept(cn, 0);
for (FieldNode fn : cn.fields) {
if (fn.desc.equals(Type.getDescriptor(Runnable.class))) {
return true;
}
}
return false;
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}
@Override
public List<String> getMixins() {
return null;
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
// To be compatible with 0.7.11
public void preApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
// To be compatible with 0.7.11
public void postApply(String targetClassName, org.spongepowered.asm.lib.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}