Jump to content

[NBT]How to save and load items?


Recommended Posts


at the moment i'm trying to do a itembackpack, which is like a chest, but you do not have to place it in the world.

You craft a item and simply make right click to open a gui. But when i make right click nothing happens.




In my mod_File i added:

NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());


I do not want to post the whole mod_File because there are many things i've added already for other items and blocks.

Now i want to include a backpack. Hope someone can help me.


Link to comment
Share on other sites

player.openGui(mod_FoodEx.instance, 0, world, 0, 0, 0);


And from GUI handler:

TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

                if(tileEntity instanceof TileEntityBackpack){


The XYZ passed inn will always be 0, so it will get the TileEntity at 0,0,0 which probably ain't an instanceof TileEntityBackpack.


I think you may have to re think what you are trying to do, you're logic is flawed mate.

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Also it is not right to use a TileEntity without a block. Use the NBT system the ItemStack provides!

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

Is there a tutorial, how to do that with items? I only found it with blocks, and have no idea, where to start.

I've already changed the 0,0,0 in openGUI to the player position, but this can't work. I have to use NBT, i understand, but i need some information or a tutorial.

Link to comment
Share on other sites

There's not a tutorial for everything, this is where tutorials stop and one have to start to act like a programmer and study source code, study what other people have done and read the documentation :)


But regarding NBT, I believe that there are some tutorials involving nbt inn general around :)


If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

Thanks. I read through the Internet and got it already a bit working. I can open a gui and place something in it. But what are the functions to save the Items, that are in the "Backpack", and load them? I don't use TileEntity anymore, cuz it's an item. ;)

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.

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.