Page 1 of 2

[Mod] Fireworks [fireworks]

PostPosted: Tue Oct 23, 2012 01:44
by InfinityProject
The idea came from here: http://minetest.net/forum/viewtopic.php?pid=48489#p48489

Fireworks are cool right? Well I'm adding them to minetest. Here, have a screenshot:

[img=Fireworks]https://dl.dropbox.com/u/82668184/screenshot_3631640.png[/img]

What this mod does is when the fireworks are punched, the fire part appears in the sky and disappears in a few seconds.

Crafting w = wood and t = torch r = red fireworks b = blue y = yellow
Red Fireworks
www
wtw
www

Blue Fireworks
r

Yellow Fireworks
b

The rest are shapeless (can be crafted in any order.)
Orange Fireworks
r y

Green Fireworks
b y

Purple Fireworks
r b

Rainbow Fireworks

Just craft all of the colors together for 5 rainbow fireworks!

Download v0.3 (latest)
Download v0.2
Download v0.1

Changelog:
v0.1 Initial release
v0.2 Fireworks look more realistic, added blue.
v0.3 Fireworks now spawn in random locations in the sky, added orange, yellow, green, purple, and rainbow.

License: WTFPL
Depends: default

PostPosted: Tue Oct 23, 2012 01:57
by cornernote
this is a really cool idea! Hey, any chance you could use the particles mod to make the fire parts? that would look sweet if it shot up into the air, then exploded into colours of light that then die just before they hit the ground.

PostPosted: Tue Oct 23, 2012 01:58
by InfinityProject
That would look freaking awesome! Can your particles just be activated when a node is dug? Or can they be used for this purpose?

PostPosted: Tue Oct 23, 2012 02:14
by Josh
Intresting mod :)

PostPosted: Tue Oct 23, 2012 02:18
by cornernote
You'd probably have to just copy some code from particles into your mod. I dont think its worth depending on particles.

Have a look here:
https://github.com/cornernote/minetest-particles/blob/master/particles/init.lua

Change this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_on_dignode(function(pos, oldnode, digger)


To this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
fireworks.explode(function()


You'll have to do a bit more than that inside the function, but once that is working, you can call fireworks.explode() to make your fireworks particles.

You may also find it useful to see older versions of particles mod, it was less complex to understand in earlier versions:

initial version: https://github.com/cornernote/minetest-particles/tree/de92c558a5ba5c5b44e0ccd966dd6f81d1ae689a

version before pilzadam's overhaul: https://github.com/cornernote/minetest-particles/tree/1fb64627e698d58cff89bd1bb2d4b02a907c2001

PostPosted: Tue Oct 23, 2012 03:38
by mauvebic
would be nicer more round :-)

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
for x=-radius,radius do
for y=-radius,radius do
for z=-radius,radius do
   if x*x+y*y+z*z <= radius*radius then
      add_particle({x=pos.x+x,y=pos.y+y,z=pos.z+z}) end
end
end
end


though is each particle it's own entity? might lag :-/

PostPosted: Tue Oct 23, 2012 05:16
by cornernote
i think they should all start in the middle (about 100-200 of them), and explode outwards with great velocity, and gravity, then die after about 1-3 seconds.

PostPosted: Wed Oct 24, 2012 00:51
by InfinityProject
Now, I am no good at all with entities so creating them would not be easy for me. Is there a way to perhaps just spawn the particles when the fireworks node is punched?

Also mauvebic I would love to use that somehow.

PostPosted: Wed Oct 24, 2012 02:14
by mauvebic
this is the relevant bit you need:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local radius = 6 -- feel free to change this
for x=-radius,radius do
for y=-radius,radius do
for z=-radius,radius do
   if x*x+y*y+z*z <= radius*radius then
      minetest.env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z},{name='fireworks:node'}) end
end
end
end


thats it. just check the nodename and the radius you want and you should be good 2 go :-) the codes already wtfpl

PostPosted: Wed Oct 24, 2012 23:45
by InfinityProject
V0.2 Coming soon
[img=fireworks2]https://dl.dropbox.com/u/82668184/screenshot_85123323.png[/img]
Edit: 800th post!

PostPosted: Thu Oct 25, 2012 00:33
by mauvebic
Wow, that looks like the real deal :-) +1

PostPosted: Thu Oct 25, 2012 01:29
by InfinityProject
Thanks. I changed the node's drawtype to plantlike. It's actually amazing how good it looks. I want Corenernote's particles to kind of fall to the ground when the node disappears. Also I'm adding sound and blue fireworks.

PostPosted: Thu Oct 25, 2012 01:42
by InfinityProject
[img=Fireworks blue]https://dl.dropbox.com/u/82668184/screenshot_92310120.png[/img]

PostPosted: Thu Oct 25, 2012 02:24
by cornernote
that looks awesome! are you using nodes, or entities (register_node or register_entity)?

would love to see the current code so i can have a fiddle

PostPosted: Thu Oct 25, 2012 02:26
by InfinityProject
Nodes,
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
function fireworks_activate (pos, node)
if
  node.name == "fireworks:firework_red"
then
local radius = 4
for x=-radius,radius do
for y=-radius,radius do
for z=-radius,radius do
   if x*x+y*y+z*z <= radius*radius then
      minetest.env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z},{name='fireworks:red'}) end
