    001package cpw.mods.fml.common.asm;
    002
    003import org.objectweb.asm.ClassReader;
    004import org.objectweb.asm.ClassWriter;
    005import org.objectweb.asm.Opcodes;
    006import org.objectweb.asm.Type;
    007import org.objectweb.asm.tree.ClassNode;
    008
    009import cpw.mods.fml.common.registry.BlockProxy;
    010import cpw.mods.fml.relauncher.IClassTransformer;
    011
    012public class ASMTransformer implements IClassTransformer
    013{
    014    @Override
    015    public byte[] transform(String name, byte[] bytes)
    016    {
    017        if ("net.minecraft.src.Block".equals(name))
    018        {
    019            ClassReader cr = new ClassReader(bytes);
    020            ClassNode cn = new ClassNode(Opcodes.ASM4);
    021            cr.accept(cn, ClassReader.EXPAND_FRAMES);
    022            cn.interfaces.add(Type.getInternalName(BlockProxy.class));
    023            ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    024            cn.accept(cw);
    025            return cw.toByteArray();
    026        }
    027
    028        return bytes;
    029    }
    030
    031}