Jump to content

Localizing Block Name


mrkirby153

Recommended Posts

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.);
}

}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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

    • A friend found this code, but I don't know where. It seems to be very outdated, maybe from 1.12? and so uses TextureManager$loadTexture and TextureManager$deleteTexture which both don't seem to exist anymore. It also uses Minecraft.getMinecraft().mcDataDir.getCanonicalPath() which I replaced with the resource location of my texture .getPath()? Not sure if thats entirely correct. String textureName = "entitytest.png"; File textureFile = null; try { textureFile = new File(Minecraft.getMinecraft().mcDataDir.getCanonicalPath(), textureName); } catch (Exception ex) { } if (textureFile != null && textureFile.exists()) { ResourceLocation MODEL_TEXTURE = Resources.OTHER_TESTMODEL_CUSTOM; TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.deleteTexture(MODEL_TEXTURE); Object object = new ThreadDownloadImageData(textureFile, null, MODEL_TEXTURE, new ImageBufferDownload()); texturemanager.loadTexture(MODEL_TEXTURE, (ITextureObject)object); return true; } else { return false; }   Then I've been trying to go through the source code of the reload resource packs from minecraft, to see if I can "cache" some data and simply reload some textures and swap them out, but I can't seem to figure out where exactly its "loading" the texture files and such. Minecraft$reloadResourcePacks(bool) seems to be mainly controlling the loading screen, and using this.resourcePackRepository.reload(); which is PackRepository$reload(), but that function seems to be using this absolute confusion of a line List<String> list = this.selected.stream().map(Pack::getId).collect(ImmutableList.toImmutableList()); and then this.discoverAvailable() and this.rebuildSelected. The rebuild selected seemed promising, but it seems to just be going through each pack and doing this to them? pack.getDefaultPosition().insert(list, pack, Functions.identity(), false); e.g. putting them into a list of packs and returning that into this.selected? Where do the textures actually get baked/loaded/whatever? Any info on how Minecraft reloads resource packs or how the texture manager works would be appreciated!
    • This might be a long shot , but do you remember how you fixed that?
    • Yeah, I'll start with the ones I added last night.  Wasn't crashing until today and wasn't crashing at all yesterday (+past few days since removing Cupboard), so deductive reasoning says it's likeliest to be one of the new ones.  A few horse armor mods and a corn-based add-on to Farmer's Delight, the latter which I hope to keep - I could do without the horse armor mods if necessary.  Let me try a few things and we'll see. 
    • Add crash-reports with sites like https://mclo.gs/ Add this mod: https://www.curseforge.com/minecraft/mc-mods/packet-fixer/files/5416165
  • Topics

×
×
  • Create New...

Important Information

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