Posted August 18, 20169 yr 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.
August 18, 20169 yr I assume there was a log or crash? 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.
August 18, 20169 yr Author If you read the post, I get a null pointer every single time i do CapabilityProvider.get(player)
August 18, 20169 yr I mean't you should post it, guess I wasn't clear enough sorry. 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.
August 18, 20169 yr 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.
August 18, 20169 yr Alright, try putting if (hasCapability(...)) before you call getCapability(...) 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.
August 18, 20169 yr Alright, try putting if (hasCapability(...)) before you call getCapability(...) Read the code, we do that. https://github.com/TeamWizardry/Wizardry/blob/master/src/main/java/com/teamwizardry/wizardry/api/capability/WizardryCapabilityProvider.java#L31
August 18, 20169 yr 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.
August 18, 20169 yr Does it error here as well? https://github.com/TeamWizardry/Wizardry/blob/master/src/main/java/com/teamwizardry/wizardry/common/core/EventHandler.java#L79 Also do you ever send the "syncing" packet? 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.
August 18, 20169 yr Author Yes it does. but I temporarily prevented that with a null check. I'm fairly certain I'm sending the packets.
August 18, 20169 yr 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
August 18, 20169 yr 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.
August 18, 20169 yr 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.
August 18, 20169 yr 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
August 18, 20169 yr Author http://i.imgur.com/3ZiYUcY.png Breakpointed. Why is the player entity null?! the capability: http://i.imgur.com/9Qo16az.png That's correct, but the entityPlayer does NOT look promising... Why is it null?! http://i.imgur.com/cpNHNig.png
August 18, 20169 yr ... 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
August 18, 20169 yr 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?
August 18, 20169 yr 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
August 18, 20169 yr Author I did paste the error, it's a above... http://pastebin.com/1mq5KEXZ That's the null pointer I get from getCapability(player).
August 18, 20169 yr 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
August 18, 20169 yr Author My apologize, Intellij must've reformatted and removed redundant imports. I just pushed a new commit, and here's the new log: http://pastebin.com/YuifF4q8
August 18, 20169 yr 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
August 18, 20169 yr 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?
August 18, 20169 yr Author I'll do that later. What should I do to fix the registration of the caps right now?
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.