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, is there a way to translate the unlocalized names of liquids, blocks and items ?

 

e.q. i have the unlocalized name of an item as String (not the instance of the item). I want to build a method like this getTranslation("tile.whatever.a.block.or.item"); Is there any method to translate these Strings ? or is there a method to find Items via the name?

I hope I understand you good and you want to give the item a nicer name.

 

Create a package called "assets.yourmodid.lang" in src/main/resources.

create a file in the new package called "en_US.lang".

 

write in the .lang file "item.THEUNLOCALIZEDNAME.name = the nice name".

 

I believe you can find items this way:

ItemRegister.itemname

  • Author

No, i know how i translate my items. I want a method to read these translations.

Here's some methods to get the name translated to what Minecraft reads it as:

 

@Override
public String getUnlocalizedName() {
	return String.format("item.%s%s", Textures.BLOCK_ITEM_TEXTURE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}

@Override
public String getUnlocalizedName(ItemStack is) {
	return String.format("item.%s%s", Textures.BLOCK_ITEM_TEXTURE_PREFIX, getUnwrappedUnlocalizedName(super.getUnlocalizedName()));
}

public String getUnwrappedUnlocalizedName(String unlocalizedName) {
	return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1);
}

 

The name basically ends up like this: tile.modid:block/item name.name

To get a nicer name from that, you could do something like this:

 

String nicerName = "nicernamehere";

 

This would be code-only, and not what the user sees. Getting a nicer name without using the lang method is impossible, as there is the only place Minecraft reads the names from. Getting Minecraft to read names from somewhere else in addition to lang files would be hard, time-consuming, and editing the base files. The only real way to do this without lang would be to use the LanguageRegistry, something that is not recommended for 1.7 and will be removed in 1.8. All in all, either just make a string with the nicer name, or simply use the lang method. They are both simple enough for a first-time user of Eclipse and are there for a reason.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

I think what OP means is a way to get the 'translated' names of Blocks, Items, and Liquids that he didn't create.

 

To do so, it simply requires like I said to use StatCollector.translateToLocal(unlocalisedName).

 

This will not only get the user readable name, but it will also translate it to the appropriate language that the user is currently using (I believe).

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Ahhh. Yes, that makes a lot more sense. StatCollector.translateToLocal(unlocalizedName) is definitely the way to go. However, having looked at the source, I don't completely understand how that method works, but I guess it does.

 

@diesieben07: Yes, I know that code is from Pahimar. It just works so well that I showed it to seppitm. What's so BS about it?

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

Aha. Yes, I do agree with you diesieben, that is much cleaner and simpler. Pahimar's version adds a lot of confusing methods, and he does not explain them very well, to his detriment. I still do not understand why that substring hackyness is even there. Seppitm, use the method diesieben just described, as mine/Pahimar's is much more confusing.

I am the self-nominated Lord of the Mastodons and don't you dare deny it. ;) Also, check out my YouTube channel: https://www.youtube.com/user/DerpDerp44/

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.