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

I have a block with four subblocks including itself. The first two have their appropriate names, the last two have the same name. I tested adding a fifth sub block, and its name was the same as the other two as well.

 

Here are the snippets of interest:

 

In the Block.class:

    private Icon[] icons;
    ...
    public void registerIcons(IconRegister iconRegister)
    {
        blockTextures = new Icon[4]; //Change this according to how many blocks there are

        for (int i = 0; i < blockTextures.length; i++)
        {
            this.setUnlocalizedName("XailiteBlock|" + i);
            blockTextures[i] = iconRegister.registerIcon("xailite:" + (i == 0 ? "XailiteOre" : i == 1 ? "XailiteBlock" : i == 2 ? "TemperedXailiteOre" : i == 3 ? "RefinedXailiteBlock" : null));
        }
    }

 

In the ItemBlock.class:

    public String getUnlocalizedName(ItemStack itemstack)
    {
        String name;
        switch (itemstack.getItemDamage())
        {
            case 0:
                name = "world";
                break;

            case 1:
                name = "nether";
                break;

            default:
                name = "broken";
                break;
        }
        return this.getUnlocalizedName() + "." + name;
    }

 

Registering the block:

GameRegistry.registerBlock(xailiteBlock, ItemXailiteBlock.class, "Xailite" + xailiteBlock.getUnlocalizedName().substring(5));

 

Giving them display names:

LanguageRegistry.addName(new ItemStack(xailiteBlock, 1, 2), "Refined Xailite Block");
LanguageRegistry.addName(new ItemStack(xailiteBlock, 1, 3), "Tempered Xailite Ore");

 

The two blocks with the same name are the refined block and the tempered ore. They return the correct block when broken, the recipes are correct, etc. the only discrepancy is them having the same name.

 

Try moving

this.setUnlocalizedName()

method to its own method:

 

@Override
public String getUnlocalizedName(ItemStack item) {
	return this.getUnlocalizedName() + "." + <YOUR NAME HERE>;
}

 

Use a "." instead of a "|" in the name. That might be another cause of the problem.

  • Author

Well, here's the block file now:

public class XailiteBlock extends Block
{
    public XailiteBlock(int id)
    {
        super(id, Material.rock);
        this.setCreativeTab(Xailite.xailiteTab);
        this.setHardness(5.5F);
    }

    @SideOnly(Side.CLIENT)
    private Icon[] blockTextures;

    public void registerIcons(IconRegister iconRegister)
    {
        blockTextures = new Icon[4]; //Change this according to how many blocks there are

        for (int i = 0; i < blockTextures.length; i++)
        {
            blockTextures[i] = iconRegister.registerIcon("xailite:" + (i == 0 ? "XailiteOre" : i == 1 ? "XailiteBlock" : i == 2 ? "TemperedXailiteOre" : i == 3 ? "RefinedXailiteBlock" : null));
        }
    }

    @Override
    public Icon getIcon(int id, int metadata)
    {
        return blockTextures[metadata];
    }

    @Override
    public void getSubBlocks(int id, CreativeTabs tab, List subBlockList)
    {
        for (int i = 0; i < blockTextures.length; ++i)
        {
            subBlockList.add(new ItemStack(id, 1, i));
        }
    }

    @Override
    public int damageDropped(int metadata)
    {
        this.setUnlocalizedName("XailiteBlock|" + metadata);
        return metadata;
    }

    @Override
    public boolean isBeaconBase(World worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ)
    {
        return worldObj.getBlockMetadata(x, y, z) == 1;
    }

    public String getUnlocalizedName(ItemStack itemStack)
    {
        return this.getUnlocalizedName() + "Xailite";
    }
}

 

But it doesn't seem to work. And it's definitely the last two blocks having the same unlocalized name.

  • Author

Fixed it! It turns out that the unlocalized name switch needed the cases for the two other damage values in order to make a different unlocalized name.

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.