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

Currently I have a GUI that sends a packet to the server with an item name, and then the server is supposed to get the item and do something.

 

How would I get an item from just a name? I don't want to use IDs because they'll probably be removed completely I think.

Kain

  • Author

Dug a little deeper, found out how (I think).

GameData.itemRegistry.get(name)

Kain

They are very unlikely to remove IDs; integers are just too handy of a storage method to get rid of entirely, though most users will never know they are there anymore. That was the point of moving to a registration system, but the game itself still tracks everything by ID, so you should be safe doing so as well.

The point to be made here is, never hard-code any IDs from now on. PERIOD. Ever.

If you get an ID temporarily (from a call to the registry for example), expect it to be fine for this session only. Do not ever store it persistently or load it from persistent store and expect it to mean anything.

As long as you get the ID from the registry in the first place, it should be safe to store that for example in an NBT tag, since that's exactly what happens when you write an ItemStack to NBT anyway. The game will refuse to load or at least give you warning messages if any of the items / blocks have changed from the id to string mappings that get stored with the world save. Otherwise, how do you think Minecraft is storing the data itself? Certainly not as complex objects, and it wouldn't make any sense if the ids that were stored in your world save meant nothing the next time you load, as all the items and blocks in the game would be corrupt.

I should have been clearer, I guess. By "persistent store" I meant, any file system outside of the inner minecraft communication system of world storage.

Now I repeat the important part: Never hard-code IDs in the newer version of minecraft.

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.