// ", OpCode " + m.instructions.get(index).getOpcode());
// find local Block object node and from that, local object
// index
if (m.instructions.get(index).getType() == AbstractInsnNode.FIELD_INSN)
{
FieldInsnNode blocksListNode = (FieldInsnNode) m.instructions.get(index);
if (blocksListNode.owner.equals(hm.get("blockJavaClassName")) && blocksListNode.name.equals(hm.get("blocksListFieldName")))
{
int offset = 1;
while (m.instructions.get(index + offset).getOpcode() != ASTORE)
offset++;
System.out.println("Found Block object ASTORE Node at " + (index + offset));
VarInsnNode blockNode = (VarInsnNode) m.instructions.get(index + offset);
blockIndex = blockNode.var;
System.out.println("Block object is in local object " + blockIndex);
}
}
// find local metadata variable node and from that, local
// variable index
if (m.instructions.get(index).getType() == AbstractInsnNode.METHOD_INSN)
{
MethodInsnNode mdNode = (MethodInsnNode) m.instructions.get(index);
if (mdNode.owner.equals(hm.get("worldJavaClassName")) && mdNode.name.equals(hm.get("getBlockMetadataMethodName")))
{
int offset = 1;
while (m.instructions.get(index + offset).getOpcode() != ISTORE)
offset++;
System.out.println("Found metadata local variable ISTORE Node at " + (index + offset));
VarInsnNode mdFieldNode = (VarInsnNode) m.instructions.get(index + offset);
mdIndex = mdFieldNode.var;
System.out.println("Metadata is in local variable " + mdIndex);
}
}
if (m.instructions.get(index).getOpcode() == IFNULL)
{
System.out.println("Found IFNULL Node at " + index);
int offset = 1;
while (m.instructions.get(index + offset).getOpcode() != ALOAD)
offset++;
System.out.println("Found ALOAD Node at offset " + offset + " from IFNULL Node");
System.out.println("Patching method " + (String) hm.get("javaClassName") + "/" + m.name + m.desc + "...");
// make a new label node for the end of our code
LabelNode lmm1Node = new LabelNode(new Label());
// make new instruction list
InsnList toInject = new InsnList();
// construct instruction nodes for list
toInject.add(new VarInsnNode(ALOAD, 0));
toInject.add(new FieldInsnNode(GETFIELD, (String) hm.get("javaClassName"), (String) hm.get("worldFieldName"), "L" + (String) hm.get("worldJavaClassName") + ";"));
toInject.add(new VarInsnNode(ILOAD, 1));
toInject.add(new VarInsnNode(ILOAD, 2));
toInject.add(new VarInsnNode(ILOAD, 3));
toInject.add(new VarInsnNode(ALOAD, blockIndex));
toInject.add(new VarInsnNode(ILOAD, mdIndex));
toInject.add(new VarInsnNode(ALOAD, 0));
toInject.add(new FieldInsnNode(GETFIELD, (String) hm.get("javaClassName"), (String) hm.get("entityPlayerFieldName"), "L" + (String) hm.get("entityPlayerMPJavaClassName") + ";"));
toInject.add(new MethodInsnNode(INVOKESTATIC, "keepcalm/mods/events/EventFactory", "onBlockHarvested", "(L" + (String) hm.get("worldJavaClassName") + ";IIIL" + (String) hm.get("blockJavaClassName") + ";IL" + (String) hm.get("entityPlayerJavaClassName") + ";)Z"));
LabelNode endIf = new LabelNode(new Label());
toInject.add(new JumpInsnNode(Opcodes.IFEQ, endIf));
toInject.add(new InsnNode(Opcodes.ICONST_0));
toInject.add(new InsnNode(Opcodes.IRETURN));