#move to the ground
execute at @s run spreadplayers ~ ~ 0 1 false @s


#generate random number(based on marker's UUID) between 0-3 to determine the firework type
execute at @s run execute store result score @s KyuDummy run data get entity @s UUID[0] .1
scoreboard players set @s KyuDummy2 4
scoreboard players operation @s KyuDummy %= @s KyuDummy2

#
execute at @s[scores={KyuDummy=0}] run summon firework_rocket ~ ~ ~ {Tags:["FireworkRocketGetData"],Trail:1b,Life:0,LifeTime:100,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:0,Flicker:0b,Colors:[I;57374],FadeColors:[I;53020]}]}}}}
execute at @s[scores={KyuDummy=1}] run summon firework_rocket ~ ~ ~ {Tags:["FireworkRocketGetData"],Trail:1b,Life:0,LifeTime:100,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:1,Flicker:0b,Colors:[I;57374],FadeColors:[I;53020]}]}}}}
execute at @s[scores={KyuDummy=2}] run summon firework_rocket ~ ~ ~ {Tags:["FireworkRocketGetData"],Trail:1b,Life:0,LifeTime:100,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:2,Flicker:0b,Colors:[I;57374],FadeColors:[I;53020]}]}}}}
#execute at @s[scores={KyuDummy=3}] run summon firework_rocket ~ ~ ~ {Tags:["FireworkRocketGetData"],Trail:1b,Life:0,LifeTime:100,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:3,Flicker:0b,Colors:[I;57374],FadeColors:[I;53020]}]}}}}
execute at @s[scores={KyuDummy=3}] run summon firework_rocket ~ ~ ~ {Tags:["FireworkRocketGetData"],Trail:1b,Life:0,LifeTime:100,FireworksItem:{id:firework_rocket,Count:1,tag:{Fireworks:{Explosions:[{Type:4,Flicker:0b,Colors:[I;57374],FadeColors:[I;53020]}]}}}}



#generate random number(based on marker's UUID) between 0-35, then add 30, to determine the firework lifetime
execute at @s run execute store result score @s KyuDummy run data get entity @s UUID[1] .1
scoreboard players set @s KyuDummy2 36
scoreboard players operation @s KyuDummy %= @s KyuDummy2
scoreboard players add @s KyuDummy 30
execute at @s run execute store result entity @e[type=firework_rocket,limit=1,sort=nearest,distance=..2,tag=FireworkRocketGetData] LifeTime int 1 run scoreboard players get @s KyuDummy


#10% chance to have the flicker effect
execute if predicate suhc:10percent run execute at @s run data merge entity @e[type=firework_rocket,limit=1,sort=nearest,distance=..2,tag=FireworkRocketGetData] {Flicker:1b}


#generate random number(based on marker's UUID) between 0-16774647 to determine the firework color
execute at @s run execute store result score @s KyuDummy run data get entity @s UUID[2] .1
scoreboard players set @s KyuDummy2 16774648
scoreboard players operation @s KyuDummy %= @s KyuDummy2
execute at @s run execute store result entity @e[type=firework_rocket,limit=1,sort=nearest,distance=..2,tag=FireworkRocketGetData] FireworksItem.tag.Fireworks.Explosions[0].Colors[0] int 1 run scoreboard players get @s KyuDummy


#set the fade colors to 80% of the main color - which is just a darker version of it
execute at @s run execute store result entity @e[type=firework_rocket,limit=1,sort=nearest,distance=..2,tag=FireworkRocketGetData] FireworksItem.tag.Fireworks.Explosions[0].FadeColors[0] int .5 run scoreboard players get @s KyuDummy


execute at @s run tag @e[type=firework_rocket,limit=1,sort=nearest,distance=..2,tag=FireworkRocketGetData] remove FireworkRocketGetData

kill @s[type=marker]





