1.16.x Is it possible to create An object made up of two block in a world?I want to create a door

Discussion in 'Spigot Plugin Development' started by admin_tian, Oct 18, 2020.

  1. Is it possible to create An object made up of two block in a world, like door\iron_door?


    I wrote the code to create the door and ran it. However, as a result, the newly created blocks is destroyed in an instant.


    [My code]:
    Code (Java):
    Block b= p.getLocation().getBlock();
                b.setType(Material.ACACIA_DOOR);
                Door door= (Door) this.getServer().createBlockData(Material.ACACIA_DOOR);
                door.setHalf(Half.BOTTOM);
                door.setFacing(BlockFace.NORTH);
                door.setHinge(Hinge.LEFT);
                door.setOpen(true);
                door.setPowered(false);
                b.getState().setBlockData(door);
               
               
                Block bTop= b.getRelative(0, 1, 0);
                bTop.setType(Material.ACACIA_DOOR);
                Door door1= (Door) this.getServer().createBlockData(Material.ACACIA_DOOR);
                door1.setHalf(Half.TOP);
                door1.setFacing(BlockFace.NORTH);
                door1.setHinge(Hinge.LEFT);
                door1.setOpen(true);
                door1.setPowered(false);
                bTop.getState().setBlockData(door1);

    ___________________________________

    It seems that the two blocks that make up a door are not considered to be one by the system.

    How can I successfully create a door?
    Please, I'm a new developer here.I need some help. Thank you.

    A similar example that can be created is tall grass. It also needs help to create.
     
  2. 1. You can call Block#setBlockData(BlockData) directly on the block which is preferred since changes to the state are not backed by the block itself
    2. That method accepts a boolean (applyPhysics) which you should set to false, so that is what causes the block to disappear in an instant.