Solved Firework not showing Particles

Discussion in 'Plugin Development' started by Grauly, Oct 4, 2018.

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

    Grauly

    So i tried using fireworks as a source of damage for my plugin, I stumbled across the following problem:
    The firework i spawned (code below) spawns correctly, deals the damage its ment to do, but dose not display any Particles or plays the sound of the explosion. So i hear the rocket getting launched, i can kill mobs with it but it wont play the sounds or show the Particles. I assume it has something to do with the meta, but is throws no errors and works, except for the particles (and the sound). Can anyone help me?

    Code:
    Firework fw = (Firework) activePlayer.getWorld().spawn(point, Firework.class);
                                    FireworkMeta fwmeta = fw.getFireworkMeta();
                                    FireworkEffect fweffect = FireworkEffect.builder()
                                            .flicker(false)
                                            .trail(true)
                                            .withColor(Color.WHITE)
                                            .with(Type.BALL_LARGE)
                                            .build();
                                    fwmeta.clearEffects();
                                    fwmeta.addEffect(fweffect);
                                    fwmeta.setPower(0);
                                    fw.setFireworkMeta(fwmeta);
                                    fw.detonate();
    I am aware of the fact that my code is useing things that almost do the same thing (or do the exact same thing just with a other approach). I am coding on 1.13 if that matters.
    NOTE: the Location "point" is defined.

    Thanks in advance of your help!
     
  2. Is there really nobody who knows anything about fireworks?

    All I know is that you could try to print fweffect, fwmeta and fw to see if anything is suspicious.
    Or maybe settings the power to 1 instead of 0, but that's just a dumb guess.
     
  3. hmm let me have a look into this i dont really deal with fireworks
     
  4. Offline

    Grauly

    Ok that would be simple debug, but how do I print them out? i guess object#toString(); (hopefully this is written like this, pls correcte me) dosnt work that simple :D
    But ill try find a way to do that. And with the power... ill try.

    I Hope you dont come to a point like mine :)

    @knokko @Shadow_tingBRO Thanks for replying! I almost gave up on this.

    UPDATE: I built in the debug, and nothing seems wrong, but still the same problems from the beginning:
    Debug.png

    This is the debug from THIS:
    Code:
     String s1 = String.valueOf(fweffect.hasFlicker());
    String s2 = String.valueOf(fweffect.hasTrail());
    String s3 = fweffect.getColors().get(0).toString();
    String s4 = fweffect.getType().toString();
    String finalString = s1 + ", " + s2 + ", " + s3 + ", " + s4;
    Bukkit.broadcastMessage(finalString);
    I know. Not the most efficient way :)
     
    Last edited: Oct 19, 2018
  5. @Grauly
    Nothing seems wrong indeed. It's very hard to debug because it looks like the problem is not in your code. Working with other peoples code can be so nasty ;(

    What happens if you remove the line '
    fwmeta.clearEffects();
    '?

    Or maybe, can you try to spawn a simple Firework without modifying with any additional code?


    If the ideas above don't help, I have some more:

    Listen for the EntitySpawnEvent and check if the entity that spawns is a Firework. If it is, then print all it's relevant data.
    After that, go to your test server, craft a normal fireworks and launch it. Compare the output you get with the output of your plug-in fireworks.

    If you still can't find anything:

    Get the NMS FireworkRocketEntity by using ((CraftFirework)fw).getHandle(); (or something like that). Search for the method that saves it's NBT data. Once you find that method, go back to your listener and print the entire NBT in the console. Do that with both your custom fireworks and normal fireworks.

    If you still don't know why, it's time for some very ugly coding. Then use Bukkit.dispatchCommand and the /summon command to spawn fireworks with the right NBT.
     
    Last edited: Oct 19, 2018
  6. Offline

    Grauly

    Ok... a lot of stuff happened. I tested a few things(based the ideas of @knokko ), and found:

    1. Turnes out, what actualy causes the problem is the "fw.detonate()" , it seems that it is too quick, so that the effects cant get applied in time (ok i removed the "fwmeta.clearEffects()" too but i dont thinks that was the problem :) ).

    2. This solved a big part of the problem ( BIG THANKS ) but even with a power of 0 the rocket takes about half a second to detonate (but with the colors and the effects :D).

    So thats the only question remaining, but again a BIG thank you, for putting work into it.
    Ill take a look if I can use the /summon Command for instant firework but i dont know how it will turn out.
    Thanks Again!
     
  7. @Grauly
    You could try to register a task to the Bukkit scheduler that lets your rocket explode after a delay.

    I think /summon is more like a last resort, not exactly a proper solution. Nevertheless, in mc 1.8 (I don't know about later versions), it was possible to set the fuse to 0 and let them explode instantly.
     
  8. Offline

    Grauly

    @knokko ill try to schedule it for the lowest time possible(1 tick as far as i know) , and see how that turns out, I also thought about doing the declaraion of e.g. the effect before i apply it or something like that.
    To the command stuff: I couldnt find any good solution for 1.13 , and ill stop working on that. but setting the fuse is as far as I understand how the "setPower()" method works, and... it dose not work as intended.

    UPDATE: using the scheduler to schedule the fw.detonate works. I am going to mark this as solved.

    Big thanks to @knokko !
     
    Last edited: Oct 21, 2018
Thread Status:
Not open for further replies.

Share This Page