Jump to content

Getting an Item from String


TLHPoE

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • It will be about medeaival times
    • the mods are crashing and I'm not sure why so heres everything  crash log https://pastebin.com/RxLKbMNR  L2 Library (12library) has failed to load correctly java.lang.NoClassDefFoundError: org/antarcticgardens/newage/content/energiser/EnergiserBlock L2 Screen Tracker (12screentracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create: Interiors (interiors) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.tterrag.registrate.AbstractRegistrate L2 Damage Tracker (12damagetracker) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create Enchantment Industry (create_enchantment_industry) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.Createfiegistrate Create Crafts & Additions (createaddition) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate Create Slice & Dice (sliceanddice) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Tabs (12tabs) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Modular Golems (modulargolems) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate Create: Steam 'n' FRails (railways) has failed to load correctly java.lang.NoClassDefFoundError : Could not initialize class com.simibubi.create.foundation.data.Createfregistrate Cuisine Delight (cuisinedelight) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.12library.base.L2Registrate Create (create) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.Create Guardian Beam Defense (creategbd) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class com.simibubi.create.foundation.data.CreateRegistrate L2 Item Selector (12itemselector) has failed to load correctly java.lang.NoClassDefFoundError: Could not initialize class dev.xkmc.l2library.base.L2Registrate
    • hey there, I have been using Forge for years without any problems, but for some time now I have been getting this error message when I click on “Installer” under the downloads. This happens on all versions. I have tried various things but have not gotten any results. If anyone has a solution, I would be very grateful!
    • I don't have mcreator installed.
    • the session has expired, what if the modified LAN Server displays the same screen after logging in as after logging in to the premium server from a non-premium account? Minecraft Forge 1.20.1 CurseForge. I also use Mod LAN World Plug n Play
  • Topics

×
×
  • Create New...

Important Information

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