Multi Textured Block

Today I will show another tutorial on doing multi textured blocks. I will be making a dice block with different textures to the respective sides. The block wont have rotation, however. I will do that in a different tutorial. Here’s the textures, as always, free to use:
     

This will all be done in the block class. So, let’s apply what we know from previous tutorials, and make a normal block class.

public class BlockDice extends Block
{
    private static final String name = "dice";

    public BlockDice()
    {
        super(Material.iron);
        GameRegistry.registerBlock(this, name);
        setBlockName(name);
        setCreativeTab(CreativeTabs.tabBlock);
    }
}

There, we have our custom block class. Don’t forget to register it in your ModBlocks class! Now, let’s do the texturing, because this block currently has no textures. To do that, we have to add two methods, registerBlockIcons() and getIcon(), also add an IIcon array to store our icons.

public class BlockDice extends Block
{
    private static final String name = "dice";

    private IIcon[] icons = new IIcon[6];

    public BlockDice()
    {
        super(Material.iron);
        GameRegistry.registerBlock(this, name);
        setBlockName(name);
        setCreativeTab(CreativeTabs.tabBlock);
    }

    @Override
    public void registerBlockIcons(IIconRegister reg)
    {
        for (int i = 0; i < 6; i++)
        {
            icons[i] = reg.registerIcon(TutorialMod.MODID + ":" + name + "_" + (i + 1));
        }
    }

    @Override
    public IIcon getIcon(int side, int meta)
    {
        return icons[side];
    }
}

I’ve added an icon arraycalled icons, and made it 6 long with the following:

private IIcon[] icons = new IIcon[6]

Also, let’s take a look at the registerBlockIcons() method:

@Override
public void registerBlockIcons(IIconRegister reg)
{
    for (int i = 0; i < 6; i++)
    {
        icons[i] = reg.registerIcon(TutorialMod.MODID + ":" + name + "_" + (i + 1));
    }
}

In it, a for-loop that registers 6 different numbered icons for each entry in our icon array. With this, the texture names should be dice_1.png, dice_2.png and so on. If you want to start from 0, remove the + 1 in the end. I prefer to start from 1, because the dice dots does not start from 0.

Now, let’s take a look at our getIcon() method.

@Override
public IIcon getIcon(int side, int meta)
{
    return icons[side];
}

This simply means it will return each icons for respective sides. Remember this:

  • Side 0 is facing the bottom
  • Side 1 is facing the top
  • Side 2 is facing north
  • Side 3 is facing south
  • Side 4 is facing west
  • Side 5 is facing east

That’s it for this tutorial, I hope you enjoyed it!

Leave a comment