Spawning Falling Blocks

Discussion in 'Plugin Development' started by Awesom_AA, Aug 22, 2020.

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

    Awesom_AA

    How can I spawn a flying cobblestone block when a player right clicks? I understand how to listen for PlayerInteract and then check if its a right-click, but I can't figure out how to create a cobble block specific. There are tutorials on how to make the block you mine specifically fly, but you can do event.getBlock() for those whereas I need the same block everytime. Something like Material.COBBLESTONE.getData() doesnt work for the parameters.
     
  2. Offline

    KarimAKL

    @Awesom_AA I'd imagine you should do something like this:
    Code:Java
    1. // The location to spawn it at
    2. Location location = ...;
    3.  
    4. // Spawn the falling block
    5. FallingBlock block = location.getWorld().spawnFallingBlock(location, Material.COBBLESTONE.createBlockData());
    6.  
    7. // Send it flying using velocity
    8. block.setVelocity(...);
     
  3. Offline

    Awesom_AA

    Cool, the createBlockData was the method I was looking for

    Edit: Sike, cant get it to work maybe because im using spigot 1.12? If I use Material.COBBLESTONE the method doesnt exist.
    I also tried creating a material m and then creating data from that material but that doesnt seem to work either
     
    Last edited: Aug 23, 2020
  4. Offline

    KarimAKL

    @Awesom_AA Oh, BlockData doesn't yet exist in that version. I think you can use this instead:
    Code:Java
    1. // The location to spawn it at
    2. Location location = ...;
    3.  
    4. // Spawn the falling block
    5. FallingBlock block = location.getWorld().spawnFallingBlock(location, new MaterialData(Material.COBBLESTONE));
    6.  
    7. // Send it flying using velocity
    8. block.setVelocity(...);
     
Thread Status:
Not open for further replies.

Share This Page