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

Hey everyone,

 

I looked into the Stairs and Furnace code to create a block that faces you when you place it, but it somehow doesn't work.

 

public class BlockCupboard extends BlockTutorial {

    public static final PropertyDirection FACING = PropertyDirection.create( "facing", EnumFacing.Plane.HORIZONTAL );

    public BlockCupboard(){
        super( new Material( MapColor.brownColor ) );
        this.setUnlocalizedName("cupboard");
        this.setDefaultState( this.blockState.getBaseState().withProperty( FACING, EnumFacing.NORTH ) );
    }

    public int getMetaFromState( IBlockState state ) {
        return 0;
    }

    protected BlockState createBlockState() {
        return new BlockState( this, new IProperty[] {FACING} );
    }

    public IBlockState onBlockPlaced( World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer )
    {
        return this.getDefaultState().withProperty( FACING, placer.getHorizontalFacing().getOpposite() );
    }
}

 

Do I need to set a Metavalue depending on the facing of the block? I didn't need it when I changed the texture of a different block depending what is adjacent to a block.

What is weird is that my blocks always face east, although the default facing is set to north, at least that is what F3 is telling me.

I alredy updated to 1.9 (some changes), but:

 

1. Use @Override - always! Saves you from trying to override wrong method.

Note: You can set Eclipse to add it for you. (Preferences)

 

2.

@Override
public int getMetaFromState(IBlockState state)
{
	return state.getValue(FACING).getIndex();
}

 

You need to actually return things.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Thanks Ernio,

 

yeah I should use override, I'm just testing things out, but that's a good habit.

 

I added that line and it works now, but I just don't understand why it's needed. I changed textures based on connected blocks without changing the metadata, but here it seems needed. Do you know why?

If you are changing texture based on anything that is not Metadata (Tile, surroundings, etc.) - you are not really using metadata of block. When you (internals) actually ask BlockState for metadata - this methods is called. It is supposed to parse any Properties into one of values from 0 to 15. You can even have 1000 properties, you just can't save them all into 16-valued metadata.

1.7.10 is no longer supported by forge, you are on your own.

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.