How do i summon a firework without the rocket part

Discussion in 'Plugin Development' started by 360_, Oct 9, 2017.

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

    360_

    How would i edit this code so a firework just summons and i doesn't do the rocket part
    Code:
    int power = (int)(Math.random()*0)+0;
                   Firework fw = (Firework) player.getWorld().spawnEntity(new Location(player.getWorld(), 771, 26, -420), EntityType.FIREWORK);
                FireworkMeta fireworkmeta = fw.getFireworkMeta();
                List<Color> c = new ArrayList<Color>();
                c.add(Color.WHITE);
                c.add(Color.RED);
                FireworkEffect e = FireworkEffect.builder().withColor(c).withFade(c).with(Type.BURST).trail(true).build(); // Edit firework
                fireworkmeta.addEffect(e);
                fw.detonate();
                fireworkmeta.setPower(power);
                fw.setFireworkMeta(fireworkmeta); // Set firework's data
     
  2. Offline

    MightyOne

    Firework#detonate() will let the it i stantly explode. If you call it right away no fire work rocket will be visible. Enough?
     
  3. Offline

    360_

    that's already in the code
     
  4. Offline

    Zombie_Striker

    @360_
    I believe you are saying you want the particle effects without the firework entity, correct? If so, you will need to make it invisible. You can do this by either calling setInvisible method or giving it the invisibility potion effect.
     
  5. Offline

    360_

    Im just trying to make it so the firework pops and not have it so it goes up in the air more for a bit and the pops
     
  6. Offline

    Side8StarLite

    @360_
    Think you can handle reflection? instant-firework.jpg
    The giant try/catch block is what does the job. If you prefer the version without reflection, this is it:
    Code:
    ((CraftFirework)firework).getHandle().expectedLifespan = 1;
    Note that the above version will only work on the version you build the plugin with. So I'd suggest using the one with reflection.
    Here is the link to the original video.
     
    Zombie_Striker likes this.
  7. Offline

    360_

    Im currently trying to use the "((CraftFirework)firework).getHandle().expectedLifespan = 1;" code and trying to do it myself but if i have issues ill come back here

    Im not sure if i did it right
    Code:
    int power = (int)(Math.random()*1)+0;
                 Firework fw = (Firework) player.getWorld().spawnEntity(new Location(player.getWorld(), 748, 47, -289), EntityType.FIREWORK);
                 FireworkMeta fireworkmeta = fw.getFireworkMeta();
                 List<Color> c = new ArrayList<Color>();
                 c.add(Color.WHITE);
                 c.add(Color.BLACK);
                 FireworkEffect e = FireworkEffect.builder().withColor(c).withFade(c).with(Type.BALL).trail(true).build(); // Edit firework
                 fireworkmeta.addEffect(e);
                 fw.detonate();
                 fireworkmeta.setPower(power);
                 fw.setFireworkMeta(fireworkmeta); // Set firework's data
                 ((CraftFirework)firework).getHandle().expectedLifespan = 1;
     
    Last edited by a moderator: Oct 10, 2017
  8. Offline

    Side8StarLite

    @360_
    Yeah just like that.
     
  9. Offline

    360_

  10. Offline

    Side8StarLite

    @360_
    You must replace "firework" with "fw", since that's what you named your firework to be - sorry for the confusion
     
  11. Offline

    360_

  12. Offline

    Side8StarLite

    @360_
    Did you import all the correct files? What does it say when you hover over the error?
    Edit: I realize it might not show the error if you hover over it. Just press Ctrl + Shift + O, and that should fix the problem (shortcut for organizing imports)
     
    Last edited: Oct 13, 2017
Thread Status:
Not open for further replies.

Share This Page