Skip to content

Commit

Permalink
Made TransformTools a bit more OO. Also includes patches for TE and G…
Browse files Browse the repository at this point in the history
…T wrenches.
  • Loading branch information
Joe12o committed Jan 3, 2014
1 parent c111eba commit 9bd424d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
11 changes: 9 additions & 2 deletions src/main/java/com/skcraft/alicefixes/AliceTransformer.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
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 {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,62 @@

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);
}
}

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);
Expand Down

0 comments on commit 9bd424d

Please sign in to comment.