Jump to content

[1.10.2] How to get ModId from Item


Purplicious_Cow

Recommended Posts

In 1.710, I had this nifty piece of code that could pull the ModId from an item. In 1.10.2, GameRegistry has changed, and with it, it seems, is the path to get ModId. Can anyone point me in the correct direction?

 

I use the modid for various purposes.

 

1.7.10 code that worked:

public static String getModId(Item item) {
GameRegistry.UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor(item);
return id == null || id.modId.equals("") ? "minecraft" : id.modId;
}

public static String getModId(ItemStack key) {
return getModId(key.getItem());
}

 

 

Link to comment
Share on other sites

Wait, so do you not know your ModID? When you make your mom, one of the first steps is making YOUR OWN ModID. You set it early on.

 

There are several ways to do this too.

my personal favorite, is

@Mod(modid = Reference.MOD_ID);

 

Refernece is another class, where i did

	public static final String MOD_ID = "tmm";

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

I have not yet seen a way to get -only- the modid, but as you have an item, you can get the registryname which contains it, then split the string with the regex ":". Hacky way, but should be do-able.

 

 

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

The registry name is a

ResourceLocation

, the domain of which (

ResourceLocation#getResourceDomain

) is the mod ID. You don't need to resort to string parsing.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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



×
×
  • Create New...

Important Information

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