Get/Set orientation of blocks (Stairs,Logs ...)

Discussion in 'Plugin Development' started by Sandr0RM46, Jul 23, 2021.

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

    Sandr0RM46

    Hello everyone , i'm making my first thread since i can't find an updated working solution .
    As of now i've scaled down to work directly on this problem and i'm simply trying to place stairs that automatically face NORTH for example :

    (...)
    import org.bukkit.material.Stairs; //There is another "Stairs" on org.bukkit.block.data.type

    public void blocktestlistener(BlockPlaceEvent event) {
    Block block = event.getBlock();
    BlockState blockState = block.getState();
    if (blockState.getData() instanceof Stairs){
    Stairs data = (Stairs) blockState.getData();
    data.setFacingDirection(BlockFace.NORTH);
    }
    }

    With this code it enters the if statement when i place most stairs (for example Diorite , Exposed , Oxidized stairs and much more don't work, only wood, stone, cobblestone stairs) but apart from that the main problem is that the facing direction doesn't even change at all .

    Originally i needed to copy a region of blocks and save each block specification on a .txt file with some custom format like :
    x,y,z,DIRECTION,TYPE
    or something like that and when the user wants he can load that information from .txt and paste those blocks on the world
    So my doubts are :

    -How can i get the direction of which a block is facing (North , South , West or East)
    -How can i create a block with a certain direction (example , i want an oak log facing NORTH at X=0,Y=0,Z=0 )

    Any suggestion will be deeply appreciated[/LEFT]
     
  2. Offline

    Tim_M

    I think you might have to
    Code:
    block.getState().update(true);
    
    EDIT:
    or maybe
    Code:
    blockState.update(false, false);
    
     
  3. Offline

    Sandr0RM46

    @Tim_M Thank you ! With some modifications it started working! I'll check if my original idea is "accomplishable" now that i am starting to understand a little bit more
     
  4. Offline

    Tim_M

    Alright, that's nice to hear. If you fixed it you should probably post your working code (for other people) and mark the thread as solved!
     
Thread Status:
Not open for further replies.

Share This Page