Implement new fire particles

This commit is contained in:
iliekprogrammar 2021-03-15 02:57:13 +08:00
parent 53bfda827a
commit b23495b9c1
1 changed files with 65 additions and 0 deletions

View File

@ -28,7 +28,70 @@ local alldirs=
{ x = 0, y = 0, z = 1}
}
-- 3 exptime variants because the animation is not tied to particle expiration time.
local smoke_pdef_base = {
amount = 0.5,
time = 0,
-- minpos = vector.add(pos, { x = -0.45, y = -0.45, z = -0.45 }),
-- maxpos = vector.add(pos, { x = 0.45, y = 0.45, z = 0.45 }),
minvel = { x = 0, y = 0.1, z = 0 },
maxvel = { x = 0, y = 1.4, z = 0 },
-- minexptime = ???,
-- maxexptime = ???,
minsize = 4.0,
maxsize = 5.0,
-- texture = "mcl_particles_smoke_anim.png^[colorize:#000000:???",
animation = {
type = "vertical_frames",
aspect_w = 8,
aspect_h = 8,
-- length = ???,
},
collisiondetection = true,
}
local smoke_pdef_cached = {}
local spawn_smoke = function(pos)
local min = math.min
local new_minpos = vector.add(pos, { x = -0.45, y = -0.45, z = -0.45 })
local new_maxpos = vector.add(pos, { x = 0.45, y = 0.45, z = 0.45 })
-- populate the cache
if not next(smoke_pdef_cached) then
-- the last frame plays for 1/8 * N seconds, so we can take advantage of it
-- to have varying exptime for each variant.
local exptimes = { 1.0, 3.0, 5.0 }
local colorizes = { "178", "204", "243" }
local id = 1
for _,exptime in ipairs(exptimes) do
for _,colorize in ipairs(colorizes) do
smoke_pdef_base.minpos = new_minpos
smoke_pdef_base.maxpos = new_maxpos
smoke_pdef_base.maxexptime = exptime
smoke_pdef_base.animation.length = exptime + 0.1
smoke_pdef_base.minexptime = min(exptime, (7.0/8.0 * (exptime + 0.1) + 0.1))
smoke_pdef_base.texture = "mcl_particles_smoke_anim.png^[colorize:#000000:" ..colorize
smoke_pdef_cached[id] = table.copy(smoke_pdef_base)
mcl_particles.add_node_particlespawner(pos, smoke_pdef_cached[id], "high")
id = id + 1
end
end
-- cache already populated
else
for i, smoke_pdef in ipairs(smoke_pdef_cached) do
smoke_pdef.minpos = new_minpos
smoke_pdef.maxpos = new_maxpos
mcl_particles.add_node_particlespawner(pos, smoke_pdef, "low")
end
end
--[[ Old smoke pdef
local spawn_smoke = function(pos)
mcl_particles.add_node_particlespawner(pos, {
amount = 0.1,
time = 0,
@ -48,6 +111,8 @@ local spawn_smoke = function(pos)
length = 2.1,
},
}, "high")
-- ]]
end
--