Jump to content

[1.10.2] Block Metadata Value Limit [Solved]


pfgforge

Recommended Posts

I have a custom block which has a facing direction and a type. A facing direction already uses up most of the metadata that a block can store, and I need to have at least more than 8 variants of a block along with its facing direction. How can I render by both its facing direction and its type without passing the metadata limit, or get more metadata I can have on my block?

 

This block does have a tileentity associated with it, so if there is any way to move the block rotation rendering into the tileentity, that would work fine

 

    public static final PropertyDirection FACING = PropertyDirection.create("facing");
    public static final PropertyInteger TYPE = PropertyInteger.create("type", 0, 31);

    @Override
    public int getMetaFromState(IBlockState state) {
        int i = 0;
        i = i | ((EnumFacing)state.getValue(FACING)).getIndex();

        {
            i |= 8;
        }
        
        i = i | ((Integer)state.getValue(TYPE)) << 3;

        return i;
    }

 

java.lang.ArrayIndexOutOfBoundsException: 24

 

{
    "forge_marker": 1,
    "defaults": {
        "some defaults...": 0
    },
    "variants": {
        "facing": {
            "north": {
                "y":0
            },
            "south": {
                "y":180
            },
            "west": {
                "y":270
            },
            "east": {
                "y":90
            },
            "up": {
                "x":270
            },
            "down": {
                "x":90
            }
        },
        "type": {
            0: {
                "nothing changed here"
            },
            1: {
                "some submodels..."
            },
            2: {
                "some more submodels..."
            },
            3: {
                "even more submodels..."
            },
            4: {
                "lots of submodels..."
            }
            "I need more submodels than this": 0
        }
    }
}

Link to comment
Share on other sites

Metadata is limited to 16 values, so a property with 6 values limits you to one other property with 2 values (2 * 6 = 12, 3 * 6 = 18).

 

If you require additional values, you need to store them in a

TileEntity

. If you want to use them to determine the model, override

Block#getActualState

to set the property from the value stored in the

TileEntity

.

 

You can see an example of this here:

Block

,

TileEntity

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Metadata is limited to 16 values, so a property with 6 values limits you to one other property with 2 values (2 * 6 = 12, 3 * 6 = 18).

 

If you require additional values, you need to store them in a

TileEntity

. If you want to use them to determine the model, override

Block#getActualState

to set the property from the value stored in the

TileEntity

.

 

You can see an example of this here:

Block

,

TileEntity

.

 

The blocks I need this for are already tileentitites

 

How can I then render them facing their direction with submodels for the different types?

 

Or does the getActualState allow more than the 15 bits

 

Edit: I'm stupid

Link to comment
Share on other sites

Also, don't create your own PropertyDirection, use the one from BlockDirectional

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

Also, don't create your own PropertyDirection, use the one from BlockDirectional

And make a conscious decision on whether you want to use UP and DOWN (like a piston) or  only N, S, E & W (like a furnace). If the latter, use BlockHorizontal.

 

Actual state receives a state (probably made from a metadata value 0-15) and returns another block state, not and integer, so it is not limited. You just need to set each property within the range for that property. The method may reach out to the world (neighbor blocks, tile entities etc) to get data for deciding the actual state.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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