Posted August 25, 201411 yr 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?
August 25, 201411 yr 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
August 25, 201411 yr Author No, i know how i translate my items. I want a method to read these translations.
August 25, 201411 yr StatCollector.translateToLocal() BEFORE ASKING FOR HELP READ THE EAQ! I'll help if I can. Apologies if I do something obviously stupid. If you don't know basic Java yet, go and follow these tutorials.
August 25, 201411 yr 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/
August 25, 201411 yr 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. If you don't know basic Java yet, go and follow these tutorials.
August 25, 201411 yr 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/
August 25, 201411 yr 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.