Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Generic solution to the 16 states per block problem


Tyron
 Share

Recommended Posts

For the last few weeks I have been on and off tyring to code a generic solution that allows me to register groups of blocks of any kind to overcomes the 16 metastates per-block limit. My first attempt was an enumeration that holds all the states, and my code would just register as many blocks as needed to hold all states. But Java Enum cannot be extended so this would be a massive copy&paste for each class of block.

 

My second attempt to overcome the enum limits was to simulate extensible enums via abstract classes. But here I ran into the next limit - you can't extend from, or define abstract static methods.

 

Before I redo it all again, has perhaps already someone solved this limitation in a generic way? Or is there perhaps a software pattern I could use here?

 

What I more or less want to get to is to be able to define a list of blocktypes and the code manages the registering of blocks and setting the metadata for each type, but with the simplicity of java enums, where I could do a call like EnumFlower.Peonia.getBlockState() or EnumFlower.getStateFromMeta(block, meta)

Link to comment
Share on other sites

I added a group of colored stone blocks

 

in my block class

public static BlockIndexed[] colorstone=new BlockIndexed[numstones];

 

int the init method

 

  for(int s=0;s<numstones;s++){
colorstone[s]=new BlockIndexed(Material.rock);
String ns=""+(s+1);
String tname="colorstone"+ns;
String name=tname+"_";
colorstone[s].setBlockName(name);
colorstone[s].setBlockTextureName(tname);
colorstone[s].setCreativeTab(LoonBlocksTabs.colorblock_tab);
colorstone[s].setHardness(2.5F);
colorstone[s].setResistance(15.F);
colorstone[s].setStepSound(Block.soundTypePiston);
GameRegistry.registerBlock(colorstone[s], ColorItem.class, name);

using this method I also added slabs, wall, and steps for each stone

 

 

hope this gives you a good idea

Link to comment
Share on other sites

Mmm, code tags...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.