1.14.4 Creating a custom piston push

Discussion in 'Spigot Plugin Development' started by Forty, Feb 26, 2020.

  1. Hi!
    I am trying to achieve the movement of blocks as if they were pushed or pulled by a Piston, without there actually being a piston block.
    The block has to go into a moving state and move to an adjacent block. I am specifically looking to achieve that smooth block move animation.
    I'd like to do this with as few visible piston parts as possible. For example, if it can be done with just a piston head that briefly appears during the animation, that would be fine.

    For a scenario this could be used in, imagine right-clicking a block face and the block is pushed in the direction of the opposing block face. (I do not need help with that part, just the push animation.) Here is the example code.
    Code (Java):
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent event) {

        // Check if the player right clicked a block.
        if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
            Block block = event.getClickedBlock();

            // Check if the player clicked an actual block.
            if (block != null) {
                BlockFace blockFace = event.getBlockFace();
                Block destinationBlock = block.getRelative(blockFace.getOppositeFace());

                // Move the block to the destination block with a piston animation.

            }
        }
    }