Prepare trapdoors code for merging, make trapdoors always toggle their

state when the mesecons signal changes, no matter what state they're in
This commit is contained in:
Jeija 2015-02-03 18:10:49 +01:00
parent 94604e890c
commit a895715720

View File

@ -51,39 +51,30 @@ meseconify_door("doors:door_glass")
meseconify_door("doors:door_obsidian_glass") meseconify_door("doors:door_obsidian_glass")
-- Trapdoor -- Trapdoor
local function punch(pos) local function trapdoor_switch(pos, node)
local meta = minetest.get_meta(pos) local state = minetest.get_meta(pos):get_int("state")
local state = meta:get_int("state")
local me = minetest.get_node(pos)
local tmp_node
local tmp_node2
if state == 1 then if state == 1 then
state = 0
minetest.sound_play("doors_door_close", {pos = pos, gain = 0.3, max_hear_distance = 10}) minetest.sound_play("doors_door_close", {pos = pos, gain = 0.3, max_hear_distance = 10})
tmp_node = {name="doors:trapdoor", param1=me.param1, param2=me.param2} minetest.set_node(pos, {name="doors:trapdoor", param2 = node.param2})
else else
state = 1
minetest.sound_play("doors_door_open", {pos = pos, gain = 0.3, max_hear_distance = 10}) minetest.sound_play("doors_door_open", {pos = pos, gain = 0.3, max_hear_distance = 10})
tmp_node = {name="doors:trapdoor_open", param1=me.param1, param2=me.param2} minetest.set_node(pos, {name="doors:trapdoor_open", param2 = node.param2})
end end
minetest.set_node(pos, tmp_node)
meta:set_int("state", state) minetest.get_meta(pos):set_int("state", state == 1 and 0 or 1)
end end
minetest.override_item("doors:trapdoor", { minetest.override_item("doors:trapdoor", {
mesecons = {effector = { mesecons = {effector = {
action_on = function(pos) action_on = trapdoor_switch,
punch(pos) action_off = trapdoor_switch
end,
rules = mesecon.rules.pplate
}}, }},
}) })
minetest.override_item("doors:trapdoor_open", { minetest.override_item("doors:trapdoor_open", {
mesecons = {effector = { mesecons = {effector = {
action_off = function(pos) action_on = trapdoor_switch,
punch(pos) action_off = trapdoor_switch
end,
rules = mesecon.rules.pplate
}}, }},
}) })