Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove recipe registration of gravisuite and advanced solar panel #964

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
compileOnly("com.github.GTNewHorizons:amunra:0.6.0:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:Galacticraft:3.2.4-GTNH:dev") { transitive = false }
compileOnly("com.github.GTNewHorizons:ForestryMC:4.9.10:dev") { transitive = false }
compileOnlyApi("com.github.GTNewHorizons:Mobs-Info:0.4.5-GTNH:dev")
compileOnlyApi("com.github.GTNewHorizons:Mobs-Info:0.4.6-GTNH:dev")

runtimeOnlyNonPublishable rfg.deobf("curse.maven:biomes-o-plenty-220318:2499612")
runtimeOnlyNonPublishable("com.github.GTNewHorizons:WailaHarvestability:1.2.1-GTNH:dev")
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.26'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
}


Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.objectweb.asm.tree.ClassNode;

import com.dreammaster.coremod.transformers.ItemFocusWardingTransformer;
import com.dreammaster.coremod.transformers.recipenukers.AdvancedSolarPanelTransformer;
import com.dreammaster.coremod.transformers.recipenukers.BibliocraftTransformer;
import com.dreammaster.coremod.transformers.recipenukers.GraviSuiteTransformer;
import com.dreammaster.coremod.transformers.recipenukers.TravellersGearTransformer;

