diff --git a/mesecons/init.lua b/mesecons/init.lua index e796691..78b84d9 100644 --- a/mesecons/init.lua +++ b/mesecons/init.lua @@ -88,6 +88,7 @@ mesecon.actions_off={} -- Saves registered function callbacks for mesecon off mesecon.actions_change={} -- Saves registered function callbacks for mesecon change mesecon.pwr_srcs={} mesecon.pwr_srcs_off={} +mesecon.effectors={} mesecon.rules={} mesecon.conductors={} @@ -135,7 +136,21 @@ function mesecon:receptor_on(pos, rules) end function mesecon:receptor_off(pos, rules) - mesecon:turnoff(pos, 0, 0, 0, true, rules) + if rules == nil then + rules = mesecon:get_rules("default") + end + + local i = 1 + while rules[i]~=nil do + local np = {} + np.x = pos.x + rules[i].x + np.y = pos.y + rules[i].y + np.z = pos.z + rules[i].z + if mesecon:connected_to_pw_src(np, 0, 0, 0, {}) == false then + mesecon:turnoff(np) + end + i=i+1 + end end function mesecon:register_on_signal_on(action) diff --git a/mesecons/internal_api.lua b/mesecons/internal_api.lua index f2b097a..a3d8639 100644 --- a/mesecons/internal_api.lua +++ b/mesecons/internal_api.lua @@ -161,7 +161,6 @@ function mesecon:is_conductor_off(name) return false end - --Rules rotation Functions: function mesecon:rotate_rules_right(rules) local i=1 @@ -257,49 +256,38 @@ function mesecon:turnon(p, x, y, z, firstcall, rules) end end -function mesecon:turnoff(pos, x, y, z, firstcall, rules) - if rules==nil then - rules=mesecon:get_rules("default") - end - local lpos = {} - lpos.x=pos.x+x - lpos.y=pos.y+y - lpos.z=pos.z+z - - local node = minetest.env:get_node(lpos) +function mesecon:turnoff(pos) + local node = minetest.env:get_node(pos) local connected = 0 - local checked = {} - --Send Signals to effectors: - mesecon:changesignal(lpos) - if not mesecon:check_if_turnon(lpos) then - mesecon:deactivate(lpos) - end - - if not(firstcall) and connected==0 then - connected=mesecon:connected_to_pw_src(lpos, 0, 0, 0, checked) - end - - if connected == 0 and mesecon:is_conductor_on(node.name) then - --minetest.env:remove_node(lpos) - minetest.env:add_node(lpos, {name=mesecon:get_conductor_off(node.name)}) - nodeupdate(lpos) + if minetest.get_item_group(node.name, "mesecon_effector_on") == 1 then + if not mesecon:check_if_turnon(pos) then --Check if the signal comes from another source + --Send Signals to effectors: + mesecon:deactivate(pos) + end + mesecon:changesignal(pos) --Changesignal is always thrown because nodes can be both receptors and effectors end - if mesecon:is_conductor_on(node.name) or firstcall then - if connected == 0 then - local i=1 - while rules[i]~=nil do - mesecon:turnoff(lpos, rules[i].x, rules[i].y, rules[i].z, false) - i=i+1 - end + if mesecon:is_conductor_on(node.name) then + minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name)}) + nodeupdate(pos) + + rules = mesecon:get_rules("default") + local i=1 + while rules[i]~=nil do + local np = {} + np.x = pos.x + rules[i].x + np.y = pos.y + rules[i].y + np.z = pos.z + rules[i].z + mesecon:turnoff(np) + i=i+1 end end end -function mesecon:connected_to_pw_src(pos, x, y, z, checked, firstcall) +function mesecon:connected_to_pw_src(pos, x, y, z, checked) local i=1 local lpos = {} @@ -315,7 +303,7 @@ function mesecon:connected_to_pw_src(pos, x, y, z, checked, firstcall) i=i+1 if checked[i]==nil then checked[i]={} break end if checked[i].x==lpos.x and checked[i].y==lpos.y and checked[i].z==lpos.z then - return 0 + return false end until false @@ -324,23 +312,19 @@ function mesecon:connected_to_pw_src(pos, x, y, z, checked, firstcall) checked[i].z=lpos.z if mesecon:is_receptor_node(node.name, lpos, pos) == true then -- receptor nodes (power sources) can be added using mesecon:add_receptor_node - return 1 + return true end - if mesecon:is_conductor_on(node.name) or firstcall then -- add other conductors here - local pw_source_found=0 + if mesecon:is_conductor_on(node.name) then local rules=mesecon:get_rules("default") local i=1 while rules[i]~=nil do - pw_source_found=pw_source_found+mesecon:connected_to_pw_src(lpos, rules[i].x, rules[i].y, rules[i].z, checked, false) + if mesecon:connected_to_pw_src(lpos, rules[i].x, rules[i].y, rules[i].z, checked) == true then return true end i=i+1 end - if pw_source_found > 0 then - return 1 - end end end - return 0 + return false end function mesecon:check_if_turnon(pos) @@ -378,7 +362,7 @@ function mesecon:updatenode(pos) if mesecon:connected_to_pw_src(pos, 0, 0, 0, {}) then mesecon:turnon(pos, 0, 0, 0) else - mesecon:turnoff(pos, 0, 0, 0) + mesecon:turnoff(pos) end end @@ -396,7 +380,9 @@ end) minetest.register_on_dignode( function(pos, oldnode, digger) if mesecon:is_conductor_on(oldnode.name) then - mesecon:turnoff(pos, 0, 0, 0, true) + local i = 1 + + mesecon:receptor_off(pos) end end ) diff --git a/mesecons_battery/init.lua b/mesecons_battery/init.lua index 655442b..b5e50a9 100644 --- a/mesecons_battery/init.lua +++ b/mesecons_battery/init.lua @@ -19,7 +19,7 @@ for i = 1, 5 do type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, }, - groups = {dig_immediate=2, mesecon = 2}, + groups = {dig_immediate=2, mesecon = 2, mesecon_effector_on = 1}, description="Battery", }) mesecon:add_receptor_node_off("mesecons_battery:battery_charging_"..i) @@ -46,7 +46,7 @@ for i = 1, 5 do type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, }, - groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2}, + groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 2, mesecon_effector_off = 1}, description="Battery", }) mesecon:add_receptor_node("mesecons_battery:battery_discharging_"..i) diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua index cb6d0af..5089795 100644 --- a/mesecons_delayer/init.lua +++ b/mesecons_delayer/init.lua @@ -1,9 +1,9 @@ for i = 1, 4 do local groups = {} if i == 1 then - groups = {bendy=2,snappy=1,dig_immediate=2, mesecon = 2} + groups = {bendy=2,snappy=1,dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2} else - groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1, mesecon = 2} + groups = {bendy=2,snappy=1,dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, not_in_creative_inventory=1, mesecon = 2} end boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab diff --git a/mesecons_lamp/init.lua b/mesecons_lamp/init.lua index 21a6882..d086ae2 100644 --- a/mesecons_lamp/init.lua +++ b/mesecons_lamp/init.lua @@ -20,7 +20,7 @@ minetest.register_node("mesecons_lamp:lamp_on", { wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125}, wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125}, }, - groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon = 2}, + groups = {dig_immediate=3,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon = 2}, drop='"mesecons_lamp:lamp_off" 1', }) @@ -45,7 +45,7 @@ minetest.register_node("mesecons_lamp:lamp_off", { wall_bottom = {-0.3125,-0.5,-0.3125,0.3125,-0.375,0.3125}, wall_side = {-0.375,-0.3125,-0.3125,-0.5,0.3125,0.3125}, }, - groups = {dig_immediate=3, mesecon = 2}, + groups = {dig_immediate=3, mesecon_receptor_off = 1, mesecon = 2}, description="Meselamp", }) diff --git a/mesecons_lightstone/init.lua b/mesecons_lightstone/init.lua index 4fdf275..55c3394 100644 --- a/mesecons_lightstone/init.lua +++ b/mesecons_lightstone/init.lua @@ -2,13 +2,13 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on) minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_off", { tile_images = {texture_off}, inventory_image = minetest.inventorycube(texture_off), - groups = {cracky=2, mesecon = 2}, + groups = {cracky=2, mesecon_effector_off = 1, mesecon = 2}, description=name.." Lightstone", }) minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", { tile_images = {texture_on}, inventory_image = minetest.inventorycube(texture_on), - groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2}, + groups = {cracky=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon = 2}, drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1", light_source = LIGHT_MAX-2, description=name.." Lightstone", diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua index 1b0f5ee..d76c85f 100644 --- a/mesecons_microcontroller/init.lua +++ b/mesecons_microcontroller/init.lua @@ -6,9 +6,9 @@ for c = 0, 1 do for d = 0, 1 do local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a) if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then - groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 2} + groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2} else - groups = {dig_immediate=2, mesecon = 2} + groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2} end minetest.register_node(nodename, { description = "Microcontroller", diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua index 0cf0010..9e40be1 100644 --- a/mesecons_movestones/init.lua +++ b/mesecons_movestones/init.lua @@ -39,7 +39,7 @@ minetest.register_node("mesecons_movestones:movestone", { tile_images = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"}, paramtype2 = "facedir", legacy_facedir_simple = true, - groups = {cracky=3}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1}, description="Movestone", }) @@ -116,7 +116,7 @@ minetest.register_node("mesecons_movestones:sticky_movestone", { inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"), paramtype2 = "facedir", legacy_facedir_simple = true, - groups = {cracky=3}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1}, description="Sticky Movestone", }) diff --git a/mesecons_noteblock/init.lua b/mesecons_noteblock/init.lua index ddd1f82..09e3b8c 100644 --- a/mesecons_noteblock/init.lua +++ b/mesecons_noteblock/init.lua @@ -1,7 +1,7 @@ minetest.register_node("mesecons_noteblock:noteblock", { description = "Noteblock", tile_images = {"mesecons_noteblock.png"}, - groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2}, + groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_effector_off = 1, mesecon = 2}, drawtype = "allfaces_optional", visual_scale = 1.3, paramtype="light", diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 7e0b984..1c0a8a8 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -3,7 +3,7 @@ minetest.register_node("mesecons_pistons:piston_normal", { description = "Piston", tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"}, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, paramtype2 = "facedir", after_dig_node = function(pos, oldnode) local dir = mesecon:piston_get_direction(oldnode) @@ -23,7 +23,7 @@ minetest.register_node("mesecons_pistons:piston_normal", { minetest.register_node("mesecons_pistons:piston_sticky", { description = "Sticky Piston", tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"}, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, paramtype2 = "facedir", after_dig_node = function(pos, oldnode) local dir = mesecon:piston_get_direction(oldnode) diff --git a/mesecons_pistons/pistons_down.lua b/mesecons_pistons/pistons_down.lua index 1df60df..82bb3f4 100644 --- a/mesecons_pistons/pistons_down.lua +++ b/mesecons_pistons/pistons_down.lua @@ -3,7 +3,7 @@ minetest.register_node("mesecons_pistons:piston_down_normal", { description = "Piston DOWN", tiles = {"jeija_piston_tb.png", "jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"}, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, after_dig_node = function(pos, oldnode) local dir = {x=0, y=-1, z=0} pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check @@ -22,7 +22,7 @@ minetest.register_node("mesecons_pistons:piston_down_normal", { minetest.register_node("mesecons_pistons:piston_down_sticky", { description = "Sticky Piston DOWN", tiles = {"jeija_piston_tb.png", "jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"}, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, after_dig_node = function(pos, oldnode) local dir = {x=0, y=-1, z=0} pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check diff --git a/mesecons_pistons/pistons_up.lua b/mesecons_pistons/pistons_up.lua index 68dee16..1d116ca 100644 --- a/mesecons_pistons/pistons_up.lua +++ b/mesecons_pistons/pistons_up.lua @@ -3,7 +3,7 @@ minetest.register_node("mesecons_pistons:piston_up_normal", { description = "Piston UP", tiles = {"jeija_piston_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"}, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, after_dig_node = function(pos, oldnode) local dir = {x=0, y=1, z=0} pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check @@ -22,7 +22,7 @@ minetest.register_node("mesecons_pistons:piston_up_normal", { minetest.register_node("mesecons_pistons:piston_up_sticky", { description = "Sticky Piston UP", tiles = {"jeija_piston_sticky_side.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png"}, - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, after_dig_node = function(pos, oldnode) local dir = {x=0, y=1, z=0} pos.x, pos.y, pos.z = pos.x + dir.x, pos.y + dir.y, pos.z + dir.z --move to first node to check diff --git a/mesecons_random/init.lua b/mesecons_random/init.lua index be0ab19..d60b871 100644 --- a/mesecons_random/init.lua +++ b/mesecons_random/init.lua @@ -4,7 +4,7 @@ minetest.register_node("mesecons_random:removestone", { tile_images = {"jeija_removestone.png"}, inventory_image = minetest.inventorycube("jeija_removestone_inv.png"), material = minetest.digprop_stonelike(1.0), - groups = {cracky=3, mesecon = 2}, + groups = {cracky=3, mesecon_effector_off = 1, mesecon = 2}, description="Removestone", }) diff --git a/mesecons_temperest/init.lua b/mesecons_temperest/init.lua index f087ad4..05c7bc8 100644 --- a/mesecons_temperest/init.lua +++ b/mesecons_temperest/init.lua @@ -105,7 +105,7 @@ minetest.register_node("mesecons_temperest:mesecon_plug", { tile_images = {"jeija_mesecon_plug.png"}, inventory_image = "jeija_mesecon_plug.png", wield_image = "jeija_mesecon_plug.png", - groups = {dig_immediate=2, mesecon = 2}, + groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, walkable = false, selection_box = { type = "fixed", @@ -139,7 +139,7 @@ minetest.register_node("mesecons_temperest:mesecon_socket_off", { tile_images = {"jeija_mesecon_socket_off.png"}, inventory_image = "jeija_mesecon_socket_off.png", wield_image = "jeija_mesecon_socket_off.png", - groups = {dig_immediate=2, mesecon = 2}, + groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, walkable = false, selection_box = { type = "fixed", @@ -156,7 +156,7 @@ minetest.register_node("mesecons_temperest:mesecon_socket_on", { paramtype = "light", is_ground_content = true, tile_images = {"jeija_mesecon_socket_on.png"}, - groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2}, + groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, walkable = false, selection_box = { type = "fixed", @@ -191,7 +191,7 @@ if ENABLE_TEMPEREST then paramtype = "light", is_ground_content = true, tile_images = {"jeija_mesecon_inverter_off.png"}, - groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 2}, + groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, walkable = false, selection_box = { type = "fixed", @@ -212,7 +212,7 @@ if ENABLE_TEMPEREST then tile_images = {"jeija_mesecon_inverter_on.png"}, inventory_image = "jeija_mesecon_inverter_on.png", wield_image = "jeija_mesecon_inverter_on.png", - groups = {dig_immediate=2, mesecon = 2}, + groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2}, walkable = false, selection_box = { type = "fixed",