mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-17 16:41:06 +01:00
Convert campfire particle spawning from ABM to particle spawner
This commit is contained in:
parent
c32e88e910
commit
1d28a8e4ac
1 changed files with 95 additions and 44 deletions
|
@ -161,6 +161,75 @@ function mcl_campfires.cook_item(pos, elapsed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function destroy_particle_spawner (pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local part_spawn_id = meta:get_int("particle_spawner_id")
|
||||||
|
if part_spawn_id and part_spawn_id > 0 then
|
||||||
|
minetest.delete_particlespawner(part_spawn_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function create_smoke_partspawner (pos, constructor)
|
||||||
|
if not constructor then
|
||||||
|
destroy_particle_spawner (pos)
|
||||||
|
end
|
||||||
|
|
||||||
|
local haybale = false
|
||||||
|
|
||||||
|
local node_below = vector.offset(pos, 0, -1, 0)
|
||||||
|
if minetest.get_node(node_below).name == "mcl_farming:hay_block" then
|
||||||
|
haybale = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local smoke_timer
|
||||||
|
|
||||||
|
if haybale then
|
||||||
|
smoke_timer = 8
|
||||||
|
else
|
||||||
|
smoke_timer = 4.75
|
||||||
|
end
|
||||||
|
|
||||||
|
local spawner_id = minetest.add_particlespawner({
|
||||||
|
amount = 3,
|
||||||
|
time = 0,
|
||||||
|
minpos = vector.add(pos, vector.new(-0.25, 0, -0.25)),
|
||||||
|
maxpos = vector.add(pos, vector.new( 0.25, 0, 0.25)),
|
||||||
|
minvel = vector.new(-0.2, 0.5, -0.2),
|
||||||
|
maxvel = vector.new(0.2, 1, 0.2),
|
||||||
|
minacc = vector.new(0, 0.5, 0),
|
||||||
|
maxacc = vector.new(0, 0.5, 0),
|
||||||
|
minexptime = smoke_timer,
|
||||||
|
maxexptime = smoke_timer * 2,
|
||||||
|
minsize = 6,
|
||||||
|
maxsize = 8,
|
||||||
|
collisiondetection = true,
|
||||||
|
vertical = false,
|
||||||
|
texture = "mcl_campfires_particle_1.png",
|
||||||
|
texpool = {
|
||||||
|
"mcl_campfires_particle_1.png";
|
||||||
|
{ name = "mcl_campfires_particle_1.png", fade = "out" },
|
||||||
|
{ name = "mcl_campfires_particle_2.png" },
|
||||||
|
{ name = "mcl_campfires_particle_3.png" },
|
||||||
|
{ name = "mcl_campfires_particle_4.png" },
|
||||||
|
{ name = "mcl_campfires_particle_5.png" },
|
||||||
|
{ name = "mcl_campfires_particle_6.png" },
|
||||||
|
{ name = "mcl_campfires_particle_7.png" },
|
||||||
|
{ name = "mcl_campfires_particle_8.png" },
|
||||||
|
{ name = "mcl_campfires_particle_9.png" },
|
||||||
|
{ name = "mcl_campfires_particle_10.png" },
|
||||||
|
{ name = "mcl_campfires_particle_11.png" },
|
||||||
|
{ name = "mcl_campfires_particle_11.png" },
|
||||||
|
{ name = "mcl_campfires_particle_12.png" },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
meta:set_int("particle_spawner_id", spawner_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function mcl_campfires.register_campfire(name, def)
|
function mcl_campfires.register_campfire(name, def)
|
||||||
-- Define Campfire
|
-- Define Campfire
|
||||||
minetest.register_node(name, {
|
minetest.register_node(name, {
|
||||||
|
@ -207,7 +276,8 @@ function mcl_campfires.register_campfire(name, def)
|
||||||
drawtype = "mesh",
|
drawtype = "mesh",
|
||||||
mesh = "mcl_campfires_campfire.obj",
|
mesh = "mcl_campfires_campfire.obj",
|
||||||
tiles = {
|
tiles = {
|
||||||
{name=def.fire_texture,
|
{
|
||||||
|
name=def.fire_texture,
|
||||||
animation={
|
animation={
|
||||||
type="vertical_frames",
|
type="vertical_frames",
|
||||||
aspect_w=32,
|
aspect_w=32,
|
||||||
|
@ -215,14 +285,16 @@ function mcl_campfires.register_campfire(name, def)
|
||||||
length=2.0
|
length=2.0
|
||||||
}}
|
}}
|
||||||
},
|
},
|
||||||
overlay_tiles = {{
|
overlay_tiles = {
|
||||||
|
{
|
||||||
name=def.lit_logs_texture,
|
name=def.lit_logs_texture,
|
||||||
animation = {
|
animation = {
|
||||||
type = "vertical_frames",
|
type = "vertical_frames",
|
||||||
aspect_w = 32,
|
aspect_w = 32,
|
||||||
aspect_h = 16,
|
aspect_h = 16,
|
||||||
length = 2.0,
|
length = 2.0,
|
||||||
}},
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
use_texture_alpha = "clip",
|
use_texture_alpha = "clip",
|
||||||
groups = { handy=1, axey=1, material_wood=1, lit_campfire=1 },
|
groups = { handy=1, axey=1, material_wood=1, lit_campfire=1 },
|
||||||
|
@ -232,6 +304,10 @@ function mcl_campfires.register_campfire(name, def)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 4)
|
inv:set_size("main", 4)
|
||||||
|
create_smoke_partspawner (pos, true)
|
||||||
|
end,
|
||||||
|
on_destruct = function(pos)
|
||||||
|
destroy_particle_spawner (pos)
|
||||||
end,
|
end,
|
||||||
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
|
on_rightclick = function (pos, node, player, itemstack, pointed_thing)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
@ -312,37 +388,12 @@ minetest.register_globalstep(function(dtime)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function mcl_campfires.generate_smoke(pos, haybale)
|
minetest.register_lbm({
|
||||||
local smoke_timer
|
|
||||||
|
|
||||||
if haybale then
|
|
||||||
smoke_timer = 8
|
|
||||||
else
|
|
||||||
smoke_timer = 4.75
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.add_particle({
|
|
||||||
pos = vector.offset(pos, math.random(-0.5, 0.5), 0, math.random(-0.5, 0.5)),
|
|
||||||
velocity = vector.new(0, 1, 0),
|
|
||||||
texture = "mcl_campfires_particle_" .. math.random(1, 12) .. ".png",
|
|
||||||
size = 10,
|
|
||||||
acceleration = vector.new(0, 0.5, 0),
|
|
||||||
collisiondetection = true,
|
|
||||||
expirationtime = smoke_timer,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
label = "Campfire Smoke",
|
label = "Campfire Smoke",
|
||||||
|
name = "mcl_campfires:campfire_smoke",
|
||||||
nodenames = {"group:lit_campfire"},
|
nodenames = {"group:lit_campfire"},
|
||||||
interval = 2,
|
run_at_every_load = true,
|
||||||
chance = 2,
|
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local node_below = vector.offset(pos, 0, -1, 0)
|
create_smoke_partspawner (pos)
|
||||||
local haybale = false
|
|
||||||
if minetest.get_node(node_below).name == "mcl_farming:hay_block" then
|
|
||||||
haybale = true
|
|
||||||
end
|
|
||||||
mcl_campfires.generate_smoke(pos, haybale)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue