Jump to content

My capabilities REFUSE to work. 5 devs checked it and all failed to find a clue.


LordSaad

Recommended Posts

Hey there! So I was trying to make my first ever capability, but it gives a null pointer exception every time I try to get the capability of a player ANYWHERE in the mod at ANY time. I even tried to copy the capabilities from another mod byte for byte with no luck.

 

Calling "WizardryCapabilityProvider.get(playerIn);" always returns null anywhere and I try to call it, and yes, I DO register it and attach the capability in the attachCapability event.

 

First off: This is my capability package in my project.

https://github.com/TeamWizardry/Wizardry/tree/master/src/main/java/com/teamwizardry/wizardry/api/capability

(Ignore the bloods package)

 

Second: My registration and attachment of the capabilities to players:

https://github.com/TeamWizardry/Wizardry/blob/master/src/main/java/com/teamwizardry/wizardry/init/ModCapabilities.java

I want to make something clear here, the if statement

`if (!e.getEntity().hasCapability(WizardryCapabilityProvider.wizardryCapability, null)) {`

is passing successfully here.

 

Third: My commonProxy registeration:

https://github.com/TeamWizardry/Wizardry/blob/master/src/main/java/com/teamwizardry/wizardry/common/proxy/CommonProxy.java#L22

 

Fourth: Registration of the eventHandler that attaches the capabilities from the second point:

https://github.com/TeamWizardry/Wizardry/blob/master/src/main/java/com/teamwizardry/wizardry/Wizardry.java#L106

 

And finally, fifth: The packet handler for the message. It is registered in commonProxy in the third point: https://github.com/TeamWizardry/Wizardry/tree/master/src/main/java/com/teamwizardry/wizardry/common/network

 

I've had 5 of my (dev) friends check thoroughly over my code, all of them, including myself, failed to find an error as to why the capabilities always return null anywhere and everywhere. It's a simple null pointer.

 

If anyone can find any error in the code, please tell me.

Link to comment
Share on other sites

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Because I need that same capability for blocks (haven't coded that part yet)

 

And players can hold capabilities, so it's a perfect solution/usage.

 

I think Lex meant "Why would your capability already be on the player in

AttachCapabilityEvent.Entity

?"

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Somewhat, my point is if you're getting a null from the player then you need to check if the player is getting you cap set.

Its your mod you have to debug it.

It should be simple enough, use your IDEs breakpoints.

Also ALLLLLWAAAAYYYYYSSS post logs.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Ya dude, a quick step into your get function would show you that wizardryCapability was null.

Which means your cap is never registered.

This is basic debugging dude...

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Link to comment
Share on other sites

Should I call the same line:

CapabilityManager.INSTANCE.register(IWizardryCapability.class, new WizardryCapabilityStorage(), DefaultWizardryCapability.class);

In the clientProxy's preInit as well?

or in the main class's preInit or what?

 

I just tried registering the cap in clientproxy and that crashed, then tried the main class's preinit and that crashed as well. I'm assuming I shouldn't be registering it like that. What must I do?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.