Fireball Projectile

Discussion in 'Plugin Development' started by GHOSTDJ, Dec 12, 2020.

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

    GHOSTDJ

    I am trying to make a sword with which if you right click on any block, a fireball will spawn 20 blocks on top of the right clicked block and will come downward till it hits the block. Ive figured out making the sword and spawning the fireball but I can get it to fall down

    Code:

    Code:
        @EventHandler
        public void onClick(PlayerInteractEvent event){
            if(event.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.GOLDEN_SWORD))
                if(event.getPlayer().getInventory().getItemInMainHand().getItemMeta().hasLore()){
                    Player player = (Player) event.getPlayer();
    
                    if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
                        Block block = event.getClickedBlock();
                        Location loc = block.getLocation().add(0,20,0);
                        World world = player.getWorld();
                        Entity meteor = loc.getWorld().spawn(loc, Fireball.class);
                        Vector vector = block.getLocation().toVector();
                        meteor.setVelocity(vector);
                    }
                }
        }
     
  2. Offline

    CraftCreeper6

    @GHOSTDJ
    Why use toVector()? Vectors specify a direction, converting the location to a vector is just nothing.

    If you just want it to move down then set it's y velocity to a negative value?
     
Thread Status:
Not open for further replies.

Share This Page