Jump to content

[1.8.9] Facing of a block


ErnstLustig

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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.