How can you give a player fireworks?

The Dropper block, available since Minecraft 1.5, can be used for this purpose. It is similar to a dispenser, except that it does not “activate” items like arrows and fireworks, so they will be dropped for the player to pick them up instead.


There are several ways to give a player on your server Fireworks.

Of course, the obvious way is to simply craft them from Firework Stars and give them to the player. This requires materials, requires you to walk up to them, etc. You could leave them in a Chest, but that still isn't automatable.

You can try putting the Fireworks in a Dispenser, but it will fire them off rather than give them. Instead, the Dropper can be used to properly dispense Fireworks that a player can pick up and use.

The most flexible option, however, is the /give command. It requires being an Operator on the server, but the power it has in customizing the fireworks is incredible.

Using /give with Fireworks

Using a command of the form

/give <PLAYERNAME> fireworks <AMOUNT> 0 <DATA>

you can create arbitrarily complex fireworks, using colours not even present in the game, and give them to a player. It works both directly typed in, or through Command Blocks, though direct typing has much more strict character limits. Command blocks can use all the usual @p selector stuff in place of PLAYERNAME.

Explosion Data

The data format is as follows:

{Fireworks:{Flight:<FLIGHT LENGTH>, Explosions:[<EXPLOSION INFO>]}}

Flight length is a number, corresponding to the duration the firework should fly. Explosions will be of the following form:

{Type:<TYPE>, Colors[<COLORS>], Flicker:<0 or 1>, Trail:<0 or 1>}

And you can add multiple explosions by just putting commas between them. The Type is a number, with 0 for Small Ball, 1 for Large Ball, 2 for Star Shaped, 3 for Creeper Shaped, and 4 for Burst. Flicker and Trail (Which control the effects normally gained from using a Diamond or Glowstone Dust in the Firework Star)are 0 to not be used, 1 to be present, and can be omitted entirely.

The Colors section is a series of numbers, with commas between them. Each corresponds to a single colour used to create the firework. The numbers are in the form

Blue + 256 * Green + 256*256*Red

Where Blue, Green, and Red are numbers between 0 and 255. So 255 is solid blue, 65280 is solid green, and 16711680 is solid red.

Putting it together

So, putting it together, a /give command to give my character a single firework, with a fuse length of 3, and a single small-ball explosion of stark blue sparks, should look like:

/give wmailman fireworks 1 0 {Fireworks:{Flight:3, Explosions:[{Type:0, Colors:[255]}]}}

Whereas, a command to give me three fireworks, with a one-length fuse, with two explosions, one a red star, the other a green and blue large ball, would become:

/give wmailman fireworks 1 0 {Fireworks:{Flight:1, Explosions:[{Type:2, Colors:[16711680]}, {Type:1, Colors:[255, 65280]}]}}

And, just for one last example, you could use

/give wmailman fireworks 1 0 {Fireworks:{Flight:3, Explosions:[{Type:0, Colors:[255], Flicker:1, Trail:1}]}}

to create a version of the first fireworks, but with the explosion having both the flicker and trail effects.

Caveats

  • The colour listed on any firework created this way will be named "Custom" in the item, unless you use the exact colour codes created by crafting in-game. Unfortunately, I do not know what those numbers are exactly.

  • Almost everything in the data is case-sensitive.

Firework Stars

You can also do this with Firework Stars. The data tag will be in the format

{Explosion:<EXPLOSION INFO>}

Where the Explosion Info is the same as described for Fireworks.

Pictures

Because this post turned into a bit of a wall of text, here's some example shots of me using /give:

Me typing the command

Once that command is typed in, the resulting firework is added to my inventory:

Me holding the fireworks

The command used here was

/give wmailman fireworks 1 0 {Fireworks:{Flight:3, Explosions:[Type:0, Colors:[255, 65535]}]}}

This means a single firework, fuse length of 3, with one Small Ball explosion, with two colours, one solid blue, the other blue-green.

Despite the names of the colours displaying as Custom, the resulting explosion has nice pretty blue and blue-green sparks, as I expected:

The explosion

Sources:

The Minecraft Wiki Page on the player.dat format has a small section on Fireworks. The colour numbers are described elsewhere on that page. Most of the work lies in turning the result into the JSONish format Minecraft expects. Which is basically just leniently-parsed JSON.


When using a dispenser, the fireworks leave the dispenser armed, so that isn't much good.

Firework in dispenserLaunched firework

Also, because the fireworks all share an ID (401) command blocks can't be used (it just spawns a firework with no explosion in it).

You can, however, use spawners to spawn the dropped item entity (one of Seth Bling's scripts can be used.) These are harder to control, though, and limiting the amount of items the player gets can be tricky.

Dropped item entity Using MCedit to make the spawner Spawned from custom spawner

Note this technique can be used to spawn any custom item, such as enchanted weapons and custom potions.