Jump to content

[1.8.9] Item metadata


Spyeedy

Recommended Posts

Okay, so i've created my own Item with 4 metadata value. The problem is that I want each of my metadata items to have a different name instead of having one uniformed name. As you can see in the image below, I used one localization and all the metadata's names have the same name.

8mzyR6O.gif

 

ItemMetadata class:

 

 

public class MetaRing extends Item
{
public MetaRing()
{
	this.setHasSubtypes(true);
	this.setUnlocalizedName("meta_ring");
	this.setRegistryName("meta_ring");
	this.setHasSubtypes(true);
	this.setCreativeTab(Main.tabBrothers);
}

@Override
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems)
{
	subItems.add(new ItemStack(itemIn, 1, 0));
	subItems.add(new ItemStack(itemIn, 1, 1));
	subItems.add(new ItemStack(itemIn, 1, 2));
	subItems.add(new ItemStack(itemIn, 1, 3));
}
}

 

 

 

RegisterItems class:

 

 

public class RegisterItems
{
public static Item meta_ring;

public static void main()
{
	init();
	register();
}

private static void init()
{
	meta_ring = new MetaRing();
}

private static void register()
{
	GameRegistry.registerItem(meta_ring, meta_ring.getRegistryName());
}

public static void registerRenders()
{
	PlayHelper.registerRenderMetaItems(meta_ring, 0, "white_meta_ring");
	PlayHelper.registerRenderMetaItems(meta_ring, 1, "red_meta_ring");
	PlayHelper.registerRenderMetaItems(meta_ring, 2, "blue_meta_ring");
	PlayHelper.registerRenderMetaItems(meta_ring, 3, "green_meta_ring");
}
}

 

 

 

Registered RegisterItems#main in my Mod class's preInit and RegisterItems#registerRenders in my ClientProxy's preInit.

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

You need to override

getUnlocalizedName(ItemStack)

in your

Item

class and return whatever unlocalized name you want based on the metadata.

 

Hm, can I use the if statements and check if the ItemDamage is equals to a specific value, then return the String of the name?

width=620 height=260http://www.startrek.com/uploads/assets/articles/61c89a9d73c284bda486afaeaf01cdb27180359b.jpg[/img]

Till next time. Thank you for delivering funny scenes to Star Trek as Chekov :) . Will always remember you

Link to comment
Share on other sites

You'd be stunned by how much data is stored by Minecraft in order to avoid calculating it every time it is needed. Just think of the model bakery...

 

A switch statement would compile into a jump table much like the array I suggested. The only difference might be where the strings are stored (or maybe only where the pointers to the strings are stored).

 

For a compact data set with known contiguous index, a static array should fit perfectly.

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.