Add in a fluidid transformer

This commit is contained in:
cpw 2015-04-05 15:28:27 -04:00
parent 3fc40b955a
commit 7506a5b7ad
3 changed files with 58 additions and 2 deletions

View file

@ -13,7 +13,7 @@ public class FMLForgePlugin implements IFMLLoadingPlugin
@Override @Override
public String[] getASMTransformerClass() public String[] getASMTransformerClass()
{ {
return new String[0]; return new String[] { "net.minecraftforge.classloading.FluidIdTransformer" };
} }
@Override @Override

View file

@ -0,0 +1,56 @@
package net.minecraftforge.classloading;
import java.util.ListIterator;
import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import cpw.mods.fml.common.FMLLog;
public class FluidIdTransformer implements IClassTransformer {
private static final String FLUID_TYPE = "net/minecraftforge/fluids/FluidStack";
private static final String GETID_NAME = "getFluidID";
private static final String LEGACY_FIELDNAME = "fluidID";
private static final String GETID_DESC = "()I";
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if (basicClass == null)
return null;
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
for (MethodNode m: classNode.methods)
{
for (ListIterator<AbstractInsnNode> it = m.instructions.iterator(); it.hasNext(); )
{
AbstractInsnNode insnNode = it.next();
if (insnNode.getType() == AbstractInsnNode.FIELD_INSN)
{
FieldInsnNode fi = (FieldInsnNode)insnNode;
if (FLUID_TYPE.equals(fi.owner) && LEGACY_FIELDNAME.equals(fi.name) && fi.getOpcode() == Opcodes.GETFIELD)
{
FMLLog.fine("Method %s.%s%s: Replacing GETFIELD fluidID with INVOKEVIRTUAL getFluidID", name, m.name, m.desc);
it.remove();
MethodInsnNode replace = new MethodInsnNode(Opcodes.INVOKEVIRTUAL, FLUID_TYPE, GETID_NAME, GETID_DESC, false);
it.add(replace);
}
}
}
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
}

View file

@ -23,7 +23,7 @@ public class ForgeVersion
//This number is incremented every minecraft release, never reset //This number is incremented every minecraft release, never reset
public static final int minorVersion = 13; public static final int minorVersion = 13;
//This number is incremented every time a interface changes or new major feature is added, and reset every Minecraft version //This number is incremented every time a interface changes or new major feature is added, and reset every Minecraft version
public static final int revisionVersion = 2; public static final int revisionVersion = 3;
//This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code. //This number is incremented every time Jenkins builds Forge, and never reset. Should always be 0 in the repo code.
public static final int buildVersion = 0; public static final int buildVersion = 0;