Solved setblock door facing towards a blockface

Discussion in 'Spigot Plugin Development' started by craterhater, May 29, 2017.

  1. Hey there,

    How would I setblock a door with a certain direction?

    Thanks!
     
    • Useful Useful x 1
  2. Thank you!

    Here is the final code for anyone that needs it:
    Code (Text):
    Location loc = event.getBlock().getLocation();
                       
                        BlockState state = loc.getBlock().getState();
                        MaterialData data =state.getData();
                        Door d = (Door) data;

                        d.setFacingDirection(d.getFacing().getOppositeFace());
                        state.update();
     
  3. You'd have to check if the block's data (Block#getState().getData()) is instanceof Door.

    Code (Text):
    // The block
    Block b = Bukkit.getWorld("world").getBlockAt(0, 0, 0);

    // Making sure the block is a door
      if (b.getState().getData() instanceof Door) {
        // Casting
        Door door = (Door) b.getState().getData();

        // Setting facing direction
        door.setFacingDirection(BlockFace.NORTH);

        // Calling update on its state because we changed it
        b.getState().update();
    }
    EDIT:
    Oops, didn't see the replies above.
     
    • Friendly Friendly x 1