diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/ASMConfigPlugin.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/ASMConfigPlugin.java index 2ff49fd9..c074799f 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/ASMConfigPlugin.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/ASMConfigPlugin.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; @@ -13,6 +15,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -31,6 +34,7 @@ import org.objectweb.asm.tree.MethodNode; import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; import org.spongepowered.asm.mixin.extensibility.IMixinInfo; +import org.spongepowered.asm.mixin.transformer.ClassInfo; import org.spongepowered.asm.service.MixinService; public class ASMConfigPlugin implements IMixinConfigPlugin { @@ -109,6 +113,24 @@ public ASMConfigPlugin() { @Override public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { var wasTransformed = transformClass(targetClassName, targetClass, mixinClassName, TransformFrom.ApplicationStage.PRE_APPLY); dasmTransformedInPreApply.put(mixinClassName + "|" + targetClassName, wasTransformed); + + try { + // ugly hack to add class metadata to mixin + // based on https://github.com/Chocohead/OptiFabric/blob/54fc2ef7533e43d1982e14bc3302bcf156f590d8/src/main/java/me/modmuss50/optifabric/compat/fabricrendererapi + // /RendererMixinPlugin.java#L25:L44 + Method addMethod = ClassInfo.class.getDeclaredMethod("addMethod", MethodNode.class, boolean.class); + addMethod.setAccessible(true); + + ClassInfo ci = ClassInfo.forName(targetClassName); + Set existingMethods = ci.getMethods().stream().map(x -> x.getName() + x.getDesc()).collect(Collectors.toSet()); + for (MethodNode method : targetClass.methods) { + if (!existingMethods.contains(method.name + method.desc)) { + addMethod.invoke(ci, method, false); + } + } + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + throw new IllegalStateException(e); + } } @Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {