From 9bd424d9cf798c7c48f2b7e0ea8fb037619d459f Mon Sep 17 00:00:00 2001 From: Joe12o Date: Thu, 2 Jan 2014 19:27:47 -0500 Subject: [PATCH] Made TransformTools a bit more OO. Also includes patches for TE and GT wrenches. --- .../skcraft/alicefixes/AliceTransformer.java | 11 +++++- .../transformers/TransformTools.java | 39 ++++++++++++------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/skcraft/alicefixes/AliceTransformer.java b/src/main/java/com/skcraft/alicefixes/AliceTransformer.java index 50157fd..ddd172a 100644 --- a/src/main/java/com/skcraft/alicefixes/AliceTransformer.java +++ b/src/main/java/com/skcraft/alicefixes/AliceTransformer.java @@ -1,11 +1,12 @@ package com.skcraft.alicefixes; +import com.skcraft.alicefixes.transformers.TransformBreaker; import com.skcraft.alicefixes.transformers.TransformTools; import com.skcraft.alicefixes.transformers.TransformExcavationWand; import com.skcraft.alicefixes.transformers.TransformTradeWand; +import com.skcraft.alicefixes.util.ASMHelper; import cpw.mods.fml.common.FMLLog; import net.minecraft.launchwrapper.IClassTransformer; - import java.util.logging.Level; public class AliceTransformer implements IClassTransformer { @@ -13,7 +14,13 @@ public class AliceTransformer implements IClassTransformer { private final IClassTransformer[] transformers = { new TransformExcavationWand(), new TransformTradeWand(), - new TransformTools() + new TransformTools("thaumcraft.common.items.equipment.ItemElementalAxe", "func_77648_a", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;IIIIFFF)Z"), + new TransformTools("thaumcraft.common.items.equipment.ItemElementalShovel", "func_77660_a", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;IIIILnet/minecraft/entity/EntityLivingBase;)Z"), + new TransformTools("gravisuite.ItemVajra", "a", "(L" + ASMHelper.getObf("ItemStack") + ";L" + ASMHelper.getObf("EntityPlayer") + ";L" + ASMHelper.getObf("World") + ";IIIIFFF)Z"), + new TransformTools("thermalexpansion.item.tool.ItemWrench", "onItemUseFirst", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;IIIIFFF)Z"), + new TransformTools("thermalexpansion.item.tool.ItemWrenchBattle", "onItemUseFirst", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;IIIIFFF)Z"), + new TransformTools("gregtechmod.api.items.GT_Wrench_Item", "onItemUseFirst", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/EntityPlayer;Lnet/minecraft/world/World;IIIIFFF)Z"), + new TransformBreaker() }; @Override diff --git a/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java b/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java index 7c3c33b..2d04f86 100644 --- a/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java +++ b/src/main/java/com/skcraft/alicefixes/transformers/TransformTools.java @@ -11,32 +11,45 @@ public class TransformTools implements IClassTransformer { + private String className; + private String method; + private String desc; + + public TransformTools(String className, String method, String desc) { + this.className = className; + this.method = method; + this.desc = desc; + } + @Override public byte[] transform(String name, String transformedName, byte[] bytes) { - if(name.equals("thaumcraft.common.items.equipment.ItemElementalAxe") || - name.equals("thaumcraft.common.items.equipment.ItemElementalShovel") || - name.equals("gravisuite.ItemVajra")) { + if(name.equals(className)) { ClassReader cr = new ClassReader(bytes); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS); - cr.accept(new ToolVisitor(cw), 0); + cr.accept(new ToolVisitor(cw, method, desc), 0); return cw.toByteArray(); } return bytes; } class ToolVisitor extends ClassVisitor { - public ToolVisitor(ClassVisitor cv) { + + private String method; + private String desc; + + public ToolVisitor(ClassVisitor cv, String method, String desc) { super(ASM4, cv); + this.method = method; + this.desc = desc; } @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - if(name.equals("func_77648_a") || name.equals("func_77660_a") || (name.equals("a") && - desc.equals("(L" + ASMHelper.getObf("ItemStack") + ";L" + ASMHelper.getObf("EntityPlayer") + - ";L" + ASMHelper.getObf("World") + ";IIIIFFF)Z"))) { - return new ToolMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), name.equals("func_77660_a") ? false : true); + if(name.equals(method) && desc.equals(this.desc)) { + return new ToolMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), + !name.equals("func_77660_a")); } return super.visitMethod(access, name, desc, signature, exceptions); } @@ -44,16 +57,16 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si class ToolMethodVisitor extends MethodVisitor { - boolean onBlockDestroyed; + boolean alternate; - public ToolMethodVisitor(MethodVisitor mv, boolean onBlockDestroyed) { + public ToolMethodVisitor(MethodVisitor mv, boolean alternate) { super(ASM4, mv); - this.onBlockDestroyed = onBlockDestroyed; + this.alternate = alternate; } @Override public void visitCode() { - if(onBlockDestroyed) { + if(alternate) { ASMHelper.injectCodeBoolXYZ(mv, 2, 4, 5, 6); } else { ASMHelper.injectCodeBoolXYZ(mv, 7, 4, 5, 6);