我正在尝试使用此枚举并添加新材料。任何尚未删除的东西在其他地方都有硬依赖,即使如此,根据 mods 作者的说法,这几乎是 java 字节限制,所以无论如何都没有太多的工作空间。
GregoriousT 提到“有一种方法。Overmind 使用反射攻击了 Enum 以添加他自己的东西。不知道他是怎么做到的,如果你问他,也不知道他需要多长时间才能回复。”
我们正在谈论的枚举:http: //pastebin.com/g0aJ2Qjd
所以我只是问,我该怎么做呢?
这是我当前尝试[FML]: Variable m:1|newInstance|public java.lang.Object sun.reflect.DelegatingConstructorAccessorImpl.newInstance(java.lang.Object[]) throws java.lang.InstantiationException,java.lang.IllegalArgumentException,java.lang.reflect.InvocationTargetException|false
在客户端崩溃之前抛出的内容。(为了便于阅读,删除了日志代码)
当前尝试:
public class MaterialsNew {
public static void getGregMaterials() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, SecurityException{
Utils.LOG_WARNING("Stepping through the process of Greg's materials.");
Constructor<?> con = Materials.class.getDeclaredConstructors()[0];
java.lang.reflect.Method[] methods = con.getClass().getDeclaredMethods();
for (java.lang.reflect.Method m1 : methods) {
if (m1.getName().equals("acquireConstructorAccessor")) {
m1.setAccessible(true);
m1.invoke(con, new Object[0]);}
}
Field[] fields = con.getClass().getDeclaredFields();
Object ca = null;
for (Field f : fields) {
if (f.getName().equals("constructorAccessor")) {
f.setAccessible(true);
ca = f.get(con);
}
}
Method m = ca.getClass().getMethod( "newInstance", new Class[] { Object[].class });
m.setAccessible(true);
Materials v = (Materials) m.invoke(ca, new Object[] { new Object[] { "NEWMATERIAL", Integer.MAX_VALUE } });
System.out.println(v.getClass() + ":" + v.name() + ":" + v.ordinal());}}
任何帮助或建议表示赞赏,他们在 Forge IRC 的人也不确定。