001/* 002 * Forge Mod Loader 003 * Copyright (c) 2012-2013 cpw. 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser Public License v2.1 006 * which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 008 * 009 * Contributors: 010 * cpw - implementation 011 */ 012 013package cpw.mods.fml.common.asm; 014 015import org.objectweb.asm.ClassReader; 016import org.objectweb.asm.ClassWriter; 017import org.objectweb.asm.Opcodes; 018import org.objectweb.asm.Type; 019import org.objectweb.asm.tree.ClassNode; 020 021import cpw.mods.fml.common.registry.BlockProxy; 022import cpw.mods.fml.relauncher.IClassTransformer; 023 024public class ASMTransformer implements IClassTransformer 025{ 026 @Override 027 public byte[] transform(String name,String transformedName, byte[] bytes) 028 { 029 if ("net.minecraft.src.Block".equals(name)) 030 { 031 ClassReader cr = new ClassReader(bytes); 032 ClassNode cn = new ClassNode(Opcodes.ASM4); 033 cr.accept(cn, ClassReader.EXPAND_FRAMES); 034 cn.interfaces.add(Type.getInternalName(BlockProxy.class)); 035 ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); 036 cn.accept(cw); 037 return cw.toByteArray(); 038 } 039 040 return bytes; 041 } 042 043}