Applied Energistics 2

Applied Energistics 2

137M Downloads

API Question, IAppEngApi is always null

SirEndii opened this issue ยท 8 comments

commented

Describe the bug
Hey, i want to use the AE2 Api for my mod, but when i implement IAEAddon to my MeBridgeTileEntity class, the IAppEngApi from onAPIAvailable is null.

To Reproduce
Implement IAEAddon and add @AEAddon to the class.

Additional context
Class: https://gist.github.com/Seniorendi/d6924254aa3846d417ba3fa1215798b6

Environment
AE2 version: 8.2.0-beta.2
Forge version: 35.1.28

commented

Check your logfile for Failed to load messages.

Also: You might be misunderstanding how this works.
AE2 will instantiate the class you annotate with @AeAddon exactly once during startup, and then call onAPIAvailable on it.

This means that you should probably have a separate addon-class with a static field where you stash the API, instead of an instance field on your TEs, since it'll be null for every TileEntity except that one instance AE2 happens to create during startup.....

commented

Also: You might be misunderstanding how this works.
AE2 will instantiate the class you annotate with @AeAddon exactly once during startup, and then call onAPIAvailable on it.

Thank you! I will try this.

commented

I'm confused, I don't know exactly what the problem is. Maybe it's because I don't quite understand your sentence (my native language is not English).
AE2 says on every world load
Grid features for de.srendi.advancedperipherals.common.blocks.tileentity.MeBridgeTileEntity@2c7fb24c are server side only.
My code for the AE Api: https://github.com/Seniorendi/AdvancedPeripherals/blob/master/src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AppEngApi.java

I somehow understand the sentence about the mistake, but I don't know what to do about it.
It would be nice if someone could help.

commented
    public static final AppEngApi INSTANCE = new AppEngApi();

This will not really be used by AE2.

However. Since you made this static, the API class should work. Have you checked if it is null or not now?

    private static IAppEngApi api;
commented

This is not null, i checked this.

commented

Then this is not related to the addon annotation. Please keep in mind: AE2 Grids only exist on the server. Calling any of their functions on the client-side will fail.

commented

Ahh thanks. I'll get in touch if something else doesn't work.

commented

Everything works now, thank you!
If I have other questions about the API, should I write in here or create a new issue?