Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

Posted

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.

  • Author

If you read the post, I get a null pointer every single time i do CapabilityProvider.get(player)

  • Author

It really is redundant to post. It's a null pointer on that get method anywhere and everywhere I call it. Nothing else about it. It's IWizardryCapability being returned null from that get method.

  • Author

Here's a fun redundant log for anyone who wants it:

 

http://pastebin.com/1mq5KEXZ

 

This was after removing "if (data == null) return;" (which just stopped the entire event there)

 

That's one example usage of getting the cap. I've used it in a lot more places and it's just the same result.

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.

  • Author

Yes it does. but I temporarily prevented that with a null check.

I'm fairly certain I'm sending the packets.

Why would your capability be on the players?

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

  • Author

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.

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.

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

... its not null... something it is useing in its toString is null. Which would make sense based on where this event is fired...

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

  • Author

So what should I do? I assumed that was the perfect event to attach a capability, but if I cant even get the entity, what am I supposed to do?

it is, you've attached it, atleast thats what it looks like.

Show us THE ACTUAL FREAKING ERROR

 

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

There is nothing that can be null on line 58

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

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

  • Author

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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.