I'm trying to make only one class be required to name the subblocks of any metablock that use this class at the time of the record, that is, name them as if they were parameter values, but without using one.
Although this revolves around an API (Minecraft Forge), I think the problem is more of Java, so here is a brief explanation of how it works what I intend to do.
A metablock is made up of subblocks, which are variations of the same block (for example, the same block, but only changes the texture and name). Each subblock needs a name to identify it. These names are listed in the ExemploItemBlock
class in a String[]
, and are then named in nomeDoMetablock.nomeDoSubBlock
format (eg ExemploMetablock.azul
, ExemploMetablock.verde
, etc.)
// Classe ExemploItemBlock
public static final String[] SUBNAMES = new String[] {"azul", "verde", "amarelo"};
@Override
public String getUnlocalizedName(ItemStack itemStack)
{
int i = itemStack.getItemDamage();
return getUnlocalizedName() + "." + SUBNAMES[i];
}
Then the ExemploMetaBlock
metablock is instantiated and registered with
// Classe onde são feitos os registros
public static Block ExemploMetaBlock = new ExemploMetaBlock();
GameRegistry.registerBlock(ExemploMetaBlock, ExemploItemBlock.class, "ExemploMetaBlock");
After this, everything works without problems, however I would have to create an ItemBlock class for each new metablock I want to do, and I do not find this very practical or appropriate, thinking better to create a single class to be used by any future metablock .
As you can see, the second parameter of the GameRegistry.registerBlock()
method (which is an API method) requires a value of type Class
. And that's where the problem is: how do I make the class ExemploItemBlock
dynamic without using instances?
I even tried to add a String [] parameter in the ExemploItemBlock
constructor and use an instance with the names in place of the class name, but, as expected, accused type mismatch, as it is only Class
o type accepted.
I searched everywhere for a way to do this, but I only found two ways:
1. create an ItemBlock class for each new metablock; 2. change SUBNAMES[i]
in getUnlocalizedName()
by i
or itemStack.getItemDamage()
naming so the subblocks by numbers instead of names (eg ExemploMetaBlock.0
, ExemploMetaBlock.1
, etc.), without having to use String [] or anything and becoming a universal class. But this way is also very antipractical, because then it is very difficult to identify which subblock is which.
So my question is: is there any way to get a Universal ItemBlock class, but naming the subblocks by names (words)?
Class Content: ExampleBetaBlock , ExampleItemBlock .