Posted June 23, 20169 yr Hi, Ive been making an armour mod, where the armour needs to store some nbt data. The data is attached to it via actions in a gui. The only thing is - when the nbt is changed through the gui, the data doesnt seem to sync untill I pick the item from my inventory and put it back. If I relog, the data is gone, if I drop it by pressing 'Q' the data is gone. However if I move it to a different slot, or just drop it manually (as in pick it from the inventory and click outside the gui) the data stays. I presume its something about the nbt not getting synced until the item is interacted with, but my question is why and what do I do with it? Any help will be much appreciated
June 23, 20169 yr Yup, that is right. Few rules: 1. Data manipulation must always happen on server. 2. Gui is client-only! 3. In every case of guis that are supposed to edit something - you will ALWAYS send a packet. General design: * Gui action (e.g buton click) * Client packet to server * Server handles packet (note: thread safety) * Server checks agains requirements (if it is legal for player to do such edit) * Server modifies given ItemStack and client gets update. 4. Now here is a big note: (which you probably know) Whenever there is ItemStack on display (in gui) - there is also Container which handles syncing ItemStacks' visible in-container positions. When ItemStack would get edited on server without notifying - client will stay with old data (that's why it would get updated once you actually move it). Logically - after editing ItemStack on server (from mentioned packet) you will need to notify change. You pretty much do that manually (by sending packet server -> client wth update of stack at given slot in current container which can be accessed from player instance) or you could probably use some internal thing - lookup Container code such as transferStackInSlot and other (which I think does those). 5. Now - you may ask - "If I do it (change) on client-only, why it sometimes gets saved?" - well, if nothing changed since I was hanving fun with it - just change your game mode (creative game mode allows bi-directional ItemStack updates) - that is if nothing changed. 1.7.10 is no longer supported by forge, you are on your own.
June 23, 20169 yr Author Thanks for the reply! Thats a lot of info Some of it I knew, but not all. Well, I guess I'll have to go read up about custom packets, as I know the theory but haven't ever actually used them... Oh and the change to creative thing does still work
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.