diff options
-rw-r--r-- | mesecons_doors/init.lua | 111 | ||||
-rw-r--r-- | mesecons_mvps/init.lua | 27 |
2 files changed, 91 insertions, 47 deletions
diff --git a/mesecons_doors/init.lua b/mesecons_doors/init.lua index 7346128..52d6c17 100644 --- a/mesecons_doors/init.lua +++ b/mesecons_doors/init.lua @@ -20,31 +20,53 @@ local function on_rightclick(pos, dir, check_name, replace, replace_dir, params) end local function meseconify_door(name) - if not minetest.registered_items[name] then return end + if minetest.registered_items[name .. "_b_1"] then + -- old style double-node doors + local function toggle_state1 (pos, node) + on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) + end - local function toggle_state1 (pos, node) - on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0}) - end - - local function toggle_state2 (pos, node) - on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) - end + local function toggle_state2 (pos, node) + on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2}) + end - minetest.override_item(name.."_b_1", { - mesecons = {effector = { - action_on = toggle_state1, - action_off = toggle_state1, - rules = mesecon.rules.pplate - }}, - }) + minetest.override_item(name.."_b_1", { + mesecons = {effector = { + action_on = toggle_state1, + action_off = toggle_state1, + rules = mesecon.rules.pplate + }} + }) - minetest.override_item(name.."_b_2", { - mesecons = {effector = { - action_on = toggle_state2, - action_off = toggle_state2, - rules = mesecon.rules.pplate - }}, - }) + 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 = { + action_on = function(pos, node) + local door = doors.get(pos) + if door then + door:open() + end + end, + action_off = function(pos, node) + 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) + end end meseconify_door("doors:door_wood") @@ -67,18 +89,41 @@ local function trapdoor_switch(pos, node) minetest.get_meta(pos):set_int("state", state == 1 and 0 or 1) end -if minetest.registered_nodes["doors:trapdoor"] then - minetest.override_item("doors:trapdoor", { +if doors and doors.get then + local override = { mesecons = {effector = { - action_on = trapdoor_switch, - action_off = trapdoor_switch + action_on = function(pos, node) + local door = doors.get(pos) + if door then + door:open() + end + end, + action_off = function(pos, node) + local door = doors.get(pos) + if door then + door:close() + end + end, }}, - }) + } + 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) +else + if minetest.registered_nodes["doors:trapdoor"] then + minetest.override_item("doors:trapdoor", { + mesecons = {effector = { + action_on = trapdoor_switch, + action_off = trapdoor_switch + }}, + }) - minetest.override_item("doors:trapdoor_open", { - mesecons = {effector = { - action_on = trapdoor_switch, - action_off = trapdoor_switch - }}, - }) + minetest.override_item("doors:trapdoor_open", { + mesecons = {effector = { + action_on = trapdoor_switch, + action_off = trapdoor_switch + }}, + }) + end end diff --git a/mesecons_mvps/init.lua b/mesecons_mvps/init.lua index bfbd774..2f4edfc 100644 --- a/mesecons_mvps/init.lua +++ b/mesecons_mvps/init.lua @@ -15,16 +15,16 @@ end -- Nodes that cannot be pushed / pulled by movestones, pistons function mesecon.is_mvps_stopper(node, pushdir, stack, stackid) + -- unknown nodes are always stoppers + if not minetest.registered_nodes[node.name] then + return true + end + local get_stopper = mesecon.mvps_stoppers[node.name] if type (get_stopper) == "function" then get_stopper = get_stopper(node, pushdir, stack, stackid) end - if get_stopper == nil - and not minetest.registered_nodes[node.name] then - -- unknown nodes must be stoppers - mesecon.mvps_stoppers[node.name] = true - get_stopper = true - end + return get_stopper end @@ -53,16 +53,15 @@ function mesecon.mvps_process_stack(stack) end end --- tests if the node can't be pushed -local replaceable_cache = {air = true, ignore = false} +-- tests if the node can be pushed into, e.g. air, water, grass local function node_replaceable(name) - if replaceable_cache[name] ~= nil then - return replaceable_cache[name] + if name == "ignore" then return true end + + if minetest.registered_nodes[name] then + return minetest.registered_nodes[name].buildable_to or false end - --local replaceable = not minetest.registered_nodes[name] or minetest.registered_nodes[name].buildable_to or false - local replaceable = (minetest.registered_nodes[name] and minetest.registered_nodes[name].buildable_to) or false - replaceable_cache[name] = replaceable - return replaceable + + return false end function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky) |