From c074e47bcd8bf7c2aeb1904cf906276e355a7f6b Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Tue, 28 Apr 2015 14:08:41 -0400 Subject: [PATCH] fix bug in showerhead spawners (if two or more running at the same time, only the last could be turned off) --- homedecor/bathroom_sanitation.lua | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/homedecor/bathroom_sanitation.lua b/homedecor/bathroom_sanitation.lua index 5129939..84b3bc9 100644 --- a/homedecor/bathroom_sanitation.lua +++ b/homedecor/bathroom_sanitation.lua @@ -201,7 +201,6 @@ homedecor.register("shower_head", { 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 this_spawner_meta = minetest.get_meta(pos) local fdir = node.param2 local minx = fdir_to_flowpos.minx[fdir + 1] local maxx = fdir_to_flowpos.maxx[fdir + 1] @@ -210,9 +209,20 @@ homedecor.register("shower_head", { local velx = fdir_to_flowpos.velx[fdir + 1] local velz = fdir_to_flowpos.velz[fdir + 1] - if fdir and fdir < 4 and this_spawner_meta:get_string("active") ~= "yes" and is_tray - or this_spawner_meta:get_string("active") == "yes" and id == nil and is_tray then - this_spawner_meta:set_string("active", "yes") + local this_spawner_meta = minetest.get_meta(pos) + local id = this_spawner_meta:get_int("active") + + if id ~= 0 then + minetest.after(0, function(s_handle) + minetest.sound_stop(s_handle) + end, s_handle) + local player = clicker:get_player_name() + minetest.delete_particlespawner(id, player) + this_spawner_meta:set_int("active", 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}, @@ -223,19 +233,21 @@ homedecor.register("shower_head", { texture = "homedecor_water_particle.png", }) s_handle = minetest.sound_play("homedecor_shower", { - pos = pos, max_hear_distance = 5, loop = true + pos = pos, + max_hear_distance = 5, + loop = true }) - elseif this_spawner_meta:get_string("active") == "yes" and id then - this_spawner_meta:set_string("active", "no") - minetest.after(0, function(s_handle) - minetest.sound_stop(s_handle) - end, s_handle) - local player = clicker:get_player_name() - minetest.delete_particlespawner(id, player) + this_spawner_meta:set_int("active", id) + return end end, on_destruct = function(pos) - minetest.delete_particlespawner(id) + local this_spawner_meta = minetest.get_meta(pos) + local id = this_spawner_meta:get_int("active") + if id ~= 0 then + minetest.delete_particlespawner(id) + this_spawner_meta:set_int("active", nil) + end end })