The simplest way to do this would be to create a generic class which extends BlockOre and contains the name you need to retrieve, such as:
public class GenericBlockOre extends BlockOre
{
final String name;
@SideOnly(Side.CLIENT)
public IIcon iconOre, iconNetherOre, iconEndOre;
public GenericBlockOre(final int id, final String name)
{
super(id);
this.name = name;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
iconOre = iconRegister.registerIcon(Reference.MODID + ":End" + this.name + "Ore");
iconNetherOre = iconRegister.registerIcon(Reference.MODID + ":Nether" + this.name + "Ore");
iconEndOre = iconRegister.registerIcon(Reference.MODID + ":" + this.name + "Ore");
}
}
And your items would become:
public static Block aluminumOre = new GenericBlockOre(1, "Aluminum");
public static Block vibraniumOre = new GenericBlockOre(2, "Vibranium");
public static Block poloniumOre = new GenericBlockOre(3, "Polonium");
Or if you really need to create a new class as well, the extending classes could be as simple as:
class AluminumOre extends GenericBlockOre
{
public AluminumOre()
{
super(1, "Aluminum");
}
}
N.B. Obviously you can't use 1
, 2
, 3
as your block IDs and need to be changed.
However, if you are absolutely certain it has to be generic and you're willing to sacrifice the efficiency of your mod for it, you could do this to maniuplate the ore name out of the class:
final AluminumOre ore = new AluminumOre();
final String className = ore.getClass().getSimpleName();
final String oreName = className.substring(0, className.indexOf("Ore"));
System.out.println(oreName); //Prints: Aluminum