Posted November 25, 20204 yr Howdy folks I'm having some trouble with the ObfuscationReflectionHelper. I'm using findfield, and it works fine when I run it in a development environment and when I package it as a mod. But I've had a bug report from another programmer who finds that it crashes his code. The difference appears to be that his environment is running with obfuscated names, so that the reflection helper can't find the deobfuscated field name. Any thoughts on what's going on and how I can robustly fix it? The whole obfuscation/deobfuscation is still something of a black box for me and I can't reproduce his issue so I don't have many clues to point me in the right direction. Cheers TGG The code: private static World getPrivateWorldFromWorldRenderer(WorldRenderer worldRenderer) throws IllegalAccessException { if (worldField == null) { worldField = ObfuscationReflectionHelper.findField(WorldRenderer.class, "world"); } return (World)worldField.get(worldRenderer); } private static Field worldField; His crash log: https://pastebin.com/ExUU5BaS and in particular: Caused by: java.lang.NoSuchFieldException: world and I notice lots of obfuscated (Searge) names in there: eg at net.minecraft.client.renderer.WorldRenderer.func_228426_a_(WorldRenderer.java:1096) ~[?:?] {re:classloading,pl:runtimedistcleaner:A} When I try to reproduce the crash by changing my code to worldField = ObfuscationReflectionHelper.findField(WorldRenderer.class, "worldDONOTFIND"); I get the same error but my crash log has deobfuscated (MCP) names in it eg at net.minecraft.client.renderer.WorldRenderer.updateCameraAndRender(WorldRenderer.java:1118) ~[forge:?] {re:classloading,pl:runtimedistcleaner:A}
November 26, 20204 yr The issue with reflection normally is that methods and fields have different names depending on their mappings. Forge in a universal environment will use the srg names (field_123456_a_) while a dev environment will use the mapping names (example). How do we fix this? In comes ObfuscationReflectionHelper where it will take a srg name string and map it to its current mapping environment as needed. So, the field/method being specified must be the srg qualified name. You can find these names using '!mcpf <field_name>' or '!mcpm <method_name>' via dming the forge-bot over on the forge discord. Edited November 26, 20204 yr by ChampionAsh5357
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.