Solved How do you use Block.setBlockData(...)?

Discussion in 'Spigot Plugin Development' started by Pangamma, Jul 27, 2018.

  1. I'm running into a bunch of cases where I need an instance of BlockData, but I have no idea how to create an instance of it. I'm trying to figure out how to actually change a block type + add any relevant settings for that block type as well. And I want to do it in an efficient way so that if I ever wanted to do a custom world generator it would be efficient enough to work for that. Can we put together a guide for using BlockData? I was searching and could not find anything about it.

    http://prntscr.com/kbkqt7


    p.sendBlockChange(location, BLOCKDATA);
    b.setBlockData(BLOCKDATA);
     
  2. BlockData blockData = Material.OAK_STAIRS.createBlockData();
    If you need to set BlockData data values, cast blockData to the appropriate class and then use the associated methods:
    Stairs stairs = (Stairs) blockData;
    stairs.setFacing(BlockFace.EAST);
    b.setBlockData(stairs);
     
    #2 eccentric, Jul 27, 2018
    Last edited: Jul 27, 2018
    • Like Like x 1
    • Agree Agree x 1
  3. Love youuuuu. Thanks a million man.