V-Tweaks

V-Tweaks

11M Downloads

Please register your capability

RoShioLeo opened this issue ยท 3 comments

commented

I received a crash report. https://pastebin.com/0KfHJU3m
I noticed that NPE threw abnormally. And it's my code.

@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side)
{
    if (cap.equals(WORLD_PLAYERS_DATA))
        return data.cast();
    else
        return LazyOptional.empty();
}

Only if the cap is null, it would throw NPE. But it should be nonnull.
Then I found

at com.oitsjustjose.vtweaks.common.util.GuideNotifier.onPlayerJoin(GuideNotifier.java:26) ~[vtweaks:3.5.0] {re:classloading}

That means your capability is null.

@CapabilityInject(IVTweaksCapability.class)
public static final Capability<IVTweaksCapability> VTWEAKS_CAPABILITY = null;

In Javadoc, it says

When placed on a FIELD, the field will be set to an instance of Capability once that capability is registered. That field must be static and be able to hold a instance of 'Capability' Example:
@CapabilityInject(IExampleCapability.class)
private static final Capability TEST_CAP = null;

That means you need to register your capability, or it cannot inject.

But I couldn't find any code that you register the capability.

CapabilityManager.INSTANCE::register

Please use this to register.
Although when I installed your mod, the game didn't crash, the possibility still exists.

commented

Interesting - Geolosys doesn't usually have this issue and I don't believe it registers like this either but I will do this ASAP.

commented

Yes, it's strange.
It can usually work well when unregistered.
I don't know why. ๐Ÿ˜‚

commented

This should no longer be an issue as I'm not using capabilities like this anymore.