5) Create the new firework recipe
I will create the Barrier Firework, a simple one. It will create barrier particles when it explodes.
But first, I need to create the item and its recipe. I'm opening data/cool_fireworks/functions/checkitem.mcfunction
I want people need a Red Dye item to get the firework. The Red Dye item id is "minecraft:red_dye". If you don't know the id of an item, go on minecraft with commands enabled, hold the item you want and type /data get entity @s SelectedItem.id The id will be minecraft:+what the game gave you.
So, I will write
execute if entity @e[type=item,tag=!global.ignore,distance=..0.5,nbt={Item:{id:"minecraft:red_dye",Count:1b}}] run data modify storage ulg:fireworks intick.checkitem set value "cool_fireworks:barrier"
execute if entity @e[type=item,tag=!global.ignore,distance=..0.5,nbt={Item:{id:"minecraft:red_dye",Count:1b}}] run kill @e[type=item,tag=!global.ignore,tag=!global.ignore.kill,distance=..0.5,nbt={Item:{id:"minecraft:red_dye",Count:1b}},limit=1]
Two lines, you only need to change minecraft:red_dye inside the id of the item you want, and cool_fireworks:barrier in yourdatapacknamespace:fireworknamespace. Your namespace is the one you chose before, the firework namespace is a new one. I want to add the Barrier Firework, so I chose "barrier" as firework namespace.
Remember the firework namespace, for the same firework you need to use the same namespace.
Now I will open data/cool_fireworks/functions/performfireworkchange.mcfunction and I will write this text inside:
execute if data storage ulg:fireworks {intick:{checkitem:"cool_fireworks:barrier"}} run data modify entity @s Item.tag.ulg set value {customfirework:1b,CustomFirework:"cool_fireworks:barrier",PersistentFirework:{IsPersistent:0b,RemoveDefaultDurability:0b}}
If you want to add more checks and changes, you need to know how datapacks work and redirect to a new function after run keyword.
Now, replace cool_fireworks:barrier with yourdatapacknamespace:fireworknamespace, as you did before.
If you want to know that, the firework data are the ones after "set value".
customfirework:1b means that fireworks is a custom one, so my datapack knows and applies the functions on it.
CustomFirework:"yourdatapackname:fireworknamespace" is used to set what custom firework it is. We want it to be our own firework.
PersistentFirework part is used for persistent fireworks, that is fireworks that last a long time exploding or doing things. I will not explain how to work on them in this tutorial. IsPersistent says to my datapack if the firework is persistent (1b) or not (0b). Again, use 0b since we don't need a persistent firework. RemoveDefaultDurability says the datapack if the firework will last 3 seconds (0b) or more (1b, and the time is specified inside the explosion function).
6) Create the Firework Explosion
Now I'm opening data/cool_fireworks/functions/performexplosion.mcfunction to write a line inside it.
execute as @s[type=minecraft:firework_rocket,tag=!global.ignore,nbt={FireworksItem:{tag:{ulg:{CustomFirework:"cool_fireworks:barrier"}}}}] run function cool_fireworks:explosions/barrier
Again, replace cool_fireworks:barrier with yourdatapacknamespace:fireworknamespace. Replace cool_fireworks:explosions/barrier with yourdatapacknamespace:explosions/fireworknamespace.
I know I am repeating the same thing many times, but I want it to be as understandable as possible and I hope to succeed.
Go on data/cool_fireworks/functions and create the "explosions" folder there. Inside this new folder, I will create barrier.mcfunction file. You will call it as the firework namespace but always with the .mcfunction extensions.
Open this new file...
I said I want it to create barrier particles, so I will just place "particle barrier ~ ~ ~ 1 1 1 1 500 force" in a line.
Remember you need to use relative coordinates (~ ~ ~) and force method for particles, or people will not be able to see it.
Done!
7) Get your firework playing survival or creative
Place an item frame on the floor or on a table, place a firework you created inside it, and drop the item you chose. For my example, I will drop a red dye on the item frame and wait (3 seconds). If you did the first steps well, the item will disappear and the firework will have become the custom one. How to know if it works? Find a beautiful plane and try it!
Here my cool_fireworks:barrier Firework