Fireballs and Vectors?

Discussion in 'Plugin Development' started by SirMonkeyFood, Nov 19, 2015.

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

    SirMonkeyFood

    Hey, I'm making a simple plugin that shoots fireballs when you right click an item, and then removes the item. It all works just fine, but it seems that spawning more than 1 fireball in the same location causes them to collide with each other and explode before touching the ground. I'm pretty sure my only two choices are to create a delay between each time a fireball is spawned, or move the locations of where the fireballs spawn. I want it to be instantaneous so that the player can click and then turn without affecting the fireball launch trajectory, so I need to find a way to put the fireballs at different points along the vector(the player's sight line). Is there a simple way to do this, or would I be better off doing the delays? Also, is there any other way to prevent the fireballs from exploding before hitting the ground?

    (^If that doesn't make sense I'll try to clarify ^)

    Thanks for any help!

    Code:
    Code:
    @EventHandler
        public void onFlame(PlayerInteractEvent e) {
            Player charmander = e.getPlayer();
            if (charmander.getItemInHand().getType() == Material.BLAZE_POWDER) {
                if (charmander.getLocation().getY() <= 100) {
                    if (charmander
                            .getItemInHand()
                            .getItemMeta()
                            .getDisplayName()
                            .equalsIgnoreCase(
                                    "" + ChatColor.DARK_RED + "" + ChatColor.BOLD
                                            + "Charmander!")) {
                        ItemStack blazepowder = new ItemStack(
                                Material.BLAZE_POWDER, 1);
                        {
                            ItemMeta bpmeta = blazepowder.getItemMeta();
                            bpmeta.setDisplayName(ChatColor.DARK_RED + ""
                                    + ChatColor.BOLD + "Charmander!");
                            blazepowder.setItemMeta(bpmeta);
                        }
                        charmander.getInventory().removeItem(blazepowder);
                        Random Randiesp = new Random();
                        int Randomstrikesp = Randiesp.nextInt(10);
                        Randomstrikesp++;
                        Randomstrikesp = Randomstrikesp - 5;
                        Random Randiesp1 = new Random();
                        int Randomstrikesp1 = Randiesp1.nextInt(10);
                        Randomstrikesp1++;
                        Randomstrikesp1 = Randomstrikesp1 - 5;
                        Random Randiesp2 = new Random();
                        int Randomstrikesp2 = Randiesp2.nextInt(10);
                        Randomstrikesp2++;
                        Randomstrikesp2 = Randomstrikesp2 - 5;
                        Random Randiesp3 = new Random();
                        int Randomstrikesp3 = Randiesp3.nextInt(10);
                        Randomstrikesp3++;
                        Randomstrikesp3 = Randomstrikesp3 - 5;
                        Random Randiesp4 = new Random();
                        int Randomstrikesp4 = Randiesp4.nextInt(10);
                        Randomstrikesp4++;
                        Randomstrikesp4 = Randomstrikesp4 - 5;
    
                        Random Randiesy = new Random();
                        int Randomstrikesy = Randiesy.nextInt(10);
                        Randomstrikesy++;
                        Randomstrikesy = Randomstrikesy - 5;
                        Random Randiesy1 = new Random();
                        int Randomstrikesy1 = Randiesy1.nextInt(10);
                        Randomstrikesy1++;
                        Randomstrikesy1 = Randomstrikesy1 - 5;
                        Random Randiesy2 = new Random();
                        int Randomstrikesy2 = Randiesy2.nextInt(10);
                        Randomstrikesy2++;
                        Randomstrikesy2 = Randomstrikesy2 - 5;
                        Random Randiesy3 = new Random();
                        int Randomstrikesy3 = Randiesy3.nextInt(10);
                        Randomstrikesy3++;
                        Randomstrikesy3 = Randomstrikesy3 - 5;
                        Random Randiesy4 = new Random();
                        int Randomstrikesy4 = Randiesy4.nextInt(10);
                        Randomstrikesy4++;
                        Randomstrikesy4 = Randomstrikesy4 - 5;
    
                        Location loc = charmander
                                .getEyeLocation()
                                .toVector()
                                .add(charmander.getLocation().getDirection()
                                        .multiply(2))
                                .toLocation(
                                        charmander.getWorld(),
                                        charmander.getLocation().getYaw()
                                                + Randomstrikesy,
                                        charmander.getLocation().getPitch()
                                                + Randomstrikesp);
                        Fireball fireball = charmander.getWorld().spawn(loc,
                                Fireball.class);
                        Location loc1 = charmander
                                .getEyeLocation()
                                .toVector()
                                .add(charmander.getLocation().getDirection()
                                        .multiply(2))
                                .toLocation(
                                        charmander.getWorld(),
                                        charmander.getLocation().getYaw()
                                                + Randomstrikesy1,
                                        charmander.getLocation().getPitch()
                                                + Randomstrikesp1);
                        Fireball fireball1 = charmander.getWorld().spawn(loc1,
                                Fireball.class);
                        Location loc2 = charmander
                                .getEyeLocation()
                                .toVector()
                                .add(charmander.getLocation().getDirection()
                                        .multiply(2))
                                .toLocation(
                                        charmander.getWorld(),
                                        charmander.getLocation().getYaw()
                                                + Randomstrikesy2,
                                        charmander.getLocation().getPitch()
                                                + Randomstrikesp2);
                        Fireball fireball2 = charmander.getWorld().spawn(loc2,
                                Fireball.class);
                        Location loc3 = charmander
                                .getEyeLocation()
                                .toVector()
                                .add(charmander.getLocation().getDirection()
                                        .multiply(2))
                                .toLocation(
                                        charmander.getWorld(),
                                        charmander.getLocation().getYaw()
                                                + Randomstrikesy3,
                                        charmander.getLocation().getPitch()
                                                + Randomstrikesp3);
                        Fireball fireball3 = charmander.getWorld().spawn(loc3,
                                Fireball.class);
                        Location loc4 = charmander
                                .getEyeLocation()
                                .toVector()
                                .add(charmander.getLocation().getDirection()
                                        .multiply(2))
                                .toLocation(
                                        charmander.getWorld(),
                                        charmander.getLocation().getYaw()
                                                + Randomstrikesy4,
                                        charmander.getLocation().getPitch()
                                                + Randomstrikesp4);
                        Fireball fireball4 = charmander.getWorld().spawn(loc4,
                                Fireball.class);
    
     
  2. Offline

    Scimiguy

    Store the location prior to creating the runnable, then use that location in the runnable so the player's movement doesn't change it at the time
     
Thread Status:
Not open for further replies.

Share This Page