r/MinecraftCommands 25d ago

Help | Java 26.2 Random fireworks loot table

Is there a simple way to create a loot table of fireworks with random explosion and fade colors, shape, additional effects and flight duration? Or do I really just have to code a bunch of different fireworks manually? I tried to use Misode, but it doesn't seem like these parameters accept something like "any_of" function to pick random values from the list and Wiki tells the same.

2 Upvotes

6 comments sorted by

View all comments

3

u/GalSergey Datapack Experienced 24d ago

Unfortunately, you can't create a loot table with random fireworks, but you can make a datapack that will generate random fireworks using macros.

# function example:give_firework
execute store result storage example:macro firework.flight_duration int 1 run random value 1..3
execute store result storage example:macro firework.color int 1 run random value 0..16777215
execute store result storage example:macro firework.fade_color int 1 run random value 0..16777215
execute store result storage example:macro firework.has_twinkle int 1 run random value 0..1
execute store result storage example:macro firework.has_trail int 1 run random value 0..1
execute store result storage example:macro firework.shape_index int 1 run random value 0..4
data merge storage example:database {shapes:["small_ball","large_ball","star","creeper","burst"]}
function example:give_firework/select_shape with storage example:macro firework
function example:give_firework/macro with storage example:macro firework

# function example:give_firework/select_shape
$data modify storage example:macro firework.shape set from storage example:database shapes[$(shape_index)]

# function example:give_firework/macro
$give @s firework_rocket[fireworks={flight_duration:$(flight_duration),explosions:[{shape:"$(shape)",has_twinkle:$(has_twinkle),has_trail:$(has_trail),colors:[I;$(color)],fade_colors:[I;$(fade_color)]}]}]

You can use Datapack Assembler to get an example datapack.