Jump to content

Naming metadata blocks, and block tooltips [SOLVED] [1.7.10]


TheEpicTekkit

Recommended Posts

Hello everyone.

 

So, I would like to know how I can name metadata blocks. I currently cant figure it out at all, even after looking at vanilla things like wool, I cant find how they name them, I can find, and have made my own version of, a string array with all the names, and the name is located in the array at its metadata position. So I mean that for example, if the metadata is 2, then its name would be the third second string in the array (0, 1, 2...). Now, I will if there is no other way, but I don't want to have to do a languageRegistry.addName for each metadata, I would like to be able to use a for loop that loops through each metadata, and gets the corresponding name from the array, but the only place I can do that from is the block class, but I cant register the names in the block class, because by the time that method has been called, the block is already registered with the name tile.myBlock.name.

 

Now, I would also like to know how to add tooltips for a block. I do know that this involves an ItemBlock, but I don't know how to set up an itemblock, and I cant find any tutorials anywhere.

 

Thanks.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

I don't actually think I have done the metadata subblocks correctly then. The following is all of my metadata related methods.

 

Names

        //This is static so that I can access it outside the class without needing to create an unnecessary instance of it.
        public static String[] names = new String[] {
	"LV Cable", "Uninsulated Tin Wire", "MV Cable", "Uninsulated Copper Wire", "HV Cable", "Uninsulated Gold Wire", "UV Cable", "Uninsulated Reactor Cable"
};

 

Getting all subBlocks

        @Override
@SideOnly(Side.CLIENT)	
public void getSubBlocks(Item itemStack, CreativeTabs tab, List list) {
	for (int i = 0; i < this.names.length; i++) {
		list.add(new ItemStack(itemStack, 1, i));
	}
}

 

Get damage dropped

        @Override
public int damageDropped(int meta) {
	return meta;
}

 

I don't know if this is relevant, or will affect anything, but my block extends BlockContainer. I wouldn't really expect this to make a difference, but, might be worth mentioning.

 

Now, I don't know if I have missed any important methods here, so please tell me if I have missed a method. I don't know if I have an itemblock (well, I do have an itemblock, every block has one, but I don't have a custom one, and, at least, all the subblocks have the same itemblock.) Also, another thing that I don't know why is happening, is that if I pick up a block with one metadata, say, metadata 4, and then I pick up another of that block with a different metadata, they will stack, and get turned into the metadata of the first block I picked up, and this is a very strange bug, I haven't seen that before.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Okay, thanks, I have it working almost perfectly now, even the tooltips. Unfortunately, there is as always, another problem. The naming is weird. Now, what is happening is that metadata 0 is taking the 8th name in the array for some reason, ("Uninsulated Reactor Cable" this is without tile.myBlock.name), and the rest are taking the appropriate name from the array, so meta 1 is taking "Uninsulated Tin Wire" etc, but with tile.cable. and .name at the start and end.

 

So...

metadata 0: "Uninsulated Reactor Cable"

metadata 1: "tile.cable.Uninsulated Tin Wire.name"

metadata 2: "tile.cable.MV Cable.name"

and the same for the rest, "tile.cable.NameFromArray.name"

 

The way I am registering the names and block is like so:

                for (int i = 0; i < BlockCable.names.length; i++) {
		LanguageRegistry.addName(new ItemStack(cable, i), BlockCable.names[i]);
                      //LanguageRegistry.addName(new ItemStack(BlockToName, metadata), name);
	}
	GameRegistry.registerBlock(cable, ItemBlockCable.class, "itemBlockCable");
              //GameRegistry.registerBlock(BlockToRegister, BlocksItemBlockClass.class, "name");

And, this is where I am registering all my blocks. It is not in the block class it self.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Sorry for the late reply.

 

ItemBlockCable

package generator.net.theepictekkit.generator.common.blocks.itemblocks;

import java.util.List;

import generator.net.theepictekkit.generator.common.blocks.BlockHandler;
import generator.net.theepictekkit.generator.common.blocks.advanced.BlockCable;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemBlockCable extends ItemBlock {

public ItemBlockCable(Block cable) {
	super(cable);
	cable = BlockHandler.cable;
	this.setHasSubtypes(true);
	this.setUnlocalizedName("itemBlockCable");
}

@Override
public int getMetadata (int meta) {
	return meta;
}

@Override
public String getUnlocalizedName (ItemStack stack) {
	return this.getUnlocalizedName() + "." + BlockCable.names[stack.getItemDamage()];
}

@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
	int meta = stack.getItemDamage();

	list.add("ToolTip for metadata " + meta); //This was a tooltip test.
}
}

 

And, how do I set up a language file? I know what they are, but haven't really bothered to use them when I probably should. Can you point me to a good tutorial for language files?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

Okay.

 

My cable names were in the code above.

        public static String[] names = new String[] {
	"LV Cable", "Uninsulated Tin Wire", "MV Cable", "Uninsulated Copper Wire", "HV Cable", "Uninsulated Gold Wire", "UV Cable", "Uninsulated Reactor Cable"
};

 

Also, come to think of it, I am now noticing something....

 

this.getUnlocalizedName() + "." + BlockCable.names[stack.getItemDamage()]; in the getUnlocalizedName method in the itemblock seems to be what it is being named.

 

getUnlocalizedName always returns its unlocalized name with the prefix "tile."

then it is selecting the name from the array.

and I'm guessing that this is in-properly naming it, as in-properly named things end with ".name"

 

So, what is the proper way to name an ItemBlock.

 

I know that I could add ".substring(11, 5)" to remove 11 characters from the front of the string; "tile.cable." and 5 characters from the end of the string; ".name" but, this is almost certainly in-properly naming it too.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Link to comment
Share on other sites

In an array, am I right in thinking that the first object is at position 0, the second at position 1 etc. it starts at 0, not 1. This is what I always found the case to be. But, if I am wrong, then that might be the problem.

 

Also, with the lang file, are un-named blocks that don't have a TileEntity "block.unLocalizedName.name" or "tile.unLocalizedName.name"?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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.