end
end
end
minetest.sound_play("fireworks.ogg",
    {pos = pos, gain = 1.0, max_hear_distance = 32,})
elseif
  node.name == "fireworks:firework_blue"
then
local radius = 4
for x=-radius,radius do
for y=-radius,radius do
for z=-radius,radius do
   if x*x+y*y+z*z <= radius*radius then
      minetest.env:add_node({x=pos.x+x,y=pos.y+y,z=pos.z+z},{name='fireworks:blue'}) end
end
end
end
minetest.sound_play("fireworks.ogg",
    {pos = pos, gain = 1.0, max_hear_distance = 32,})
end
end
minetest.register_on_punchnode(fireworks_activate)

PostPosted: Thu Oct 25, 2012 02:42
by cornernote
it seems...
in order to make them move, they have to be entities.
in order to make them light, they have to be nodes.

=(

PostPosted: Thu Oct 25, 2012 02:46
by InfinityProject
What I want definately is for the fireworks to launch into the air and then explode. Could the node change into an entity and turn back to a node when it has hit a position? Say y+8

PostPosted: Thu Oct 25, 2012 05:06
by cornernote
minetest.env:remove_node()
minetest.env:add_entity()

then in the onstep of the entity, after a timer expires, do the opposite.

PostPosted: Thu Oct 25, 2012 15:53
by VanessaE
Suggestion for the light issue: Register entities for the sparks so they can move, but also register a single "light node" with light level set to maximum, and place a whole bunch of them in a more or less spherical formation. Give that node fully transparent (e.g. empty) textures so that it isn't actually visible. Then delete them randomly as the sparks dissipate.

PostPosted: Fri Oct 26, 2012 02:46
by InfinityProject
Will look into that Vanessa.

Mod updated.

PostPosted: Fri Oct 26, 2012 03:42
by mauvebic
You can remove the nodes by generating a sphere of air from the same pos with the same radius, from your fireworks function using minetest.after(10,function() <--code--> end) Otherwise you could register them as falling nodes?

Please avoid entities, you'll inhibit your players ability to fire multiple fireworks at once, generating a sphere of nodes is consuming enough for most CPUs. Besides, it already looks quite nice :-)

PostPosted: Fri Oct 26, 2012 10:34
by InfinityProject
I had tried falling nodes but it didn't look very good. Why not keep the abm? It works well.

PostPosted: Sun Oct 28, 2012 17:47
by Neuromancer
This is a really cool mod.

I created some sound effects for you, and made it so they blow up in the air in random locations.
-You need to hit R to enable full viewing range to see them.
-place a bunch of red and a blue & red fireworks on the ground near enough so you can click them
-left click them in rapid succession and look up.

http://ompldr.org/vZzI2Zg

Tried this hooked up to my stereo system with some serious bass. The sounds got waaay better.
Note: I found a bug where if you left clicked on any node it would activate the firework. This has been fixed in the download above.

Does anyone have an idea on how to make the fireworks disappear faster? And/or to make them give off bright flashes of light or just more light?

PostPosted: Thu Nov 01, 2012 03:04
by InfinityProject
Nice neuromancer! Ill add that in next version. I'm gonna add green, yellow, purple, and rainbow. I will also attempt mesecon compatibility.

PostPosted: Thu Nov 01, 2012 12:07
by Jordach
This means that mesecon clocks can be used!

PostPosted: Sat Nov 03, 2012 13:04
by Neuromancer
InfinityProject wrote:Nice neuromancer! Ill add that in next version. I'm gonna add green, yellow, purple, and rainbow. I will also attempt mesecon compatibility.

Sweet! Looking forward to it!

PostPosted: Sat Nov 03, 2012 23:01
by InfinityProject
[img=purple]https://dl.dropbox.com/u/82668184/screenshot_95581952.png[/img]

[img=green]https://dl.dropbox.com/u/82668184/screenshot_95819153.png[/img]

PostPosted: Sun Nov 04, 2012 04:00
by InfinityProject
Such beauty.
[img=fireworks_all]https://dl.dropbox.com/u/82668184/screenshot_3631640.png[/img]

PostPosted: Sun Nov 04, 2012 05:46
by InfinityProject
Getting a bug in crafting.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_craft({
        type = "shapeless",
    output = "fireworks:firework_rainbow 5",
    recipe = {
        {"fireworks:firework_red", "fireworks:firework_blue", "fireworks:firework_yellow"},
        {"fireworks:firework_orange", "fireworks:firework_yellow", "fireworks:firework_green"},
        {"fireworks:firework_purple", "", ""}
    }
})


It works without it being shapeless so I think I'm using it wrong.

PostPosted: Sun Nov 04, 2012 09:11
by PilzAdam
InfinityProject wrote:Getting a bug in crafting.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_craft({
        type = "shapeless",
    output = "fireworks:firework_rainbow 5",
    recipe = {
        {"fireworks:firework_red", "fireworks:firework_blue", "fireworks:firework_yellow"},
        {"fireworks:firework_orange", "fireworks:firework_yellow", "fireworks:firework_green"},
        {"fireworks:firework_purple", "", ""}
    }
})


It works without it being shapeless so I think I'm using it wrong.

If the crafting type is shapeless you cant define a 2D table. It should be a 1D list of items or not shapeless.