Moved particle explosion to mcl_fireworks API

- crossbow rockets use the API
- fireworks use it obviously
- fireworks fly a bit faster too
This commit is contained in:
the-real-herowl 2024-12-22 04:37:18 +01:00 committed by the-real-herowl
parent 6066e0dc46
commit 3291786c1f
3 changed files with 194 additions and 190 deletions

@ -8,6 +8,8 @@ local ROCKET_TIMEOUT = 1
local YAW_OFFSET = -math.pi/2
local particle_explosion = mcl_fireworks.particle_explosion
local function damage_explosion(self, damagemulitplier, pos)
if self._harmless then return end
@ -27,194 +29,6 @@ local function damage_explosion(self, damagemulitplier, pos)
end
end
local function particle_explosion(pos)
if pos.object then pos = pos.object:get_pos() end
local particle_pattern = math.random(1, 3)
local fpitch
local type = math.random(1, 2)
local size = math.random(1, 3)
local colors = {"red", "yellow", "blue", "green", "white"}
local this_colors = {colors[math.random(#colors)], colors[math.random(#colors)], colors[math.random(#colors)]}
if size == 1 then
fpitch = math.random(200, 300)
elseif size == 2 then
fpitch = math.random(100, 130)
else
fpitch = math.random(60, 70)
end
if type == 1 then
core.sound_play("mcl_bows_firework", {
pos = pos,
max_hear_distance = 100,
gain = 3.0,
pitch = fpitch/100
}, true)
else
core.sound_play("mcl_bows_firework_soft", {
pos = pos,
max_hear_distance = 100,
gain = 4.0,
pitch = fpitch/100
}, true)
end
if particle_pattern == 1 then
core.add_particlespawner({
amount = 400 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-7 * size,-7 * size,-7 * size),
maxvel = vector.new(7 * size,7 * size,7 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[1]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 400 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-2 * size,-2 * size,-2 * size),
maxvel = vector.new(2 * size,2 * size,2 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[2]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 100 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-14 * size,-14 * size,-14 * size),
maxvel = vector.new(14 * size,14 * size,14 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[3]..".png",
glow = 14,
})
elseif particle_pattern == 2 then
core.add_particlespawner({
amount = 240 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-5 * size,-5 * size,-5 * size),
maxvel = vector.new(5 * size,5 * size,5 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[1]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 500 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-2 * size,-2 * size,-2 * size),
maxvel = vector.new(2 * size,2 * size,2 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[2]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 350 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-3 * size,-3 * size,-3 * size),
maxvel = vector.new(3 * size,3 * size,3 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[3]..".png",
glow = 14,
})
elseif particle_pattern == 3 then
core.add_particlespawner({
amount = 400 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-6 * size,-4 * size,-6 * size),
maxvel = vector.new(6 * size,4 * size,6 * size),
minexptime = .6 * size,
maxexptime = .9 * size,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[1]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 120 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-8 * size,6 * size,-8 * size),
maxvel = vector.new(8 * size,6 * size,8 * size),
minexptime = .6 * size,
maxexptime = .9 * size,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[2]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 130 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-3 * size,3 * size,-3 * size),
maxvel = vector.new(3 * size,3 * size,3 * size),
minexptime = .6 * size,
maxexptime = .9 * size,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[3]..".png",
glow = 14,
})
end
return size
end
core.register_craftitem("mcl_bows:rocket", {
description = S("Arrow"),
_tt_help = S("Ammunition").."\n"..S("Damage from bow: 1-10").."\n"..S("Damage from dispenser: 3"),

@ -1,4 +1,193 @@
local path = minetest.get_modpath("mcl_fireworks")
mcl_fireworks = {}
function mcl_fireworks.particle_explosion(pos)
if pos.object then pos = pos.object:get_pos() end
local particle_pattern = math.random(1, 3)
local fpitch
local type = math.random(1, 2)
local size = math.random(1, 3)
local colors = {"red", "yellow", "blue", "green", "white"}
local this_colors = {colors[math.random(#colors)], colors[math.random(#colors)], colors[math.random(#colors)]}
if size == 1 then
fpitch = math.random(200, 300)
elseif size == 2 then
fpitch = math.random(100, 130)
else
fpitch = math.random(60, 70)
end
if type == 1 then
core.sound_play("mcl_bows_firework", {
pos = pos,
max_hear_distance = 100,
gain = 3.0,
pitch = fpitch/100
}, true)
else
core.sound_play("mcl_bows_firework_soft", {
pos = pos,
max_hear_distance = 100,
gain = 4.0,
pitch = fpitch/100
}, true)
end
if particle_pattern == 1 then
core.add_particlespawner({
amount = 400 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-7 * size,-7 * size,-7 * size),
maxvel = vector.new(7 * size,7 * size,7 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[1]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 400 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-2 * size,-2 * size,-2 * size),
maxvel = vector.new(2 * size,2 * size,2 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[2]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 100 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-14 * size,-14 * size,-14 * size),
maxvel = vector.new(14 * size,14 * size,14 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[3]..".png",
glow = 14,
})
elseif particle_pattern == 2 then
core.add_particlespawner({
amount = 240 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-5 * size,-5 * size,-5 * size),
maxvel = vector.new(5 * size,5 * size,5 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[1]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 500 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-2 * size,-2 * size,-2 * size),
maxvel = vector.new(2 * size,2 * size,2 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[2]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 350 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-3 * size,-3 * size,-3 * size),
maxvel = vector.new(3 * size,3 * size,3 * size),
minexptime = .6 * size / 2,
maxexptime = .9 * size / 2,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[3]..".png",
glow = 14,
})
elseif particle_pattern == 3 then
core.add_particlespawner({
amount = 400 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-6 * size,-4 * size,-6 * size),
maxvel = vector.new(6 * size,4 * size,6 * size),
minexptime = .6 * size,
maxexptime = .9 * size,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[1]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 120 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-8 * size,6 * size,-8 * size),
maxvel = vector.new(8 * size,6 * size,8 * size),
minexptime = .6 * size,
maxexptime = .9 * size,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[2]..".png",
glow = 14,
})
core.add_particlespawner({
amount = 130 * size,
time = 0.0001,
minpos = pos,
maxpos = pos,
minvel = vector.new(-3 * size,3 * size,-3 * size),
maxvel = vector.new(3 * size,3 * size,3 * size),
minexptime = .6 * size,
maxexptime = .9 * size,
minsize = 2 * size,
maxsize = 3 * size,
collisiondetection = false,
vertical = false,
texture = "mcl_bows_firework_"..this_colors[3]..".png",
glow = 14,
})
end
return size
end
dofile(path .. "/register.lua")
dofile(path .. "/crafting.lua")
dofile(path .. "/crafting.lua")

@ -5,6 +5,7 @@ local description = S("Firework Rocket")
local function explode(self, pos)
-- temp code
mcl_fireworks.particle_explosion(pos)
mcl_mobs.mob_class.boom(self, pos, 1)
end
@ -44,7 +45,7 @@ local firework_entity = {
vl_projectile.has_tracer,
function(self, dtime)
self.object:add_velocity(vector.new(0, 2*dtime, 0)) -- TODO var. accel. TODO max speed?
self.object:add_velocity(vector.new(0, 5*dtime, 0)) -- TODO var. accel. TODO max speed?
end,
vl_projectile.collides_with_solids,