Jump to content

Two of four subblock's names are the same


DoktuhParadox

Recommended Posts

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.

 

Link to comment
Share on other sites

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.

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.