1
I am trying to make only one class necessary to name the subblocks of any metablock that uses this class at the time of the record, ie naming them as if they were parameter values, but without using a.
Although this revolves around an API (Minecraft Forge), I think the problem is more Java, so I make here a brief explanation of how it works what I intend to do.
A metablock is composed of subblocks, which are variations of the same block (for example, the same block, but which only changes the texture and name). Each subblock needs a name to identify it. These names are listed in the class ExemploItemBlock
in a String[]
, and then are named in the format nomeDoMetablock.nomeDoSubBlock
(ex.: ExemploMetablock.azul
, ExemploMetablock.verde
, etc.), with
// 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 metablock ExemploMetaBlock
is instantiated and recorded with
// Classe onde são feitos os registros
public static Block ExemploMetaBlock = new ExemploMetaBlock();
GameRegistry.registerBlock(ExemploMetaBlock, ExemploItemBlock.class, "ExemploMetaBlock");
After that, everything works smoothly, however I would have to create an Itemblock class for every new metablock I want to do, and I don’t think this is very practical or appropriate, finding it best to create a single class to be used by any future metablock.
As you can see, the second parameter of the method GameRegistry.registerBlock()
(which is an API method) requires a value of type Class
. And that’s the problem: how I’m going to make class ExemploItemBlock
dynamics without using instances?
I even tried to add a String[] parameter to the ExemploItemBlock
and use an instance with the names in place of the class name, but as expected, accused incompatibility of types, as it is just Class
the accepted type.
I looked everywhere for a way to do this, but only found two ways:
1. create an Itemblock class for each new metablock;
2. trade in SUBNAMES[i]
in the getUnlocalizedName()
for i
or itemStack.getItemDamage()
naming subblocks by numbers instead of names (eg.: ExemploMetaBlock.0
, ExemploMetaBlock.1
, etc.), without using String[] or anything and becoming a universal class. But this way is also very antipratic, because then it makes it very difficult to identify which subblock is which.
So my question is: is there any way to get a universal Itemblock class, but name subblocks by names (words)?
Content of classes: Exemplometablock, Exemploitemblock.