Fix classloading issue preventing JRockit from running forge

This commit is contained in:
Christian 2012-10-19 09:30:31 -04:00
parent 2687a67e73
commit f3443d3e02

View file

@ -18,11 +18,11 @@ public class EventTransformer implements IClassTransformer
public EventTransformer() public EventTransformer()
{ {
} }
@Override @Override
public byte[] transform(String name, byte[] bytes) public byte[] transform(String name, byte[] bytes)
{ {
if (name.equals("net.minecraftforge.event.Event") || name.startsWith("net.minecraft.src.") || name.indexOf('.') == -1) if (name.equals("net.minecraftforge.event.Event") || name.startsWith("net.minecraft.") || name.indexOf('.') == -1)
{ {
return bytes; return bytes;
} }
@ -47,7 +47,7 @@ public class EventTransformer implements IClassTransformer
return bytes; return bytes;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private boolean buildEvents(ClassNode classNode) throws Exception private boolean buildEvents(ClassNode classNode) throws Exception
{ {
@ -56,23 +56,24 @@ public class EventTransformer implements IClassTransformer
{ {
return false; return false;
} }
boolean hasSetup = false; boolean hasSetup = false;
boolean hasGetListenerList = false; boolean hasGetListenerList = false;
boolean hasDefaultCtr = false; boolean hasDefaultCtr = false;
Type tList = Type.getType(ListenerList.class); Class<?> listenerListClazz = Class.forName("net.minecraftforge.event.ListenerList", false, getClass().getClassLoader());
Type tList = Type.getType(listenerListClazz);
for (MethodNode method : (List<MethodNode>)classNode.methods) for (MethodNode method : (List<MethodNode>)classNode.methods)
{ {
if (method.name.equals("setup") && if (method.name.equals("setup") &&
method.desc.equals(Type.getMethodDescriptor(VOID_TYPE)) && method.desc.equals(Type.getMethodDescriptor(VOID_TYPE)) &&
(method.access & ACC_PROTECTED) == ACC_PROTECTED) (method.access & ACC_PROTECTED) == ACC_PROTECTED)
{ {
hasSetup = true; hasSetup = true;
} }
if (method.name.equals("getListenerList") && if (method.name.equals("getListenerList") &&
method.desc.equals(Type.getMethodDescriptor(tList)) && method.desc.equals(Type.getMethodDescriptor(tList)) &&
(method.access & ACC_PUBLIC) == ACC_PUBLIC) (method.access & ACC_PUBLIC) == ACC_PUBLIC)
{ {
hasGetListenerList = true; hasGetListenerList = true;
@ -83,7 +84,7 @@ public class EventTransformer implements IClassTransformer
hasDefaultCtr = true; hasDefaultCtr = true;
} }
} }
if (hasSetup) if (hasSetup)
{ {
if (!hasGetListenerList) if (!hasGetListenerList)
@ -95,9 +96,9 @@ public class EventTransformer implements IClassTransformer
return false; return false;
} }
} }
Type tSuper = Type.getType(classNode.superName); Type tSuper = Type.getType(classNode.superName);
//Add private static ListenerList LISTENER_LIST //Add private static ListenerList LISTENER_LIST
classNode.fields.add(new FieldNode(ACC_PRIVATE | ACC_STATIC, "LISTENER_LIST", tList.getDescriptor(), null, null)); classNode.fields.add(new FieldNode(ACC_PRIVATE | ACC_STATIC, "LISTENER_LIST", tList.getDescriptor(), null, null));
@ -144,7 +145,7 @@ public class EventTransformer implements IClassTransformer
method.instructions.add(new FieldInsnNode(PUTSTATIC, classNode.name, "LISTENER_LIST", tList.getDescriptor())); method.instructions.add(new FieldInsnNode(PUTSTATIC, classNode.name, "LISTENER_LIST", tList.getDescriptor()));
method.instructions.add(new InsnNode(RETURN)); method.instructions.add(new InsnNode(RETURN));
classNode.methods.add(method); classNode.methods.add(method);
/*Add: /*Add:
* public ListenerList getListenerList() * public ListenerList getListenerList()
* { * {