Jump to content

Recommended Posts

Posted

My aim is to save settings for an item on a per-item basis, and so I want to save the settings to NBT. The items have inventories, and the NBT data is saved fine and its working correctly, but I cannot get the settings to save (although they stay loaded even if you exit a world and load it again, if you restart the game everything is set to 0).

 

Each of the variables is correct when writing to NBT, but no tag is actually created. Then, when it reads obviously no tag is found so the variable is set to 0.

 

The NBT reading/writing code is here (and everything below that in that class): https://github.com/Roboguy99/HotbarBag/blob/master/src/main/java/roboguy99/hotbarBag/inventory/BagInventory.java#L169

 

The class that handles the changing/saving/loading of settings to/from NBT is here: https://github.com/Roboguy99/HotbarBag/blob/master/src/main/java/roboguy99/hotbarBag/gui/GuiConfig.java

I have no idea what I'm doing.

Posted

I'm sure it would help if writeSettingsToNBT and readSettingsFromNBT was actually being called somewhere.

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 sure it would help if writeSettingsToNBT and readSettingsFromNBT was actually being called somewhere.

 

They are...inside GuiConfig. Sorry, I probably should have specified.

 

See here: https://github.com/Roboguy99/HotbarBag/blob/master/src/main/java/roboguy99/hotbarBag/gui/GuiConfig.java#L96

And here: https://github.com/Roboguy99/HotbarBag/blob/master/src/main/java/roboguy99/hotbarBag/gui/GuiConfig.java#L205

And here: https://github.com/Roboguy99/HotbarBag/blob/master/src/main/java/roboguy99/hotbarBag/gui/GuiConfig.java#L229

 

I don't think I'm missing anything that stupid, am I?

I have no idea what I'm doing.

Posted

GUIs are CLIENT-side only, so any settings you change there are lost when the client closes. You need to save settings on the server, so you will need to send packets if you want the settings to be changed from client side.

 

Also, I didn't actually look at the settings you are changing, but most settings should only be set server side anyway and usually you don't want to expose them client-side at all.

Posted

GUIs are CLIENT-side only, so any settings you change there are lost when the client closes. You need to save settings on the server, so you will need to send packets if you want the settings to be changed from client side.

 

Also, I didn't actually look at the settings you are changing, but most settings should only be set server side anyway and usually you don't want to expose them client-side at all.

 

Ah ok, I thought that you didn't need packets with NBT. As for the settings, they're purely for client-side settings. Even if I do put any server-side values in, they won't be anything beyond the colour of an item or its name, so there's no real danger of exploits there.

I have no idea what I'm doing.

Posted

ItemStack NBT data syncs only one way automatically: from server to client. So, if you make changes on the server (e.g. by sending a packet from the GUI), those changes will be visible on the client side as well.

 

Ah, that makes sense. Thanks a lot.

I have no idea what I'm doing.

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.