Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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

Or you could pull a string from an array of strings using meta as the index.

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.

Or you could pull a string from an array of strings using meta as the index.

 

Would this really be better, just because the code is a bit shorter? I mean you store the Strings in the Array the whole time with that solution

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.