Shooting firework at eye location

Discussion in 'Plugin Development' started by micrlink, Apr 20, 2013.

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

    micrlink

    How would I make it so when someone right clicks with a stick it shoots a firework at their eye location?????
     
  2. Offline

    Tzeentchful

    I'm assuming you want to shoot the firework in the direction that the player looking.
    basically you want to get the location of their eyes, grab the normalized vector they are looking, spawn a firework and set it's velocity with the vector you just got.
    Here is an example i did with a fireball. it also shifts the vector in front of them a bit so it won't explode in their head.
    Code:java
    1.  
    2. public void shootFireball(Double speed, Location shootLocation) {
    3. Vector directionVector = shootLocation.getDirection().normalize();
    4. double startShift = 2;
    5. Vector shootShiftVector = new Vector(directionVector.getX() * startShift, directionVector.getY() * startShift, directionVector.getZ() * startShift);
    6. shootLocation = shootLocation.add(shootShiftVector.getX(), shootShiftVector.getY(), shootShiftVector.getZ());
    7.  
    8. Fireball fireballl = shootLocation.getWorld().spawn(shootLocation, Fireball.class);
    9. fireballl.setVelocity(directionVector.multiply(speed));
    10.  
    11. if(fireballl instanceof Fireball){
    12. ((Fireball) fireballl).setIsIncendiary(false);// Remove fire
    13. ((Fireball) fireballl).setShooter(this.player.getPlayer());
    14. }
    15. }
    16.  
     
  3. Offline

    chasechocolate

    FireworkEffectPlayer :)
     
    microgeek and Stigosaurus like this.
  4. Offline

    micrlink

    I tried using this with replacing fireball with firework but it did not work

    Bump

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

    chasechocolate

    micrlink why launch a fireball? But the way I would do it would be to use FireworkEffectPlayer and play a firework at the player.getTargetBlock(null, <MAX DISTANCE>).getLocation().
     
  6. Offline

    micrlink

    But wouldn't that shoot a firework from the place that a player is looking at, I want it to shoot at, as in from the player to the block, not from the block to the sky. Kinda like an arrow from a bow but without a bow.
     
  7. Offline

    chasechocolate

    It wouldn't if you use FireworkEffectPlayer. FireworkEffectPlayer simply displays the firework blast.
     
  8. Offline

    devilquak

    micrlink

    Just thought I'd warn you, fireworks are really iffy if you launch them at angles. Vanilla Minecraft methods don't permit this, as no matter what, a placed firework item always flies up, but if you use any other method to launch one and do it not at an upward angle, 9 times out of 10 it will go crazy. I tried to make a flare gun plugin back in the day, and I had a nightmarish time trying to get a rocket to shoot straight and still fly at a slow speed.

    If you're a physics and math genius, you might be able to make your own Firework entity and customize its gravitational/dark magic properties there, but otherwise, you might run into a few problems.
     
    re4ly likes this.
  9. Offline

    chasechocolate

    RingOfStorms did it quite nicely :) http://forums.bukkit.org/threads/inverse-request-rocket-launcher.119803/
     
    devilquak likes this.
  10. Offline

    RingOfStorms

    I did do it but I actually wouldn't recommending using a firework. To keep it on its path you have to send a repeating task that sets it velocity every tick (or longer lengths for less smooth flight). That could get pretty server intensive if you have several players shooting the rockets. At this point I can think of two alternatives:
    1. Don't use the rocket, and instead just use particles in a line then use the effect at the location (Ever played QuakeCraft on hypixels' server - he does this here).
    2. Create a Rocket entity yourself that extends the existing Firework nms class. You would overwrite the movement function and make it so that the firework doesn't have the up motion, and instead can be fired in a line from one velocity setting.
    Personally I would do the ladder (choice #2) as that would be still using the rocket, and with that you could even do things with gravity settings, create your own custom attributes, and it would be easier to make different types of rockets that can fire in parabolic flight patterns. But at the same time, players are going to be happy with even the particles in the line - so if you're not advanced enough you can do choice 1.
     
  11. Offline

    Regenwurm97

    I've been searching for a similar thread now for quite a while but cant find what I need :l
    The thing is, I want to create a Firework Explosion Effekt (so like a green ball of particles) at a location where an egg hits...
    Currently, I'm only able to spawn a rocket at the hitten block that will then fly up in the air and explode. But I want the firework to explode directly. Does anyone of you guys know how to play a Firework Effect manually or just cancel any event that triggers when a rocket wants to fly? ^^

    See this:
    Code:
    @EventHandler
        private void onEggThrow(ProjectileHitEvent e) {
           
            Player eventp = (Player) e.getEntity().getShooter();
            Location eventl = e.getEntity().getLocation();
           
            if(e.getEntity().getType() == EntityType.EGG) {
               
                eventp.sendMessage("Egg!");     
         
                    Firework fw = eventp.getWorld().spawn(eventl, Firework.class);
                    FireworkMeta data = fw.getFireworkMeta();
                    data.addEffects(FireworkEffect.builder().withColor(Color.BLACK).with(Type.BALL_LARGE).build());
                    data.setPower(3);
                    firework.setFireworkMeta(data);
                   
                    eventp.sendMessage("Firework Fine!");
               
            }
           
           
        }
     
  12. Offline

    micrlink

    How would I do choice 1?????
     
  13. Offline

    chasechocolate

  14. Offline

    TheJerryGoes

    @RingOfStorms Hey dude, i saw your plugin, and it's looking amazing! when it will be released? it would be awesome to asign it to a hoe, or a stick! also a way to getting them with signs would be legit!

    If you release this, this could be the first QuakeCraft plugin for public!
     
  15. Offline

    adamtherealone

    So is there any way to make something in vanilla minecraft where say the player is given a hoe, and the look at a person and right click, this then makes particles travel to that person or object and explode?
     
  16. Offline

    RingOfStorms

    Great necro post.
     
  17. Offline

    chasechocolate

    Yes. Have you tried searching?
     
Thread Status:
Not open for further replies.

Share This Page