Skip to content

Commit d899702

Browse files
authored
Incorporated the patch fix for NAE2 (#335)
1 parent 8399aed commit d899702

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.5.1
2+
- Incorporated the patch fix for NAE2 [#335](https://github.com/GTModpackTeam/GTExpert-Core/pull/335)
3+
- Drop required dependencies: NAE2 1.6.4 and AE2FC 2.6.6-r
4+
5+
* * *
6+
17
# 2.5.0
28
- Bump version to MixinBooter v10 [#334](https://github.com/GTModpackTeam/GTExpert-Core/pull/334)
39
- Updated MixinBooter from v9.4 to v10.6

src/main/java/com/github/gtexpert/core/GTExpertMod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
dependencies = GTInternalTags.DEP_VERSION_STRING + "required-after:" + Mods.Names.MIXINBOOTER + "@[10.5,);" +
3939
"required-after:" + Mods.Names.GREGICALITY_MULTIBLOCKS + ";" +
4040
"required-after:" + Mods.Names.APPLIED_ENERGISTICS2 + "@[v0.56.7,);" +
41-
"required-after:" + Mods.Names.NEEVES_AE2 + ";" + "required-after:" + Mods.Names.AE2_FLUID_CRAFTING + ";" +
4241
"after:" + Mods.Names.GREGTECH_WOOD_PROCESSING + ";" + "after:" + Mods.Names.IMPLOSION_NO_BOMB + ";" +
4342
"after:" + Mods.Names.GREGTECH_FOOD_OPTION + ";" + "after:" + Mods.Names.AE_ADDITIONS + ";" +
43+
"after:" + Mods.Names.AE2_FLUID_CRAFTING + ";" + "after:" + Mods.Names.NEEVES_AE2 + ";" +
4444
"after:" + Mods.Names.EXTRA_CPUS + ";" + "after:" + Mods.Names.ENDER_CORE + ";" +
4545
"after:" + Mods.Names.ENDER_IO + ";" + "after:" + Mods.Names.ENDER_ENDERGY + ";" +
4646
"after:" + Mods.Names.ENDER_MACHINES + ";" + "after:" + Mods.Names.ENDER_CONDUITS + ";" +

src/main/java/com/github/gtexpert/core/core/NAE2PatchTransformer.java

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66

77
import org.objectweb.asm.ClassReader;
88
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;
9+
import org.objectweb.asm.Opcodes;
10+
import org.objectweb.asm.tree.*;
1211

1312
import 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
*/
1919
public 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;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.gtexpert.core.integration.nae2;
2+
3+
import net.minecraft.item.ItemStack;
4+
import net.minecraftforge.fml.common.Optional;
5+
6+
import com.glodblock.github.loader.FCBlocks;
7+
import com.glodblock.github.loader.FCItems;
8+
9+
import co.neeve.nae2.NAE2;
10+
import co.neeve.nae2.common.registration.definitions.Upgrades;
11+
12+
public class AE2FCIntegration {
13+
14+
public static void postInit() {
15+
Upgrades upgrades = NAE2.definitions().upgrades();
16+
17+
if (upgrades.autoComplete().isEnabled())
18+
registerUpgradeFc(Upgrades.UpgradeType.AUTO_COMPLETE);
19+
if (upgrades.gregtechCircuit().isEnabled())
20+
registerUpgradeFc(Upgrades.UpgradeType.GREGTECH_CIRCUIT);
21+
}
22+
23+
@Optional.Method(modid = "nae2")
24+
private static void registerUpgradeFc(Upgrades.UpgradeType upgrade) {
25+
upgrade.registerItem(new ItemStack(FCBlocks.DUAL_INTERFACE), 1);
26+
upgrade.registerItem(new ItemStack(FCItems.PART_DUAL_INTERFACE), 1);
27+
}
28+
}

src/main/java/com/github/gtexpert/core/integration/nae2/NAE2Module.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import net.minecraft.item.crafting.IRecipe;
44
import net.minecraftforge.event.RegistryEvent;
5+
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
56

67
import com.github.gtexpert.core.api.GTEValues;
78
import com.github.gtexpert.core.api.modules.GTEModule;
@@ -19,6 +20,12 @@
1920
description = "Neeve's AE2 Integration Module")
2021
public class NAE2Module extends GTEIntegrationSubmodule {
2122

23+
@Override
24+
public void postInit(FMLPostInitializationEvent event) {
25+
if (Mods.NeevesAE2.isModLoaded())
26+
AE2FCIntegration.postInit();
27+
}
28+
2229
@Override
2330
public void registerRecipesLowest(RegistryEvent.Register<IRecipe> event) {
2431
NAE2ItemsRecipe.init();

0 commit comments

Comments
 (0)