Posted June 14, 201312 yr Hello, I was wondering if it was possible for me to get a localized block name. I am trying to get the block name as the lore but it shows up as "blockEmerald" if i was to add an emerald. I was wondering how to localize the name so it would display as "Emerald Block", the localized version of the block. My Item code: package mrkirby153.MscHouses.items; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import mrkirby153.MscHouses.api.MaterialRegistry; import mrkirby153.MscHouses.core.MscHouses; import mrkirby153.MscHouses.core.helpers.LogHelper; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ItemModifyer_Extra extends Item { public int[] modifyer_id; public ArrayList<Block> material; @SideOnly(Side.CLIENT) private Icon[] field_94594_d; public ItemModifyer_Extra(int par1) { super(par1); this.setHasSubtypes(true); this.setMaxDamage(0); material = MaterialRegistry.blocks; this.makeSubItems(); this.modifyer_id = new int[material.size()]; this.setCreativeTab(MscHouses.tabHouse_moduel); } @Override @SideOnly(Side.CLIENT) public Icon getIconFromDamage(int par1) { int j = MathHelper.clamp_int(par1, 0, 15); return this.field_94594_d[j]; } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { this.field_94594_d = new Icon[material.size()]; for(int i =0; i < material.size(); i++){ this.field_94594_d[i] = par1IconRegister.registerIcon("MscHouses:Cusom_modifyer"); } // LogHelper.log(Level.INFO, "Succesfully loaded " + modifyer_id.length + " textures"); } @Override @SideOnly(Side.CLIENT) public void getSubItems(int itemID, CreativeTabs tab, List itemList) { for(int i = 0; i < material.size(); i++){ itemList.add(new ItemStack(itemID,1,i)); } } @Override public String getUnlocalizedName(ItemStack item) { return this.getUnlocalizedName() + "." + modifyer_id[item.getItemDamage()]; } public void makeSubItems(){ Block var2; Block[] var3 = new Block[material.size()]; var3 = material.toArray(var3); for(int i = 1; i < var3.length; i++){ var2 = var3[i]; this.modifyer_id[i] = var2.blockID; LogHelper.log(Level.INFO, "Created sub item for item id " + var2.blockID); } } @Override @SideOnly(Side.CLIENT) public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { Block[] var1 = new Block[material.size()]; var1 = material.toArray(var1); par3List.add(var1[par1ItemStack.getItemDamage()].getUnlocalizedName2()); // par3List.add(LanguageRegistry.instance().addStringLocalization(var1[par1ItemStack.getItemDamage()].getUnlocalizedName(), Block.); } } http://i.imgur.com/gWwyMMO.jpg[/img]
June 14, 201312 yr LanguageRegistry.addName(new ItemStack(myItem,1,myMetadata),"My Item"); BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
June 14, 201312 yr Author LanguageRegistry.addName(new ItemStack(myItem,1,myMetadata),"My Item"); I cannot do that because I am already using that to give the item its name. I want to give it a custom lore WITHOUT having to hard code the item names/lore into it manually. http://i.imgur.com/gWwyMMO.jpg[/img]
June 14, 201312 yr LanguageRegistry.addName(new ItemStack(myItem,1,myMetadata),"My Item"); I cannot do that because I am already using that to give the item its name. I want to give it a custom lore WITHOUT having to hard code the item names/lore into it manually. Oh. Well, you can use my code then. for(String i:(Set<String>) StringTranslate.getInstance().getLanguageList().keySet()){ lang.put(i,new HashMap<String,String>()); } BufferedReader br = new BufferedReader(new InputStreamReader(modsbfp.class.getResourceAsStream("/mods/sbfp/lang/sbfp.lang"))); try{ String q, l = null; while((q = br.readLine())!=null){ if(q.equals("")||q.charAt(0)=='#'){ continue; } if(q.contains("=")){ String key = q.substring(0,q.indexOf("=")); String value = q.substring(q.indexOf("=")+1); LanguageRegistry.instance().addStringLocalization(key,l,value); }else{ l = q; } } }catch(IOException e){ e.printStackTrace(); } It works for multiple languages too. Here's the lang file, so you know how that works: de_DE oreThorium.name=Monazit oreFluorite.name=Fluorit oreMoS2.name=Molybdänit oreRutile.name=Rutil oreCinnabar.name=Zinnober oreLimonite.name=Limonit orePyrolusite.name=Pyrolusit oreAs.name=Arsenopyrit redFluxAmp.name=Redstonefluss-Verstärker redFluxAbsorber.name=Redstonefluss-Absorber redFluxStabilizer.name=Redstonefluss-Stabilisator chargedRedstone.name=Geladen Redstone dyeTiO2.name=Weiß Farbstoff dyeVermillion.name=Rot Farbstoff dyeOchre.name=Gelb Farbstoff dyeUltramarine.name=Blau Farbstoff dyeMnO2.name=Schwarz Farbstoff dyeGreen.name=Grün Farbstoff dyePurple.name=Purpur Farbstoff dyeOrange.name=Orange Farbstoff dyeGrey.name=Grau Farbstoff solarCharger.name=Redstonefluss-Infuser ######################## en_US oreThorium.name=Monazite oreFluorite.name=Fluorite oreMoS2.name=Molybdenite oreRutile.name=Rutile oreCinnabar.name=Cinnabar oreLimonite.name=Limonite orePyrolusite.name=Pyrolusite oreAs.name=Arsenopyrite redFluxAmp.name=Redstone Flux Amplifier redFluxAbsorber.name=Redstone Flux Absorber redFluxStabilizer.name=Redstone Flux Stabilizer chargedRedstone.name=Charged Redstone dyeTiO2.name=Titanium White dyeVermillion.name=Vermillion dyeOchre.name=Ochre dyeUltramarine.name=Ultramarine dyeMnO2.name=Manganese Black dyeGreen.name=Green Dye dyePurple.name=Purple Dye dyeOrange.name=Orange Dye dyeGrey.name=Grey Dye solarCharger.name=Redstone Flux Infuser item.itemSecret.name=Secret ######################## es_ES oreThorium.name=Monacita oreFluorite.name=Fluorita oreMoS2.name=Molibdenita oreRutile.name=Rutilo oreCinnabar.name=Cinabriio oreLimonite.name=Limonita orePyrolusite.name=Pirolusita oreAs.name=Arsenopirita redFluxAmp.name=Amplificador del Flujo de Redstone redFluxAbsorber.name=Absorbedor del Flujo de Redstone redFluxStabilizer.name=Estabilizador del Flujo de Redstone chargedRedstone.name=Redstone Chargado dyeTiO2.name=Blanco del Titanio dyeVermillion.name=Bermellón dyeOchre.name=Ocre dyeUltramarine.name=Azul Ultramar dyeMnO2.name=Negro del Manganeso dyeGreen.name=Tinte Verde dyePurple.name=Tinte Púrpura dyeOrange.name=Tinte Anaranjado dyeGrey.name=Tinte Gris #solarCharger.name= ######################## la_CL oreThorium.name=monazīta No, the long lines of hashmarks are not necessary. I just use them to seperate languages. BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
June 15, 201312 yr Author but how would i get the lang from the default language file? http://i.imgur.com/gWwyMMO.jpg[/img]
June 15, 201312 yr but how would i get the lang from the default language file? Why would you need to? BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
June 15, 201312 yr Author Actually, I sort of need to get the block name from a different mod. See, I am writing an API for my mod and sort of need to get the localized block name that the mod author sets for display on my item. http://i.imgur.com/gWwyMMO.jpg[/img]
June 15, 201312 yr Regardless of how they set it: StringTranslate.getInstance().translateKey("whatever"); BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
June 15, 201312 yr Author So, for the "whatever" do I just pass in an unlocalized name given through block.getUnlocalizedName()? http://i.imgur.com/gWwyMMO.jpg[/img]
June 15, 201312 yr So, for the "whatever" do I just pass in an unlocalized name given through block.getUnlocalizedName()? Yes. Nota Bene: that function will return the translated key for the currently loaded language. If you want any other language, you will have to mess with StringTranslate itself—loadLanguage() is private. BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
June 16, 201312 yr Author That didn't really work. If I pass in getUnlocalozedName(), it prints out tile.blockDiamond. if i was to pass Block.diamond into it. If I pass getUnlocalozedName2(), it prints out blockDiamond. I want it to print out "Diamond Block". How do i do that? http://i.imgur.com/gWwyMMO.jpg[/img]
June 16, 201312 yr StringTranslate.getInstance().translateKey("whatever"); Instead of "whatever" you put... either the first or the second, I can't remember. BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
June 16, 201312 yr Author I've tried both unlocalized names and neither worked. http://i.imgur.com/gWwyMMO.jpg[/img]
June 17, 201312 yr I have been known to give people complicated solutions when simple ones are there. Derp. Try BlockDiamond.getLocalizedName()? BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech.
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.