Jump to content

Recommended Posts

Posted (edited)

Hey guys, I am trying to make a backpack type item. I have managed to get the item to open a gui but when I put items into the item and close it the items disappear. Can anyone tell me what I'm doing wrong? My code is below..

 

PackItem
GuiHandler

PackContainer

 

I also have a small problem with the GUI slots being about one pixel too far to the left so if you spot the fix for that, then i'll be just as happy! :P

Any help is appreciated!

 

Edited by shauncjones
Posted

Don't implement ICapabilityProvider in your Item class. You need to override Item#initCapabilities to return an instance of an ICapabilityProvider.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted
10 minutes ago, larsgerrits said:

Don't implement ICapabilityProvider in your Item class. You need to override Item#initCapabilities to return an instance of an ICapabilityProvider.

Yeah, I was playing around I changed it back after I posted this but it still doesn't save items.

Posted

Looks like everytime something changes on the slots of your backpack you not saving those changes on the NBT (I may be wrong but check if that is happening) Also, not sure how you populate the slots, are those been fill with the contents you get from the NBT?

Posted
24 minutes ago, American2050 said:

Looks like everytime something changes on the slots of your backpack you not saving those changes on the NBT (I may be wrong but check if that is happening) Also, not sure how you populate the slots, are those been fill with the contents you get from the NBT?

I managed to get the Items to be persistent with these changes. But when I save and reload the world they are empty again.

PackItem

GuiHandler

PackContainer

PackCompatibilityProvider

Posted
12 minutes ago, Ugdhar said:

You have no code in your serializeNBT and deserializeNBT methods. That's where you write/read the stuff you wamt to save.

Well it saves the items till I close the world. But I have no clue where to even start writing stuff in there... :(

Posted
7 minutes ago, shauncjones said:

Well it saves the items till I close the world. But I have no clue where to even start writing stuff in there... :(

It's not saving anything. The items are just in there, if they had saved it'd work when you log in again.

 

The class net.minecraft.item.ItemStack has methods for saving NBT data containing items and whatnot.  I'd take a gander over there for saving NBT data.

Posted
38 minutes ago, shauncjones said:

Well it saves the items till I close the world. But I have no clue where to even start writing stuff in there... :(

I ran into this issue, it was primarily the fact that I didn't have the correct sides or checked the world.isRemote correctly. 

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.