Created
May 6, 2015 02:32
-
-
Save tterrag1098/34fd4331f0fcf57ca66d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tterrag.potionapi.common.asm; | |
import java.util.Collection; | |
import java.util.Iterator; | |
import net.minecraft.entity.EntityLivingBase; | |
import net.minecraft.launchwrapper.IClassTransformer; | |
import net.minecraft.potion.Potion; | |
import net.minecraft.potion.PotionEffect; | |
import org.apache.logging.log4j.LogManager; | |
import org.objectweb.asm.ClassReader; | |
import org.objectweb.asm.ClassWriter; | |
import org.objectweb.asm.tree.AbstractInsnNode; | |
import org.objectweb.asm.tree.ClassNode; | |
import org.objectweb.asm.tree.MethodInsnNode; | |
import org.objectweb.asm.tree.MethodNode; | |
import org.objectweb.asm.tree.VarInsnNode; | |
import tterrag.potionapi.api.effect.Effect; | |
import tterrag.potionapi.common.effect.EffectData; | |
import cpw.mods.fml.relauncher.IFMLLoadingPlugin.MCVersion; | |
import static org.objectweb.asm.Opcodes.*; | |
@MCVersion(value = "1.7.10") | |
public class EntityParticleTransformer implements IClassTransformer | |
{ | |
public static final String className = "net.minecraft.entity.EntityLivingBase"; | |
public static final String methodNameSrg = "func_70679_bo"; | |
public static final String methodNameDeobf = "updatePotionEffects"; | |
@SuppressWarnings("deprecation") | |
@Override | |
public byte[] transform(String name, String transformedName, byte[] basicClass) | |
{ | |
if (transformedName.equals(className)) | |
{ | |
ClassNode classNode = new ClassNode(); | |
ClassReader classReader = new ClassReader(basicClass); | |
classReader.accept(classNode, 0); | |
Iterator<MethodNode> methods = classNode.methods.iterator(); | |
while (methods.hasNext()) | |
{ | |
MethodNode m = methods.next(); | |
if (methodNameSrg.equals(m.name) || methodNameDeobf.equals(m.name)) | |
{ | |
for (int i = 0; i < m.instructions.size(); i++) | |
{ | |
AbstractInsnNode node = m.instructions.get(i); | |
if (node instanceof MethodInsnNode && node.getOpcode() == INVOKESTATIC | |
&& ((MethodInsnNode) node).desc.equals("(Ljava/util/Collection;)I")) | |
{ | |
String callMethodClass = "tterrag.potionapi.common.asm.EntityParticleTransformer"; | |
String callMethodName = "getColor"; | |
String callMethodSig = "(Ljava/util/Collection;Lnet/minecraft/entity/EntityLivingBase;)I"; | |
m.instructions.insertBefore(node, new VarInsnNode(ALOAD, 0)); | |
m.instructions.set(node, new MethodInsnNode(INVOKESTATIC, callMethodClass, callMethodName, callMethodSig)); | |
} | |
} | |
} | |
} | |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); | |
classNode.accept(cw); | |
LogManager.getLogger().info("Transforming " + transformedName + " Finished."); | |
return cw.toByteArray(); | |
} | |
else | |
{ | |
return basicClass; | |
} | |
} | |
@SuppressWarnings("rawtypes") | |
public static int getColor(Collection activeEffects, EntityLivingBase entity) | |
{ | |
// not relevant | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment