Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.