2015-01-22 17:27:29 +01:00
|
|
|
-- Modified, from minetest_game/mods/doors/init.lua
|
|
|
|
local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
|
|
|
|
pos.y = pos.y + dir
|
2022-03-30 21:41:51 +02:00
|
|
|
if minetest.get_node(pos).name ~= check_name then
|
2015-01-22 17:27:29 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local p2 = minetest.get_node(pos).param2
|
|
|
|
p2 = params[p2 + 1]
|
2015-02-03 01:20:44 +01:00
|
|
|
|
2015-01-22 17:27:29 +01:00
|
|
|
minetest.swap_node(pos, {name = replace_dir, param2 = p2})
|
2015-02-03 01:20:44 +01:00
|
|
|
|
2015-01-22 17:27:29 +01:00
|
|
|
pos.y = pos.y - dir
|
|
|
|
minetest.swap_node(pos, {name = replace, param2 = p2})
|
|
|
|
|
|
|
|
if (minetest.get_meta(pos):get_int("right") ~= 0) == (params[1] ~= 3) then
|
2020-08-01 15:10:14 +02:00
|
|
|
minetest.sound_play("doors_door_close", { pos = pos, gain = 0.3, max_hear_distance = 10 }, true)
|
2015-01-22 17:27:29 +01:00
|
|
|
else
|
2020-08-01 15:10:14 +02:00
|
|
|
minetest.sound_play("doors_door_open", { pos = pos, gain = 0.3, max_hear_distance = 10 }, true)
|
2015-01-22 17:27:29 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function meseconify_door(name)
|
2016-01-25 00:34:14 +01:00
|
|
|
if minetest.registered_items[name .. "_b_1"] then
|
|
|
|
-- old style double-node doors
|
2022-02-12 20:12:12 +01:00
|
|
|
local function toggle_state1 (pos)
|
2016-01-25 00:34:14 +01:00
|
|
|
on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
|
|
|
|
end
|
2015-02-14 00:02:19 +01:00
|
|
|
|
2022-02-12 20:12:12 +01:00
|
|
|
local function toggle_state2 (pos)
|
2016-01-25 00:34:14 +01:00
|
|
|
on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
|
|
|
|
end
|
2015-01-22 17:27:29 +01:00
|
|
|
|
2016-01-25 00:34:14 +01:00
|
|
|
minetest.override_item(name.."_b_1", {
|
|
|
|
mesecons = {effector = {
|
|
|
|
action_on = toggle_state1,
|
|
|
|
action_off = toggle_state1,
|
|
|
|
rules = mesecon.rules.pplate
|
|
|
|
}}
|
|
|
|
})
|
2015-01-22 17:27:29 +01:00
|
|
|
|
2016-01-25 00:34:14 +01:00
|
|
|
minetest.override_item(name.."_b_2", {
|
|
|
|
mesecons = {effector = {
|
|
|
|
action_on = toggle_state2,
|
|
|
|
action_off = toggle_state2,
|
|
|
|
rules = mesecon.rules.pplate
|
|
|
|
}}
|
|
|
|
})
|
|
|
|
elseif minetest.registered_items[name .. "_a"] then
|
|
|
|
-- new style mesh node based doors
|
|
|
|
local override = {
|
|
|
|
mesecons = {effector = {
|
2022-02-12 20:12:12 +01:00
|
|
|
action_on = function(pos)
|
2016-01-25 00:34:14 +01:00
|
|
|
local door = doors.get(pos)
|
|
|
|
if door then
|
|
|
|
door:open()
|
|
|
|
end
|
|
|
|
end,
|
2022-02-12 20:12:12 +01:00
|
|
|
action_off = function(pos)
|
2016-01-25 00:34:14 +01:00
|
|
|
local door = doors.get(pos)
|
|
|
|
if door then
|
|
|
|
door:close()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
rules = mesecon.rules.pplate
|
|
|
|
}}
|
|
|
|
}
|
|
|
|
minetest.override_item(name .. "_a", override)
|
|
|
|
minetest.override_item(name .. "_b", override)
|
2022-04-01 23:27:35 +02:00
|
|
|
if minetest.registered_items[name .. "_c"] then
|
|
|
|
minetest.override_item(name .. "_c", override)
|
|
|
|
minetest.override_item(name .. "_d", override)
|
|
|
|
end
|
2016-01-25 00:34:14 +01:00
|
|
|
end
|
2015-01-22 17:27:29 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
meseconify_door("doors:door_wood")
|
|
|
|
meseconify_door("doors:door_steel")
|
|
|
|
meseconify_door("doors:door_glass")
|
|
|
|
meseconify_door("doors:door_obsidian_glass")
|
2020-09-18 23:27:47 +02:00
|
|
|
meseconify_door("xpanes:door_steel_bar")
|
2015-02-03 01:20:44 +01:00
|
|
|
|
|
|
|
-- Trapdoor
|
2015-02-03 18:10:49 +01:00
|
|
|
local function trapdoor_switch(pos, node)
|
|
|
|
local state = minetest.get_meta(pos):get_int("state")
|
|
|
|
|
2015-02-03 01:20:44 +01:00
|
|
|
if state == 1 then
|
2020-08-01 15:10:14 +02:00
|
|
|
minetest.sound_play("doors_door_close", { pos = pos, gain = 0.3, max_hear_distance = 10 }, true)
|
2015-02-03 18:10:49 +01:00
|
|
|
minetest.set_node(pos, {name="doors:trapdoor", param2 = node.param2})
|
2015-02-03 01:20:44 +01:00
|
|
|
else
|
2020-08-01 15:10:14 +02:00
|
|
|
minetest.sound_play("doors_door_open", { pos = pos, gain = 0.3, max_hear_distance = 10 }, true)
|
2015-02-03 18:10:49 +01:00
|
|
|
minetest.set_node(pos, {name="doors:trapdoor_open", param2 = node.param2})
|
2015-02-03 01:20:44 +01:00
|
|
|
end
|
2015-02-03 18:10:49 +01:00
|
|
|
|
|
|
|
minetest.get_meta(pos):set_int("state", state == 1 and 0 or 1)
|
2015-02-03 01:20:44 +01:00
|
|
|
end
|
|
|
|
|
2016-01-25 00:34:14 +01:00
|
|
|
if doors and doors.get then
|
|
|
|
local override = {
|
2015-02-14 00:02:19 +01:00
|
|
|
mesecons = {effector = {
|
2022-02-12 20:12:12 +01:00
|
|
|
action_on = function(pos)
|
2016-01-25 00:34:14 +01:00
|
|
|
local door = doors.get(pos)
|
|
|
|
if door then
|
2016-02-28 07:16:45 +01:00
|
|
|
door:open()
|
2016-01-25 00:34:14 +01:00
|
|
|
end
|
|
|
|
end,
|
2022-02-12 20:12:12 +01:00
|
|
|
action_off = function(pos)
|
2016-01-25 00:34:14 +01:00
|
|
|
local door = doors.get(pos)
|
|
|
|
if door then
|
2016-02-28 07:16:45 +01:00
|
|
|
door:close()
|
2016-01-25 00:34:14 +01:00
|
|
|
end
|
|
|
|
end,
|
2015-02-14 00:02:19 +01:00
|
|
|
}},
|
2016-01-25 00:34:14 +01:00
|
|
|
}
|
|
|
|
minetest.override_item("doors:trapdoor", override)
|
|
|
|
minetest.override_item("doors:trapdoor_open", override)
|
|
|
|
minetest.override_item("doors:trapdoor_steel", override)
|
|
|
|
minetest.override_item("doors:trapdoor_steel_open", override)
|
2020-09-18 23:27:47 +02:00
|
|
|
|
|
|
|
if minetest.registered_items["xpanes:trapdoor_steel_bar"] then
|
|
|
|
minetest.override_item("xpanes:trapdoor_steel_bar", override)
|
|
|
|
minetest.override_item("xpanes:trapdoor_steel_bar_open", override)
|
|
|
|
end
|
|
|
|
|
2016-01-25 00:34:14 +01:00
|
|
|
else
|
|
|
|
if minetest.registered_nodes["doors:trapdoor"] then
|
|
|
|
minetest.override_item("doors:trapdoor", {
|
|
|
|
mesecons = {effector = {
|
|
|
|
action_on = trapdoor_switch,
|
|
|
|
action_off = trapdoor_switch
|
|
|
|
}},
|
|
|
|
})
|
2015-02-03 01:20:44 +01:00
|
|
|
|
2016-01-25 00:34:14 +01:00
|
|
|
minetest.override_item("doors:trapdoor_open", {
|
|
|
|
mesecons = {effector = {
|
|
|
|
action_on = trapdoor_switch,
|
|
|
|
action_off = trapdoor_switch
|
|
|
|
}},
|
|
|
|
})
|
|
|
|
end
|
2015-02-14 00:02:19 +01:00
|
|
|
end
|