|
| 1 | +package com.github.gtexpert.core.core; |
| 2 | + |
| 3 | +import java.util.Iterator; |
| 4 | + |
| 5 | +import net.minecraft.launchwrapper.IClassTransformer; |
| 6 | + |
| 7 | +import org.objectweb.asm.ClassReader; |
| 8 | +import org.objectweb.asm.ClassWriter; |
| 9 | +import org.objectweb.asm.tree.AnnotationNode; |
| 10 | +import org.objectweb.asm.tree.ClassNode; |
| 11 | +import org.objectweb.asm.tree.FieldNode; |
| 12 | + |
| 13 | +import com.github.gtexpert.core.api.util.GTELog; |
| 14 | + |
| 15 | +/** |
| 16 | + * ASM Transformer to patch NAE2's MixinDualityInterface by removing the problematic craftingList field. |
| 17 | + * This implements the diff change that removes the @Shadow craftingList field from the mixin. |
| 18 | + */ |
| 19 | +public class NAE2PatchTransformer implements IClassTransformer { |
| 20 | + |
| 21 | + @Override |
| 22 | + public byte[] transform(String name, String transformedName, byte[] basicClass) { |
| 23 | + if ("co.neeve.nae2.mixin.upgrades.gregcircuit.MixinDualityInterface".equals(transformedName)) { |
| 24 | + return patchMixinDualityInterface(basicClass); |
| 25 | + } |
| 26 | + return basicClass; |
| 27 | + } |
| 28 | + |
| 29 | + private byte[] patchMixinDualityInterface(byte[] classBytes) { |
| 30 | + try { |
| 31 | + GTELog.logger.info("Patching NAE2 MixinDualityInterface to remove craftingList field"); |
| 32 | + |
| 33 | + ClassReader classReader = new ClassReader(classBytes); |
| 34 | + ClassNode classNode = new ClassNode(); |
| 35 | + classReader.accept(classNode, 0); |
| 36 | + |
| 37 | + // Remove the craftingList field |
| 38 | + Iterator<FieldNode> fieldIterator = classNode.fields.iterator(); |
| 39 | + boolean fieldRemoved = false; |
| 40 | + |
| 41 | + while (fieldIterator.hasNext()) { |
| 42 | + FieldNode field = fieldIterator.next(); |
| 43 | + if ("craftingList".equals(field.name)) { |
| 44 | + // Check if this field has @Shadow annotation |
| 45 | + if (field.visibleAnnotations != null) { |
| 46 | + for (AnnotationNode annotation : field.visibleAnnotations) { |
| 47 | + if ("Lorg/spongepowered/asm/mixin/Shadow;".equals(annotation.desc)) { |
| 48 | + GTELog.logger |
| 49 | + .info("Removing @Shadow craftingList field from NAE2 MixinDualityInterface"); |
| 50 | + fieldIterator.remove(); |
| 51 | + fieldRemoved = true; |
| 52 | + break; |
| 53 | + } |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + if (fieldRemoved) { |
| 60 | + ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); |
| 61 | + classNode.accept(classWriter); |
| 62 | + GTELog.logger.info("Successfully patched NAE2 MixinDualityInterface"); |
| 63 | + return classWriter.toByteArray(); |
| 64 | + } else { |
| 65 | + GTELog.logger.info("craftingList field not found or already removed in MixinDualityInterface"); |
| 66 | + } |
| 67 | + |
| 68 | + } catch (Exception e) { |
| 69 | + GTELog.logger.error("Failed to patch NAE2 MixinDualityInterface: " + e.getMessage(), e); |
| 70 | + } |
| 71 | + |
| 72 | + return classBytes; |
| 73 | + } |
| 74 | +} |
0 commit comments