Open Belgabor opened 8 years ago
Thank you. but I can't receive it, because it will crash when EnergyNet.class does not exist.
In the if statement, even if it is non-attainment, EnergyNet.class will be loaded in the class loading. And if it does not exist, it will cause NoClassDefFoundError.
I feared that it would not work, so I tested that with a minimal mod collection (NEI, AMT, EMT & MCEconomy). I was surprised myself, but it works. Java only seems to mind if a missing API class is part of a method signature.
Here is a small test I did:
System.out.println("IC2");
if (ModAPIManager.INSTANCE.hasAPI("IC2API"))
System.out.println("Present");
else
System.out.println("Not Present");
if (ModAPIManager.INSTANCE.hasAPI("IC2API") && EnergyNet.instance != null)
System.out.println("Present & Initialized");
else
System.out.println("Not present or not initialized");
Minimal mod set:
[16:13:41] [Client thread/INFO] [STDOUT/DCsEcoMT]: [defeatedcrow.addonforamt.economy.EcoMTCore:init:180]: IC2
[16:13:41] [Client thread/INFO] [STDOUT/DCsEcoMT]: [defeatedcrow.addonforamt.economy.EcoMTCore:init:184]: Not Present
[16:13:41] [Client thread/INFO] [STDOUT/DCsEcoMT]: [defeatedcrow.addonforamt.economy.EcoMTCore:init:188]: Not present or not initialized
With Railcraft (which ships but does not initialize the IC2 API):
[16:18:37] [Client thread/INFO] [STDOUT/DCsEcoMT]: [defeatedcrow.addonforamt.economy.EcoMTCore:init:180]: IC2
[16:18:37] [Client thread/INFO] [STDOUT/DCsEcoMT]: [defeatedcrow.addonforamt.economy.EcoMTCore:init:182]: Present
[16:18:37] [Client thread/INFO] [STDOUT/DCsEcoMT]: [defeatedcrow.addonforamt.economy.EcoMTCore:init:188]: Not present or not initialized
It seems my intention was not communicated. I'm sorry.
I'm concerned about the "incomplete" IC2API. Some of mods has shipped with the package-info of IC2API and lacks some package about energy. It is some crash that has already been reported, but about some them, cause mod still has not been identified.
Since RailCraft has bundled all of the energy API packages (including the EnergyNet.class), your code will work. If you wish to test, I recommend to download IC2API and delete the EnergyNet.class from it.
I also have already send a commit of another fix. It corresponds to a probably incomplete API.
Oh, I see now. But if there's a mod shipping an incomplete API, won't that break the original code as well? Anyways, I think I have an idea, I'll make a new suggestion.
I already fixed it.
API (@API annotation) has a another modid, it will be loaded into the front of the preInit. It does not require the presence of a parent mod. The reading of the API and the instance initialization of API is different. They need each another way. You seem to be trying to check the instance initialization of IC2API, but not enough to confirm the presence of that file.
First of all, this mod is not going to make by multiple authors. It basically made by me. So, I did not clear the development policy. I thought that it is unnecessary. As one of it, I'll avoid importing the class of other mod in the main classes. Most of the contacts with other mod is included in the plugin package, for it avoiding the direct import. It is to prevent the crash.
In addition, I must be managed in order for this Mod to work in a stable. I do not want that this mod is used as a practice field of modding of others. It should be done in your project.
We had an odd crash on our server that I traced down to the IC2 API being detected as present, but EnergyNet.instance was not initialized (null). This is an additional safety check to insure the API is present and initialized.