Solved How to create wood stairs (Material.WOOD_STAIRS) with a certain face direction?

Discussion in 'Plugin Development' started by dp118m, Nov 24, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    dp118m

    Hello!

    In my Bukkit plugin I want to create a wood step such that its direction is equal to south (see image below).

    [​IMG]

    I try to do it using this code:

    Code:
    protected void setBlockType(final int x,
        final int y,
        final int z,
        final Material material,
        final BlockFace face) {
        final Block block = getWorld().getBlockAt(
            x,
            y,
            z
        );
        block.setType(Material.WOOD_STAIRS);
    
        if (block.getType() != null) {
            final MaterialData bt =
                block.getType().getNewData(block.getData());
            if ((bt != null) && (bt instanceof Directional))
            {
                final Directional directional = (Directional) bt;
                directional.setFacingDirection(BlockFace.SOUTH);
                block.getState().update();
            }
        }
    }
    
    It doesn't work - the block is put into the world with direction "north".

    How can I specify the facing direction?

    Thanks

    Dmitri Pisarenko
     
  2. Offline

    mcdorli

    block data
    Code:
    Block block = new Block(Material.WOOD_STAIRS);
    block.setData(<Here comes a byte, tht represents the facing>);
    
    Try to do
    Code:
    /setblock ~ ~ ~ minecraft:oak_stairs <data>
    
    and try to increase the block data, then use the correct one
     
  3. Offline

    Xerox262

    To make it face north you need to set it's data:
    • 0 for west
    • 1 for east
    • 2 for north
    • 3 for south
    Those are based on the bottom of the stair, to make it point that direction. Upside down stairs have different values.

    For the upside down version just add 4 onto it, so:
    • 4 for west
    • 5 for east
    • 6 for north
    • 7 for south
     
    Last edited: Nov 24, 2015
  4. Offline

    teej107

    @mcdorli @Xerox262 The Directional interface is supposed to make it easy so you don't need to mess with the byte values.


    @dp118m
    Don't do that. You are just getting a new MaterialData (from the Material, not the Block) that is different from the Block's MaterialData.
    Get the BlockState from the Block to get its MaterialData. You can then cast the Stairs to either Stairs or the Directional.
    Also that is a bit redundant. Why wouldn't it be null if you just set it?
     
  5. Offline

    dp118m

Thread Status:
Not open for further replies.

Share This Page