|
12 | 12 | import com.github.gtexpert.core.api.util.GTELog; |
13 | 13 |
|
14 | 14 | /** |
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. |
| 15 | + * ASM Transformer to patch NAE2's MixinDualityInterface by removing the @Shadow craftingList field |
| 16 | + * and replacing methods that reference it with no-ops. This fixes compatibility issues with newer |
| 17 | + * AE2 versions where the craftingList field no longer exists, while preserving Mixin injection points. |
18 | 18 | */ |
19 | 19 | public class NAE2PatchTransformer implements IClassTransformer { |
20 | 20 |
|
@@ -65,30 +65,32 @@ private byte[] patchMixinDualityInterface(byte[] classBytes) { |
65 | 65 | if (method.name.contains("injectInventoryChange") || |
66 | 66 | method.name.contains("handler$")) { |
67 | 67 |
|
68 | | - // Remove any GETFIELD instructions that reference craftingList |
| 68 | + // Check for any GETFIELD/PUTFIELD instructions that reference craftingList |
69 | 69 | if (method.instructions != null) { |
70 | | - boolean methodModified = false; |
| 70 | + boolean hasCraftingListRef = false; |
71 | 71 | Iterator<AbstractInsnNode> insnIterator = method.instructions.iterator(); |
72 | | - |
73 | 72 | while (insnIterator.hasNext()) { |
74 | 73 | AbstractInsnNode insn = insnIterator.next(); |
75 | | - |
76 | 74 | if (insn.getOpcode() == Opcodes.GETFIELD || insn.getOpcode() == Opcodes.PUTFIELD) { |
77 | 75 | FieldInsnNode fieldInsn = (FieldInsnNode) insn; |
78 | 76 | 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; |
| 77 | + hasCraftingListRef = true; |
85 | 78 | break; |
86 | 79 | } |
87 | 80 | } |
88 | 81 | } |
89 | 82 |
|
90 | | - if (methodModified) { |
91 | | - continue; |
| 83 | + if (hasCraftingListRef) { |
| 84 | + GTELog.logger.info( |
| 85 | + "Found reference to craftingList in method {}, replacing with no-op", |
| 86 | + method.name); |
| 87 | + method.instructions.clear(); |
| 88 | + if (method.tryCatchBlocks != null) { |
| 89 | + method.tryCatchBlocks.clear(); |
| 90 | + } |
| 91 | + method.localVariables = null; |
| 92 | + method.instructions.add(new InsnNode(Opcodes.RETURN)); |
| 93 | + modified = true; |
92 | 94 | } |
93 | 95 | } |
94 | 96 | } |
|
0 commit comments