Spawning a firework

Hi guys,
I’m new to SpongeAPI and I’m having some trouble trying to spawn a firework.
I’m able to create the FireworkEffect using the FireworkAPI, but I don’t know how to spawn it.

This is what I have so far:
FireworkEffect.builder().shape(FireworkShapes.STAR).color(Color.CYAN).flicker(false).trail(true).build();

        Entity firework = event.getTargetEntity().getLocation().getExtent().createEntity(EntityTypes.FIREWORK, event.getTargetEntity().getPosition());
        event.getTargetEntity().getLocation().getExtent().spawnEntity(firework); //TODO try

Btw, is there any [code] thing for copy/pasting code on the forums?
Thanks!

So the following code is what I have just tested.

Locatable locatable;
Firework firework = (Firework) locatable.getLocation().createEntity(EntityTypes.FIREWORK);
locatable.getLocation().spawnEntity(firework);

This does spawn the firework however it blows up with no effect right away hence why you may think its not spawning. So apply the effect and you will see it

As for your code copy and paste, the sponge forums uses MARKDOWN for its formatting, in paticular the Github flavour, here is a quick cheatsheet Markdown Cheatsheet · adam-p/markdown-here Wiki · GitHub

For the code blocks that I have used above, do 4 spaces before the line of the code starts, but if you already have code to copy and paste then I would do it like the following

Bit of random code
which is done using ` on either end of the code

Thanks for your answer.
Indeed, my code does spawn the firework. However, I want my custom firework to be spawned, not a default one.

Do you mean apply the effect of?

FireworkEffect.builder().shape(FireworkShapes.STAR).color(Color.CYAN).flicker(false).trail(true).build()

Yes, that’s what I’m trying to achieve

So a firework can have multiple effects, so create a array of firework effects, add that effect and then offer the firework effect to the firework

firework.offer(Keys.FIREWORK_EFFECT, effects);

Do that before the spawn

1 Like

EDIT: nvm, it is working but the firework is really small. How can I make it longer? Like I want it to go into the sky before exploding, not right on top of my head

Offer the following key

1 Like