1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2025-07-27 17:30:17 +02:00

abstract the particle spawner start/stop functions

This commit is contained in:
Vanessa Ezekowitz
2015-05-10 21:03:50 -04:00
parent 8ef4e8c39d
commit 12f5ac9d02
3 changed files with 128 additions and 82 deletions

View File

@ -168,33 +168,12 @@ homedecor.register("shower_tray", {
sounds = default.node_sound_stone_defaults(),
on_destruct = function(pos)
headpos = {x=pos.x, y=pos.y+2, z=pos.z}
local above_spawner_meta = minetest.get_meta(headpos)
local id = above_spawner_meta:get_int("active")
local s_handle = above_spawner_meta:get_int("sound")
if id ~= 0 then
minetest.delete_particlespawner(id)
end
if s_handle then
minetest.after(0, function(s_handle)
minetest.sound_stop(s_handle)
end, s_handle)
end
above_spawner_meta:set_int("active", nil)
above_spawner_meta:set_int("sound", nil)
homedecor.stop_particle_spawner(headpos)
end
})
--Shower Head
local fdir_to_flowpos = {
minx = { 0.15, 0.05, -0.15, -0.05 }, maxx = { -0.15, -0.3, 0.15, 0.3 },
minz = { 0.05, 0.15, -0.05, -0.15 }, maxz = { -0.3, -0.15, 0.3, 0.15 },
velx = { 0, -0.2, 0, 0.2 }, velz = { -0.2, 0, 0.2, 0 }
}
local sh_cbox = {
type = "fixed",
@ -214,69 +193,21 @@ homedecor.register("shower_head", {
selection_box = sh_cbox,
walkable = false,
on_rightclick = function (pos, node, clicker)
local below = minetest.get_node({x=pos.x, y=pos.y-2.0, z=pos.z})
local is_tray = string.find(below.name, "homedecor:shower_tray")
local fdir = node.param2
local minx = fdir_to_flowpos.minx[fdir + 1]
local maxx = fdir_to_flowpos.maxx[fdir + 1]
local minz = fdir_to_flowpos.minz[fdir + 1]
local maxz = fdir_to_flowpos.maxz[fdir + 1]
local velx = fdir_to_flowpos.velx[fdir + 1]
local velz = fdir_to_flowpos.velz[fdir + 1]
local this_spawner_meta = minetest.get_meta(pos)
local id = this_spawner_meta:get_int("active")
local s_handle = this_spawner_meta:get_int("sound")
if id ~= 0 then
if s_handle then
minetest.after(0, function(s_handle)
minetest.sound_stop(s_handle)
end, s_handle)
end
minetest.delete_particlespawner(id)
this_spawner_meta:set_int("active", nil)
this_spawner_meta:set_int("sound", nil)
return
end
if fdir and fdir < 4 and is_tray and (not id or id == 0) then
id = minetest.add_particlespawner({
amount = 60, time = 0, collisiondetection = true,
minpos = {x=pos.x - minx, y=pos.y-0.45, z=pos.z - minz},
maxpos = {x=pos.x - maxx, y=pos.y-0.45, z=pos.z - maxz},
minvel = {x=velx, y=-2, z=velz}, maxvel = {x=velx, y=-2, z=velz},
minacc = {x=0, y=0, z=0}, maxacc = {x=0, y=-0.05, z=0},
minexptime = 2, maxexptime = 4, minsize = 0.5, maxsize = 1,
texture = "homedecor_water_particle.png",
})
s_handle = minetest.sound_play("homedecor_shower", {
pos = pos,
max_hear_distance = 5,
loop = true
})
this_spawner_meta:set_int("active", id)
this_spawner_meta:set_int("sound", s_handle)
return
local below = minetest.get_node_or_nil({x=pos.x, y=pos.y-2.0, z=pos.z})
if below and string.find(below.name, "homedecor:shower_tray") then
local particledef = {
outlet_x = 0,
outlet_y = -0.42,
outlet_z = 0.1,
velocity_x = { min = -0.15, max = 0.15 },
velocity_z = { min = -0.3, max = 0.1 },
spread = 0.12
}
homedecor.start_particle_spawner(pos, node, particledef, "homedecor_shower")
end
end,
on_destruct = function(pos)
local this_spawner_meta = minetest.get_meta(pos)
local id = this_spawner_meta:get_int("active")
local s_handle = this_spawner_meta:get_int("sound")
if id ~= 0 then
minetest.delete_particlespawner(id)
end
if s_handle then
minetest.after(0, function(s_handle)
minetest.sound_stop(s_handle)
end, s_handle)
end
this_spawner_meta:set_int("active", nil)
this_spawner_meta:set_int("sound", nil)
homedecor.stop_particle_spawner(pos)
end
})