-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93d56c3
commit ed853bf
Showing
3 changed files
with
53 additions
and
3 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/main/java/com/mitchej123/hodgepodge/asm/BibliocraftTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.mitchej123.hodgepodge.asm; | ||
|
||
import com.mitchej123.hodgepodge.Hodgepodge; | ||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
import static org.objectweb.asm.Opcodes.ASM5; | ||
|
||
public class BibliocraftTransformer implements IClassTransformer { | ||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] basicClass) { | ||
if ("jds.bibliocraft.blocks.BlockLoader".equals(transformedName) || | ||
"jds.bibliocraft.items.ItemLoader".equals(transformedName)) { | ||
Hodgepodge.log.info("Patching Bibliocraft {}", transformedName); | ||
final ClassReader cr = new ClassReader(basicClass); | ||
final ClassWriter cw = new ClassWriter(0); | ||
|
||
final ClassNode cn = new ClassNode(ASM5); | ||
cr.accept(cn, 0); | ||
for (MethodNode m : cn.methods) { | ||
if ("addRecipies".equals(m.name)) { | ||
Hodgepodge.log.info("Taking a sledgehammer to {}.addRecipies()", transformedName); | ||
//Replace the body with a RETURN opcode | ||
InsnList insnList = new InsnList(); | ||
insnList.add(new InsnNode(Opcodes.RETURN)); | ||
m.instructions = insnList; | ||
m.localVariables.clear(); | ||
m.maxStack = 0; | ||
m.maxLocals = 0; | ||
} | ||
} | ||
cn.accept(cw); | ||
return cw.toByteArray(); | ||
} | ||
else { | ||
return basicClass; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters