Jump to content

Recommended Posts

Posted

I am trying to attach a capability to the player allowing for there to be a point counter listed as destruction points. The capability system I created doesn't seem to work. I made an item called Point Reader that attempts to read the current points the player has, but it keeps returning that the player doesnt have the capability.

 

Here is my code:

 

IDestruction.java

 

  Reveal hidden contents

 

 

DefaultImpl.java

 

  Reveal hidden contents

 

 

Storage.java

 

  Reveal hidden contents

 

 

EventHandlerCommon.java

 

  Reveal hidden contents

 

 

CommonProxy.java

 

  Reveal hidden contents

 

 

And I have this in my main mod class:

 

  Reveal hidden contents

 

Posted

public static final Capability<IDestruction> DESTRUCTION_CAP = null;

 

Do you ever make this field not-null?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Gotcha.

I haven't quite figured out all the things with capabilities yet.  Definitely haven't done any based on entityConstructing (that is, I've done a custom Cap on a TE of my own design and used the ItemHandler one).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I'm not entirely sure why it's not working, but I did notice some errors:

  • The
    IDestruction#destructionPoints

    field doesn't need to exist.

  • The
    DefaultImpl.points

    field shouldn't be static.

  • Your
    IStorage

    expects to work with

    NBTTagCompound

    s, but your

    ICapabilitySerializable

    uses

    NBTPrimitive

    .

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.

Posted

I just finished fixing those errors. Thank you for pointing them out.

 

I moved my @CapabilityInject to my EventHandlerCommon.java to see if that may solve anything, but it does not seem like it has. The way I am attempting to check if my player has the capability is by right clicking with an item with the following code:

 

 

  Reveal hidden contents

 

 

The way I see it, if the player has the DESTRUCTION_CAP capability, then there will be a chat message that shows the points, which is starting at 0 points. I'm instead getting a null pointer exception whenever I right click with this item. Is this a bad way to go about checking if I have the capability?

Posted
  On 9/18/2016 at 3:43 AM, PureUnstable said:

The way I am attempting to check if my player has the capability is by right clicking with an item with the following code:

 

 

  Reveal hidden contents

 

 

The way I see it, if the player has the DESTRUCTION_CAP capability, then there will be a chat message that shows the points, which is starting at 0 points. I'm instead getting a null pointer exception whenever I right click with this item. Is this a bad way to go about checking if I have the capability?

 

Yes. If the player does not have the capability, getCapability() will return null; since you call a method on the return value, if the player does not have the capability an NPE is thrown. Use hasCapability() to check if the player has a capability.

Posted

I originally had a check in an if statement to see if the player had the capability but it was coming back as false, so i just did a shortcut through the code last night before I went to bed.

 

I just took a look through my code again and realized I had my client proxy class referenced within my main mod class, but not the common proxy class. After fixing that, my capability now works. Thanks everyone for helping me work through it!

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.