66
77import org .objectweb .asm .ClassReader ;
88import 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 ;
9+ import org .objectweb .asm .Opcodes ;
10+ import org .objectweb .asm .tree .*;
1211
1312import com .github .gtexpert .core .api .util .GTELog ;
1413
1514/**
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.
15+ * ASM Transformer to patch NAE2's MixinDualityInterface by removing the problematic craftingList field
16+ * and any methods that reference it. This fixes compatibility issues with newer AE2 versions
17+ * where the craftingList field no longer exists.
1818 */
1919public class NAE2PatchTransformer implements IClassTransformer {
2020
@@ -28,16 +28,16 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
2828
2929 private byte [] patchMixinDualityInterface (byte [] classBytes ) {
3030 try {
31- GTELog .logger .info ("Patching NAE2 MixinDualityInterface to remove craftingList field " );
31+ GTELog .logger .info ("Patching NAE2 MixinDualityInterface to remove craftingList references " );
3232
3333 ClassReader classReader = new ClassReader (classBytes );
3434 ClassNode classNode = new ClassNode ();
3535 classReader .accept (classNode , 0 );
3636
37+ boolean modified = false ;
38+
3739 // Remove the craftingList field
3840 Iterator <FieldNode > fieldIterator = classNode .fields .iterator ();
39- boolean fieldRemoved = false ;
40-
4141 while (fieldIterator .hasNext ()) {
4242 FieldNode field = fieldIterator .next ();
4343 if ("craftingList" .equals (field .name )) {
@@ -48,25 +48,63 @@ private byte[] patchMixinDualityInterface(byte[] classBytes) {
4848 GTELog .logger
4949 .info ("Removing @Shadow craftingList field from NAE2 MixinDualityInterface" );
5050 fieldIterator .remove ();
51- fieldRemoved = true ;
51+ modified = true ;
5252 break ;
5353 }
5454 }
5555 }
5656 }
5757 }
5858
59- if (fieldRemoved ) {
59+ // Remove or modify methods that reference craftingList
60+ Iterator <MethodNode > methodIterator = classNode .methods .iterator ();
61+ while (methodIterator .hasNext ()) {
62+ MethodNode method = methodIterator .next ();
63+
64+ // Check if this is an injected method that might reference craftingList
65+ if (method .name .contains ("injectInventoryChange" ) ||
66+ method .name .contains ("handler$" )) {
67+
68+ // Remove any GETFIELD instructions that reference craftingList
69+ if (method .instructions != null ) {
70+ boolean methodModified = false ;
71+ Iterator <AbstractInsnNode > insnIterator = method .instructions .iterator ();
72+
73+ while (insnIterator .hasNext ()) {
74+ AbstractInsnNode insn = insnIterator .next ();
75+
76+ if (insn .getOpcode () == Opcodes .GETFIELD || insn .getOpcode () == Opcodes .PUTFIELD ) {
77+ FieldInsnNode fieldInsn = (FieldInsnNode ) insn ;
78+ if ("craftingList" .equals (fieldInsn .name )) {
79+ GTELog .logger .info (
80+ "Found reference to craftingList in method {}, removing the method entirely" ,
81+ method .name );
82+ methodIterator .remove ();
83+ modified = true ;
84+ methodModified = true ;
85+ break ;
86+ }
87+ }
88+ }
89+
90+ if (methodModified ) {
91+ continue ;
92+ }
93+ }
94+ }
95+ }
96+
97+ if (modified ) {
6098 ClassWriter classWriter = new ClassWriter (ClassWriter .COMPUTE_MAXS );
6199 classNode .accept (classWriter );
62100 GTELog .logger .info ("Successfully patched NAE2 MixinDualityInterface" );
63101 return classWriter .toByteArray ();
64102 } else {
65- GTELog .logger .info ("craftingList field not found or already removed in MixinDualityInterface" );
103+ GTELog .logger .info ("No craftingList references found in MixinDualityInterface" );
66104 }
67105
68106 } catch (Exception e ) {
69- GTELog .logger .error ("Failed to patch NAE2 MixinDualityInterface: " + e .getMessage (), e );
107+ GTELog .logger .error ("Failed to patch NAE2 MixinDualityInterface: {}" , e .getMessage (), e );
70108 }
71109
72110 return classBytes ;
0 commit comments