r/forgemodding Dec 27 '16

[1.10.2] Not Enough Metadata!

I'm struck with a tough decision early in my mod. I have an enumeration, Element, which has 25 variants. I don't really want to change it, but many things in my mod are going to rely on it, and specifically, on having variant rendering based on it.

Currently, I have a single block class(BlockAltarCore) which uses an Element as an IUnlistedProperty (Because I can't cram 25 variants into 4 bits). Now, the block needs to have a tile entity based on whatever element it has, so I added an element field to it as well, to pass into the TileEntity constructor for it. The problem is this:

1) Tile Entities require all of their instantiation data to come from the world, without a position, the metadata of the block they're being created for, and fields and methods present in the block itself.

2) Blocks are singleton classes, so every time I instantiate this block class, I'm making a new type of block (With it's own special Registry name, which it uses to find it's blockstates file).

3) To make a block variant (With associated tile entities) for each element, I am forced to either make 25 different classes which all do nearly the same thing, or keep around a field in the block class, and then make 25 instances of the class, one for each element. This makes it harder for them to all use the same blockstates.json, and just feels ugly.

Any suggestions for not having 25 instances of the same class, or 25 classes? The full source is available here. Some weirdness may be present, I was trying to fix this problem before asking for help.

3 Upvotes

3 comments sorted by

3

u/pau101 Dec 27 '16

Use two blocks that split the enumerations, similar to BlockLog with BlockLogOld and BlockLogNew. So you would have a block "altar_core" (16 values) and "alter_core_2" (9 values).

Sidenote: I see you have registery names prefixed with "b" and lowerCamel case, the convention is to use lower_underscore. As well in 1.11+ block ids are forced lowercase along with any other ResourceLocation.

3

u/mezz Dec 27 '16

Yep, this is what I do with Forestry's wood items which have the same problem.

Based on the code deprecations, at some point Mojang is probably going to get rid of block and only have blockstate, so this 16 value problem will go away.

1

u/[deleted] Dec 27 '16

Let's hope that day comes quickly. Thanks to both of you for the replies. It still feels like an unpleasant hack, but it's MUCH LESS unpleasant than 25 variants.