public class DreamClassTransformer implements IClassTransformer {
Expand All @@ -21,9 +23,11 @@ public class DreamClassTransformer implements IClassTransformer {

public DreamClassTransformer() {
// register your transformers here
registerTransformer(new AdvancedSolarPanelTransformer());
registerTransformer(new BibliocraftTransformer());
registerTransformer(new TravellersGearTransformer());
registerTransformer(new GraviSuiteTransformer());
registerTransformer(new ItemFocusWardingTransformer());
registerTransformer(new TravellersGearTransformer());
}

private void registerTransformer(IDreamTransformer transformer) {
Expand All @@ -46,7 +50,8 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
final ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
final ClassWriter classWriter = new ClassWriter(0);
transformer.transform(classNode).accept(classWriter);
transformer.transform(classNode);
classNode.accept(classWriter);
return classWriter.toByteArray();
}

Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/dreammaster/coremod/IDreamTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
Expand All @@ -17,9 +16,9 @@ public interface IDreamTransformer {
String[] targetedClasses();

/**
* Returns the transformed ClassNode
* Performs transformations to the ClassNode
*/
ClassNode transform(ClassNode classNode);
void transform(ClassNode classNode);

// =================================================

Expand Down Expand Up @@ -50,13 +49,16 @@ default boolean checkLdcInsnNode(AbstractInsnNode insnNode, Object obj) {
/**
* Method to empty the methodNode and replace its body with just a RETURN Opcode
*/
default void emptyTheMethodNode(MethodNode methodNode) {
final InsnList insnList = new InsnList();
insnList.add(new InsnNode(Opcodes.RETURN));
methodNode.instructions = insnList;
methodNode.localVariables.clear();
default void emptyMethodNode(MethodNode methodNode) {
if (!methodNode.desc.equals("()V")) {
throw new IllegalArgumentException("emptyMethodNode can only be used for ()V methods");
}
methodNode.instructions.clear();
methodNode.instructions.add(new InsnNode(Opcodes.RETURN));
methodNode.maxStack = 0;
methodNode.maxLocals = 0;
methodNode.localVariables = null;
methodNode.tryCatchBlocks = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String[] targetedClasses() {
}

@Override
public ClassNode transform(ClassNode classNode) {
public void transform(ClassNode classNode) {
if (DreamCoreMod.patchItemFocusWarding) {
DreamCoreMod.logger.info("Transforming ItemFocusWarding");
for (final MethodNode methodNode : classNode.methods) {
Expand Down Expand Up @@ -73,7 +73,6 @@ public ClassNode transform(ClassNode classNode) {
mv.visitMaxs(1, 2);
mv.visitEnd();
}
return classNode;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.dreammaster.coremod.transformers.recipenukers;

import java.util.ListIterator;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;

import com.dreammaster.coremod.DreamCoreMod;
import com.dreammaster.coremod.IDreamTransformer;

public class AdvancedSolarPanelTransformer implements IDreamTransformer {

@Override
public String[] targetedClasses() {
return new String[] { "advsolar.common.AdvancedSolarPanel" };
}

@Override
public void transform(ClassNode classNode) {
for (MethodNode mn : classNode.methods) {
if (mn.name.equals("afterModsLoaded")
&& mn.desc.equals("(Lcpw/mods/fml/common/event/FMLPostInitializationEvent;)V")) {
// changes afterModsLoaded method to :
// public void afterModsLoaded(FMLPostInitializationEvent event) {
// MTAPI.manager = MTRecipeManager.instance;
// }
mn.instructions.clear();
mn.instructions.add(
new FieldInsnNode(
Opcodes.GETSTATIC,
"advsolar/utils/MTRecipeManager",
"instance",
"Ladvsolar/utils/MTRecipeManager;"));
mn.instructions.add(
new FieldInsnNode(
Opcodes.PUTSTATIC,
"advsolar/api/MTAPI",
"manager",
"Ladvsolar/api/IMTRecipeManager;"));
mn.instructions.add(new InsnNode(Opcodes.RETURN));
DreamCoreMod.logger.info("Taking a sledgehammer to {}.{}{}", classNode.name, mn.name, mn.desc);
} else if (mn.name.equals("preInit")
&& mn.desc.equals("(Lcpw/mods/fml/common/event/FMLPreInitializationEvent;)V")) {
// deletes the 4 lines of Recipes.compressor.addRecipe.....
final ListIterator<AbstractInsnNode> it = mn.instructions.iterator();
boolean isDeleting = false;
int ordinal = 0;
while (it.hasNext()) {
final AbstractInsnNode insnNode = it.next();
if (isCompressorFieldNode(insnNode)) {
isDeleting = true;
}
if (isDeleting) {
it.remove();
}
if (isAddRecipeMethodNode(insnNode)) {
ordinal++;
if (ordinal == 4) break;
}
}
DreamCoreMod.logger.info("Taking a sledgehammer to {}.{}{}", classNode.name, mn.name, mn.desc);
}
}
}

private static boolean isCompressorFieldNode(AbstractInsnNode node) {
return node instanceof FieldInsnNode && node.getOpcode() == Opcodes.GETSTATIC
&& ((FieldInsnNode) node).owner.equals("ic2/api/recipe/Recipes")
&& ((FieldInsnNode) node).name.equals("compressor")
&& ((FieldInsnNode) node).desc.equals("Lic2/api/recipe/IMachineRecipeManager;");
}

private static boolean isAddRecipeMethodNode(AbstractInsnNode node) {
return node instanceof MethodInsnNode && node.getOpcode() == Opcodes.INVOKEINTERFACE
&& ((MethodInsnNode) node).owner.equals("ic2/api/recipe/IMachineRecipeManager")
&& ((MethodInsnNode) node).name.equals("addRecipe")
&& ((MethodInsnNode) node).desc.equals(
"(Lic2/api/recipe/IRecipeInput;Lnet/minecraft/nbt/NBTTagCompound;[Lnet/minecraft/item/ItemStack;)V");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public String[] targetedClasses() {
}

@Override
public ClassNode transform(ClassNode classNode) {
for (final MethodNode methodNode : classNode.methods) {
if ("addRecipies".equals(methodNode.name) || "initRecipes".equals(methodNode.name)) {
DreamCoreMod.logger
.info("Taking a sledgehammer to {}.{}{}", classNode.name, methodNode.name, methodNode.desc);
emptyTheMethodNode(methodNode);
public void transform(ClassNode classNode) {
for (final MethodNode mn : classNode.methods) {
if (("addRecipies".equals(mn.name) || "initRecipes".equals(mn.name)) && "()V".equals(mn.desc)) {
DreamCoreMod.logger.info("Taking a sledgehammer to {}.{}{}", classNode.name, mn.name, mn.desc);
emptyMethodNode(mn);
}
}
return classNode;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.dreammaster.coremod.transformers.recipenukers;

import java.util.ListIterator;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;

import com.dreammaster.coremod.DreamCoreMod;
import com.dreammaster.coremod.IDreamTransformer;

public class GraviSuiteTransformer implements IDreamTransformer {

@Override
public String[] targetedClasses() {
return new String[] { "gravisuite.GraviSuite" };
}

@Override
public void transform(ClassNode classNode) {
for (MethodNode mn : classNode.methods) {
if (mn.name.equals("afterModsLoaded")
OneEyeMaker marked this conversation as resolved.
Show resolved Hide resolved
&& mn.desc.equals("(Lcpw/mods/fml/common/event/FMLPostInitializationEvent;)V")) {
final ListIterator<AbstractInsnNode> it = mn.instructions.iterator();
boolean delete = false;
while (it.hasNext()) {
final AbstractInsnNode insnNode = it.next();
if (!delete && insnNode instanceof TypeInsnNode
&& insnNode.getOpcode() == Opcodes.NEW
&& ((TypeInsnNode) insnNode).desc.equals("net/minecraft/item/ItemStack")) {
delete = true;
}
if (delete) {
it.remove();
}
}
mn.instructions.add(new InsnNode(Opcodes.RETURN));
DreamCoreMod.logger.info("Taking a sledgehammer to {}.{}{}", classNode.name, mn.name, mn.desc);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public String[] targetedClasses() {
}

@Override
public ClassNode transform(ClassNode classNode) {
public void transform(ClassNode classNode) {
for (MethodNode methodNode : classNode.methods) {
if (checkMethodNode(methodNode, "init", "(Lcpw/mods/fml/common/event/FMLInitializationEvent;)V")) {
/*
Expand All @@ -45,14 +45,13 @@ public ClassNode transform(ClassNode classNode) {
classNode.name,
methodNode.name,
methodNode.desc);
return classNode;
return;
} else if (addItemCallsCount == 5) {
iterator.remove();
}
}
}
}
return classNode;
}

}