Okay so I wouldn't normally ask but I have been trying to do this for three hours and I have at least 10 tabs open trying to figure out how to do this.
Could someone please tell me how to make this work...
Okay so this is me trying to set the value of 'accessableLPX' (it's a double in the class this is in) to the value of 'EntityPlayerSP.lastReportedPosX' and I am failing at doing this... and this is even before I figure out how this will work once it's out of the development environment...
@anyone who has an idea of what I am doing wrong, please help!
What you have now should work in the development environment, but it's not very efficient and won't work in the release environment.
Looking up a field/method with reflection is expensive, so you should only do it once and store the Field/Method object in a private static final field. Use this Field/Method object when you want to access the underlying field/method.
For reflection on vanilla fields/methods to work outside of the development environment, you need to check for both the MCP (deobfuscated) and SRG (semi-obfuscated) names of the field/method. ReflectionHelper.findField and ReflectionHelper.findMethod allow you to pass multiple names for a field/method and will try each one until it finds one that exists.
You can use MCPBot to find the SRG name of a method/field.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Okay so I wouldn't normally ask but I have been trying to do this for three hours and I have at least 10 tabs open trying to figure out how to do this.
Could someone please tell me how to make this work...
Okay so this is me trying to set the value of 'accessableLPX' (it's a double in the class this is in) to the value of 'EntityPlayerSP.lastReportedPosX' and I am failing at doing this... and this is even before I figure out how this will work once it's out of the development environment...
@anyone who has an idea of what I am doing wrong, please help!
Thanks in advance.
Define "failing big time"...
~ Crows
Avatar Mod 2 -- Elemental Bending from Avatar: The Last Airbender
Contact: PM or [email protected]
What you have now should work in the development environment, but it's not very efficient and won't work in the release environment.
Looking up a field/method with reflection is expensive, so you should only do it once and store the Field/Method object in a private static final field. Use this Field/Method object when you want to access the underlying field/method.
For reflection on vanilla fields/methods to work outside of the development environment, you need to check for both the MCP (deobfuscated) and SRG (semi-obfuscated) names of the field/method. ReflectionHelper.findField and ReflectionHelper.findMethod allow you to pass multiple names for a field/method and will try each one until it finds one that exists.
You can use MCPBot to find the SRG name of a method/field.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
I'd recommend looking into reflection libraries like Mirror. Forge itself also contains reflection utilities, such as ReflectionHelper.
Here's an example on how to use it: