Would I Use getVelocity() For This Situation?

Discussion in 'Plugin Development' started by mkezar, Apr 26, 2014.

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

    mkezar

    Hi. I am making a plugin like codename_Bs boulder toss ability in arena. I am having trouble figuring out how to make a block fly through the air. I was doing some research and was wondering Would i use
    Code:java
    1. BlockDispenceEvent.getVelocity()
    Code:java
    1. BlockDispenceEvent.setVelocity(Vector vel)
    and
    Code:java
    1. BlockDispenceEvent(Block block, ItemStack dispensed, Vector velocity)
    I think these are the things i need to launch a block in the air but not sure :/ Any ideas?
     
  2. Offline

    killerman747

    mkezar
    Im pretty sure for blocks to fly through the air, it needs to either be sand or gravel. Recently thou mojang added the falling sand entities, which is most likely how these are being done. You would need to get the block that you want to fly, turn it into a sand entity and then launch it some how. You might be able to use the velocity after you create the entity.
     
  3. Offline

    mrgreen33gamer

    Ill fetch a code for you,
     
  4. Offline

    xTigerRebornx

    mkezar You'd need to spawn a falling block, set its type to the block you want, and set its velocity. You'd also need to listen to some events involving falling blocks, like when they hit the ground, and other things.
     
  5. Offline

    mrgreen33gamer

    Here yeah go:

    Code:java
    1.  
    2. @EventHandler
    3. public void onSpawnFallingBlock(PlayerInteractEvent event){
    4. Player p = event.getPlayer();
    5.  
    6. if(event.getAction() == Action.RIGHT_CLICK_AIR){
    7. if(event.getItem().getType() == Material.STICK){
    8. Location loc = p.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
    9. FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, Material.DIAMOND_BLOCK, (byte)0);
    10.  
    11. }
    12. }
    13.  
    14. }
    15.  
     
  6. Offline

    mkezar

    mrgreen33gamer so would i just paste this into my class? or do i need to import some stuff :p

    mrgreen33gamer ok so i added these imports
    Code:java
    1. import org.bukkit.block.BlockFace;
    2. import org.bukkit.entity.FallingBlock;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.player.PlayerInteractEvent;

    ik there is more but they have more than 2 to choose from and i dont want to import the wrong thing :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  7. Offline

    Slikey

    mkezar You cannot import the wrong class. If you import the wrong class you'll get an error for not fitting the right object-type. then just choose the other class to import.
    I think you will do fine if you alsoways import org.bukkit.XYZ.. other classes are often from apache, google or java.. which you don't need in most of the cases.
     
  8. Offline

    mkezar

    mrgreen33gamer Ok lol :p heres my code. some stuff got deprecated and is not working :( it does not show up in the /plugins heres the code finished
    Code:java
    1. package me.mkezar.VariousProjects;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.BlockFace;
    6. import org.bukkit.entity.FallingBlock;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11.  
    12. public class BoulderToss {
    13.  
    14. @EventHandler
    15. public void onSpawnFallingBlock(PlayerInteractEvent event){
    16. Player p = event.getPlayer();
    17.  
    18. if(event.getAction() == Action.RIGHT_CLICK_AIR){
    19. if(event.getItem().getType() == Material.STICK){
    20. Location loc = p.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
    21. FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, Material.DIAMOND_BLOCK, (byte)0);
    22.  
    23. }
    24. }
    25.  
    26. }
    27.  
    28. }
    29.  
     
  9. Offline

    mrgreen33gamer

    Here:

    Code:java
    1. package me.mkezar.VariousProjects;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.BlockFace;
    6. import org.bukkit.entity.FallingBlock;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11.  
    12. public class BoulderToss implements Listener{
    13.  
    14. @EventHandler
    15. public void onSpawnFallingBlock(PlayerInteractEvent event){
    16. Player p = event.getPlayer();
    17.  
    18. if(event.getAction() == Action.RIGHT_CLICK_AIR){
    19. if(event.getItem().getType() == Material.STICK){
    20. Location loc = p.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
    21. FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, Material.DIAMOND_BLOCK, (byte)0);
    22.  
    23. }
    24. }
    25.  
    26. }
    27.  
    28. }
     
  10. Offline

    mkezar

    mrgreen33gamer what do i import for Listener? it gives me the red squiggely line underneath it. do i import
    Code:java
    1. import org.bukkit.event;
     
  11. Offline

    mrgreen33gamer

    Just import the Listener, and make sure you put this in your onEnable in your Main Class:

    Code:java
    1.  
    2. this.getServer().getPluginManager().registerEvents(new BoulderToss(this), this);
    3.  
    4. new BoulderToss(this);
    5.  


    And here is your class again:

    Code:java
    1. package me.mkezar.VariousProjects;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.BlockFace;
    6. import org.bukkit.entity.FallingBlock;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.block.Action;
    10. import org.bukkit.event.player.PlayerInteractEvent;
    11.  
    12. public class BoulderToss implements Listener{
    13.  
    14. YourMainClass main;
    15. public BoulderToss(YourMainClass instance){
    16. main = instance;
    17. }
    18.  
    19. @EventHandler
    20. public void onSpawnFallingBlock(PlayerInteractEvent event){
    21. Player p = event.getPlayer();
    22.  
    23. if(event.getAction() == Action.RIGHT_CLICK_AIR){
    24. if(event.getItem().getType() == Material.STICK){
    25. Location loc = p.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
    26. FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, Material.DIAMOND_BLOCK, (byte)0);
    27.  
    28. }
    29. }
    30.  
    31. }
    32.  
    33. }
    34.  
     
  12. Offline

    mkezar

    I get this huge error when loading. It says it cant find the main class bandicam 2014-04-26 12-26-20-544.jpg

    bandicam 2014-04-26 12-26-12-643.jpg

    View attachment 19268

    mrgreen33gamer about the post above :p heres what my plugin

    looks like View attachment 19269

    This is BoulderToss.java
    Code:java
    1. package plugins.mkezar;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5.  
    6. public class BoulderToss extends JavaPlugin {
    7. @Override
    8. public void onEnable() {
    9. this.getServer().getPluginManager().registerEvents(new BoulderTossListener(), this);
    10. }
    11.  
    12. }
    13.  


    and this is BoulderTossListener
    Code:java
    1. package plugins.mkezar;
    2.  
    3. import org.bukkit.Location;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.BlockFace;
    6. import org.bukkit.entity.FallingBlock;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12.  
    13. public class BoulderTossListener implements Listener {
    14.  
    15. @EventHandler
    16. public void onSpawnFallingBlock(PlayerInteractEvent event) {
    17. Player p = event.getPlayer();
    18.  
    19. if(event.getAction() == Action.RIGHT_CLICK_AIR) {
    20. if(event.getItem().getType() == Material.STICK) {
    21. Location loc = p.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
    22. FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, Material.DIAMOND_BLOCK, (byte)0);
    23. }
    24. }
    25. }
    26. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  13. Offline

    mrgreen33gamer



    PM me your whole code please. And you plugin.yml
     
  14. Offline

    mkezar

    mrgreen33gamer yes sir :)

    mrgreen33gamer ok i pmed u

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  15. Offline

    killerman747

    You need an onEnabled() method to register the events
     
  16. Offline

    mkezar

    Ok. I got this working!!! But. 1 thing. It drops the block on me. I want it so it gets my line of sight and instead of dropping, its a projectile. Any ideas? here is what i have for it making a block spawn above my head.
    Code:java
    1. Location loc = p.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
    2. FallingBlock entity = loc.getWorld().spawnFallingBlock(loc, Material.STONE, (byte)0);

    so i want it to throw the block where im looking, not dropping in on my head.
    Thank you!!!
     
  17. Offline

    killerman747

    mkezar
    Get the yaw and pitch and send the block going in that direction.
     
  18. Offline

    mkezar

    killerman747 i dont know how to lol :p heres a video of a server who was exactly what i want :p sorry for bad quality but dont forget to leave a like :p i need publicity lololol :p

    bump

    killerman747 so how do i do the yaw and pitch?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  19. Offline

    mkezar

    7 months later.. lol :p
     
Thread Status:
Not open for further replies.

Share This Page