Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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
        }
    }
}

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.

  • Author

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

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.

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.