Jump to content

Item Capabilities (1.16.5)


Babelincoln1809

Recommended Posts

Hello, I'm trying to better understand capabilities and how they work. I see a lot of examples/tutorials for entities and tile entities but not much for itemstacks, at least from what I could find. I'm trying to make an itemstack store an entity and a sound event for my own item, I dunno if I can possibly do that any other way as well. Any where I could look as an example/guide, or just an explanation? 

Link to comment
Share on other sites

On 8/18/2021 at 10:18 AM, Luis_ST said:

it's the same, the only thing that changes is you attach the capability to and ItemStack and not to an Entity/BlockEntity

Alright, so how would I go about about attaching it to my own item? There's an initcapabilites method in the item class that the bucket uses, so I'm assuming that? And how would I set things like soundevent and entity in the item class?

Link to comment
Share on other sites

1 hour ago, Luis_ST said:

I attached it to the item by using that event, it keeps crashing though saying that the sound event could be null. I did add a null check, but it still crashes. I'm a bit stumped on what to do

 

IStaff Class: https://pastebin.com/NZs5dYdX

Default Instance: https://pastebin.com/9cTvw6Kx

Staff Storage: https://pastebin.com/N3UkfU2Y

Staff Provider: https://pastebin.com/eAkDKtGd

Staff Capability: https://pastebin.com/SUuqLJV4

Capability Handler: https://pastebin.com/qvrW6CCU

 

Link to comment
Share on other sites

okay first of all, you don't need an IStorage, just return and empty CompoundNBT, you should because the error occurs there
inside of getCapability you need to check if it is your Capability
and your serializeNBT and deserializeNBT methods in your StaffProvider are broken,
add a serializeNBT & deserializeNBT to your DefaultStaffCapability and call them inside the method

why did you add two providers to the ItemStack?
you should also create a git repo because it is terrible to look at many classes when using pastebin

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.



×
×
  • Create New...

Important Information

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