LogicTechCorp Posted March 20, 2017 Posted March 20, 2017 (edited) I have an access transformer that I use for a few different things and I would like to replace it. A while back I had tried using reflection but it did not work correctly. Can I have some help? Here is the AT: https://github.com/LogicTechCorp/NetherEx/blob/9adb4a8f37f0d032c5192d1abad55b46fd12f308/src/main/resources/META-INF/nex_at.cfg Use one: https://github.com/LogicTechCorp/NetherEx/blob/9adb4a8f37f0d032c5192d1abad55b46fd12f308/src/main/java/nex/world/NetherExTeleporter.java#L54 https://github.com/LogicTechCorp/NetherEx/blob/9adb4a8f37f0d032c5192d1abad55b46fd12f308/src/main/java/nex/world/NetherExTeleporter.java#L100 https://github.com/LogicTechCorp/NetherEx/blob/9adb4a8f37f0d032c5192d1abad55b46fd12f308/src/main/java/nex/world/NetherExTeleporter.java#L107-L114 https://github.com/LogicTechCorp/NetherEx/blob/9adb4a8f37f0d032c5192d1abad55b46fd12f308/src/main/java/nex/handler/EventHandler.java#L90 Use two: https://github.com/LogicTechCorp/NetherEx/blob/9adb4a8f37f0d032c5192d1abad55b46fd12f308/src/main/java/nex/util/WorldGenUtil.java#L179-L276 Edited March 22, 2017 by LogicTechCorp Quote
Choonster Posted March 20, 2017 Posted March 20, 2017 (edited) Use ReflectionHelper.findField or ReflectionHelper.findMethod to get a Field/Method object for the field/method and store it in a private static final field. You'll need to provide both the MCP and SRG names of the field/method. Use Field#get or Field#set to get or set the value of a field. If it's an instance field, pass the instance as the first argument. If it's a static field, pass null as the first argument instead. Use Method#invoke to call a method. If it's an instance method, pass the instance as the first argument. If it's a static method, pass null as the first argument instead. Pass the method's arguments as the vararg argument. Edited March 20, 2017 by Choonster Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
LogicTechCorp Posted March 20, 2017 Author Posted March 20, 2017 1 minute ago, Choonster said: Use ReflectionHelper.findField or ReflectionHelper.findMethod to get a Field/Method object for the field/method and store it in a private static final field. You'll need to provide both the MCP and SRG names of the field/method. Use Field#get or Field#set to get or set the value of a field. If it's an instance field, pass the instance as the first argument. If it's a static field, pass null as the first argument instead. Use Method#invoke to call a method. If it's an instance method, pass the instance as the first argument. If it's a static method, pass null as the first argument instead. Pass the method's arguments as the vararg argument. Thank you! I will work on it and come back if I have any issues. Quote
LogicTechCorp Posted March 22, 2017 Author Posted March 22, 2017 (edited) It seems to be working but I just want to know if I am doing it correctly. https://github.com/LogicTechCorp/NetherEx/blob/60c21b142b38243e2663bb648911fbac8fd56075/src/main/java/nex/util/WorldGenUtil.java https://github.com/LogicTechCorp/NetherEx/blob/60c21b142b38243e2663bb648911fbac8fd56075/src/main/java/nex/world/NetherExTeleporter.java https://github.com/LogicTechCorp/NetherEx/blob/60c21b142b38243e2663bb648911fbac8fd56075/src/main/java/nex/handler/EventHandler.java Edited March 22, 2017 by LogicTechCorp Quote
Choonster Posted March 22, 2017 Posted March 22, 2017 You're using the blocks Field twice and casting the value of the second call to List<Template.EntityInfo> instead of using the entities Field. This will throw a ClassCastException at runtime. It also looks like you're not actually using the size Field. I recommend following Java naming conventions by using CONSTANT_CASE for constant fields. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
LogicTechCorp Posted March 22, 2017 Author Posted March 22, 2017 9 hours ago, Choonster said: You're using the blocks Field twice and casting the value of the second call to List<Template.EntityInfo> instead of using the entities Field. This will throw a ClassCastException at runtime. It also looks like you're not actually using the size Field. I recommend following Java naming conventions by using CONSTANT_CASE for constant fields. Thanks, I didn't see that. Also, the size Field wasn't needed after all since the class has a getSize method. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.