Launch Exploding Firework without Launch Sound. The Quest for Answers

Discussion in 'Plugin Development' started by NerdsWBNerds, May 18, 2014.

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

    NerdsWBNerds

    Alright everyone, in this thread, we are going to finally find the answer to the ultimate Bukkit question.

    How do I spawn an exploding firework, without a launch sound, and make it work 100% of the time?

    Currently, all of the options I have found on the forums have yielded results that either work only about 50% of the time (other 50% firework just spawns and is destroyed), or have the launching sound, which we don't want.

    Here are some of the current methods, and the results they yield

    Works: 80-90% of the time
    No launching sound.
    Code:java
    1.  
    2.  
    3. try {
    4. // Bukkity load (CraftFirework)
    5. World world = loc.getWorld();
    6. final Firework fw = (Firework) world.spawn(loc, Firework.class);
    7. // the net.minecraft.server.World
    8. Object nms_world = null;
    9. Object nms_firework = null;
    10. /*
    11.   * The reflection part, this gives us access to funky ways of messing around with things
    12.   */
    13. if (world_getHandle == null) {
    14. // get the methods of the craftbukkit objects
    15. world_getHandle = getMethod(world.getClass(), "getHandle");
    16. firework_getHandle = getMethod(fw.getClass(), "getHandle");
    17. }
    18. // invoke with no arguments
    19. nms_world = world_getHandle.invoke(world, (Object[]) null);
    20. nms_firework = firework_getHandle.invoke(fw, (Object[]) null);
    21. // null checks are fast, so having this seperate is ok
    22. if (nms_world_broadcastEntityEffect == null) {
    23. // get the method of the nms_world
    24. nms_world_broadcastEntityEffect = getMethod(nms_world.getClass(), "broadcastEntityEffect");
    25. }
    26. /*
    27.   * Now we mess with the metadata, allowing nice clean spawning of a pretty firework (look, pretty lights!)
    28.   */
    29. // metadata load
    30. FireworkMeta data = (FireworkMeta) fw.getFireworkMeta();
    31. // clear existing
    32. data.clearEffects();
    33. // power of one
    34. data.setPower(1);
    35. // add the effect
    36. data.addEffect(fe);
    37. // set the meta
    38. fw.setFireworkMeta(data);
    39. /*
    40.   * Finally, we broadcast the entity effect then kill our fireworks object
    41.   */
    42. // invoke with arguments
    43. nms_world_broadcastEntityEffect.invoke(nms_world, new Object[]{nms_firework, (byte) 17});
    44. fw.detonate();
    45. fw.remove();
    46. } catch (Exception e) {
    47. e.printStackTrace();
    48. }
     
  2. Offline

    Quantum64

    NerdsWBNerds
    With the solution above tiny amounts of lag (more than a few players) drastically reduces the percentage of it working. There was a time when that class woken nearly 100% D:
     
  3. Offline

    NerdsWBNerds


    There has got to be some way to do this and have it work 100% of the time
     
  4. Offline

    TheMintyMate

    NerdsWBNerds
    Quantum64
    This quest for the answer is similar to a question I asked several months ago. I received advise to use packets to allow clients to visually see lightning, but without playing the lightning sound. You may need to do something similar here.
    Links:
    http://forums.bukkit.org/threads/sound-manipulation-of-lightning.251081/
    http://forums.bukkit.org/threads/using-packets-for-lightning-to-avoid-lightning-sound.251383/
    Basically, I needed to change the class of lightning and override the sound being played.

    Word of warning: Packets aren't easy to manage, and often need to be changed for EVERY bukkit update.

    Hope this helped,
    - Minty
     
  5. Offline

    TryB4

Thread Status:
Not open for further replies.

Share This Page