Posted August 12, 201312 yr Hey there, I am wondering how to use API's, and how to have my mod use them. Reason being I would like to make items in my mods have things such as Thaumcraft aspects. But I would want the mod to work without the player having the mods installed... dunno if that's possible. Thanks for the help -Jordan Why bother?
August 12, 201312 yr You can do that using reflection. Remember to catch exceptions if API isn't installed.
August 12, 201312 yr Author Pretend for a second that I know next to nothing about modding But thanks for telling me it's possible So, what exactly do I do? Do I add all the API stuff into my src folder (not my mod's of course), and then reference it as I would my own but instead of MyModName.ClassFile it would be APIName.ClassFile ? Why bother?
August 12, 201312 yr I'll pretend you know a few things in Java. You can use the API directly like you would with any class, this is called a strong reference in Java. It means code will crash if an used part of the API isn't installed. ("Class not found exception"...you might have seen that already) You can have weak reference by using reflection. This a powerful tool to use, perfectly suited in your case. Well coded, new things will happen if an API is installed, but no crash on other situation. You can start learning reflection here: http://docs.oracle.com/javase/tutorial/reflect/ If you are unsure about it, you can start by using strong reference, and if you find the API easy to use and worth the effort, you can convert strong references to weak with reflection
August 12, 201312 yr Author So if I use a strong reference it will be less laggy (according to that link)... so it's better to do that? And then maybe release 2 versions 1 API compat and one not? Why bother?
August 12, 201312 yr And then maybe release 2 versions 1 API compat and one not? your choice really, if you use strong reference it will generally be faster. but you if the mod is not installed then it wont work (like gotolink said) if you need to reflect all the time (like every milisecond) then reflection might not be such a good idea but if its only for setup then reflection is awesome! how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
August 12, 201312 yr well example in one of my mod i need to read value from a private field in some class, using reflection i am able to get a reference to that object, save it elsewhere and read the value i need from that reference. so i technicly use reflection only 1 time, to get the reference and after i dont need it. basicly its slow while im getting the reference for the first time and after that everythign is smooth. on the other side sometimes youll need to constantly use reflection so that not super efficient how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
August 12, 201312 yr Author Oh right, so if it were (for example) something like a timer from RedPower, or some sort of redstone thing that can essentially update every tick, it may be better to do a strong reference? But if it were just to check for a file, and if it was there then do XYZ it may just be better to do a weak one? Or do I have that wrong? Why bother?
August 12, 201312 yr no you got it right in my case i want to have access to the Timer reference in Minecraft (for rendering). so i only need to copy the reference once since it will be the exact same timer during your whole session. but in the case of redstone theres redstone all over the world so you dont want to have reference to everything. what you would do is use reflection every time you need to access it but that slow btw when we say slow we mean "slower then strong reference" in some case reflection will be "slow" but still fast enough so that your fps wont drop how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
August 12, 201312 yr not really offtopic, actually quite on topic as thats what op is trying to do. today i learned how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution-
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.