for (int idx = 0; idx < m.instructions.size(); idx++) {
if (m.instructions.get(idx).getOpcode() == Opcodes.ISTORE) {
System.out.println("Found ISTORE at index " + idx + ", inserting code afterwards...");
idx++; // AFTERwards, not before ;)
InsnList toAdd = new InsnList();
// to mark the end of the code
LabelNode lmmnode = new LabelNode(new Label());
// load this
toAdd.add(new VarInsnNode(Opcodes.ALOAD, 0));
// new fleece colour
toAdd.add(new VarInsnNode(Opcodes.ILOAD, 1));
// old fleece colour
toAdd.add(new VarInsnNode(Opcodes.ILOAD, 2));
toAdd.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "keepcalm/mods/events/ForgeEventHelper", "onSheepDye", "(L" + names.get("entitySheep_javaName") + ";II)Z"));
LabelNode endIf = new LabelNode(new Label());
toAdd.add(new JumpInsnNode(Opcodes.IFEQ, endIf));
toAdd.add(new InsnNode(Opcodes.RETURN));
toAdd.add(endIf);
toAdd.add(lmmnode);
m.instructions.insertBefore(m.instructions.get(idx), toAdd);
break;
}
}