summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesecons/internal.lua84
-rw-r--r--mesecons/wires.lua11
-rw-r--r--mesecons_luacontroller/init.lua31
-rw-r--r--mesecons_movestones/init.lua25
-rw-r--r--mesecons_switch/init.lua3
5 files changed, 74 insertions, 80 deletions
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index 1072aa8..7d598f0 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -1,50 +1,50 @@
-- Internal.lua - The core of mesecons
--
--- For more practical developer resources see mesecons.tk
+-- For more practical developer resources see http://mesecons.net/developers.php
--
-- Function overview
--- mesecon.get_effector(nodename) --> Returns the mesecons.effector -specifictation in the nodedef by the nodename
--- mesecon.get_receptor(nodename) --> Returns the mesecons.receptor -specifictation in the nodedef by the nodename
--- mesecon.get_conductor(nodename) --> Returns the mesecons.conductor-specifictation in the nodedef by the nodename
--- mesecon.get_any_inputrules (node) --> Returns the rules of a node if it is a conductor or an effector
--- mesecon.get_any_outputrules (node) --> Returns the rules of a node if it is a conductor or a receptor
+-- mesecon.get_effector(nodename) --> Returns the mesecons.effector -specifictation in the nodedef by the nodename
+-- mesecon.get_receptor(nodename) --> Returns the mesecons.receptor -specifictation in the nodedef by the nodename
+-- mesecon.get_conductor(nodename) --> Returns the mesecons.conductor-specifictation in the nodedef by the nodename
+-- mesecon.get_any_inputrules (node) --> Returns the rules of a node if it is a conductor or an effector
+-- mesecon.get_any_outputrules (node) --> Returns the rules of a node if it is a conductor or a receptor
-- RECEPTORS
--- mesecon.is_receptor(nodename) --> Returns true if nodename is a receptor
--- mesecon.is_receptor_on(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.on
--- mesecon.is_receptor_off(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.off
--- mesecon.receptor_get_rules(node) --> Returns the rules of the receptor (mesecon.rules.default if none specified)
+-- mesecon.is_receptor(nodename) --> Returns true if nodename is a receptor
+-- mesecon.is_receptor_on(nodename --> Returns true if nodename is an receptor with state = mesecon.state.on
+-- mesecon.is_receptor_off(nodename) --> Returns true if nodename is an receptor with state = mesecon.state.off
+-- mesecon.receptor_get_rules(node) --> Returns the rules of the receptor (mesecon.rules.default if none specified)
-- EFFECTORS
--- mesecon.is_effector(nodename) --> Returns true if nodename is an effector
--- mesecon.is_effector_on(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_off
--- mesecon.is_effector_off(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_on
--- mesecon.effector_get_rules(node) --> Returns the input rules of the effector (mesecon.rules.default if none specified)
+-- mesecon.is_effector(nodename) --> Returns true if nodename is an effector
+-- mesecon.is_effector_on(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_off
+-- mesecon.is_effector_off(nodename) --> Returns true if nodename is an effector with nodedef.mesecons.effector.action_on
+-- mesecon.effector_get_rules(node) --> Returns the input rules of the effector (mesecon.rules.default if none specified)
-- SIGNALS
--- mesecon.activate(pos, node, depth) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on), higher depths are executed later
--- mesecon.deactivate(pos, node, depth) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off), higher depths are executed later
+-- mesecon.activate(pos, node, depth) --> Activates the effector node at the specific pos (calls nodedef.mesecons.effector.action_on), higher depths are executed later
+-- mesecon.deactivate(pos, node, depth) --> Deactivates the effector node at the specific pos (calls nodedef.mesecons.effector.action_off), higher depths are executed later
-- mesecon.changesignal(pos, node, rulename, newstate, depth) --> Changes the effector node at the specific pos (calls nodedef.mesecons.effector.action_change), higher depths are executed later
-- CONDUCTORS
--- mesecon.is_conductor(nodename) --> Returns true if nodename is a conductor
--- mesecon.is_conductor_on(node) --> Returns true if node is a conductor with state = mesecon.state.on
--- mesecon.is_conductor_off(node) --> Returns true if node is a conductor with state = mesecon.state.off
--- mesecon.get_conductor_on(node_off) --> Returns the onstate nodename of the conductor
--- mesecon.get_conductor_off(node_on) --> Returns the offstate nodename of the conductor
--- mesecon.conductor_get_rules(node) --> Returns the input+output rules of a conductor (mesecon.rules.default if none specified)
+-- mesecon.is_conductor(nodename) --> Returns true if nodename is a conductor
+-- mesecon.is_conductor_on(node --> Returns true if node is a conductor with state = mesecon.state.on
+-- mesecon.is_conductor_off(node) --> Returns true if node is a conductor with state = mesecon.state.off
+-- mesecon.get_conductor_on(node_off) --> Returns the onstate nodename of the conductor
+-- mesecon.get_conductor_off(node_on) --> Returns the offstate nodename of the conductor
+-- mesecon.conductor_get_rules(node) --> Returns the input+output rules of a conductor (mesecon.rules.default if none specified)
-- HIGH-LEVEL Internals
--- mesecon.is_power_on(pos) --> Returns true if pos emits power in any way
--- mesecon.is_power_off(pos) --> Returns true if pos does not emit power in any way
--- mesecon.turnon(pos, rulename) --> Returns true whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnon; Uses third parameter recdepth internally to determine how far away the current node is from the initial pos as it uses recursion
--- mesecon.turnoff(pos, rulename) --> Turns off whatever there is at pos. Calls itself for connected nodes (if pos is a conductor) --> recursive, the rulename is the name of the input rule that caused calling turnoff; Uses third parameter recdepth internally to determine how far away the current node is from the initial pos as it uses recursion
--- mesecon.connected_to_receptor(pos, link) --> Returns true if pos is connected to a receptor directly or via conductors; calls itself if pos is a conductor --> recursive
--- mesecon.rules_link(output, input, dug_outputrules) --> Returns true if outputposition + outputrules = inputposition and inputposition + inputrules = outputposition (if the two positions connect)
--- mesecon.rules_link_anydir(outp., inp., d_outpr.) --> Same as rules mesecon.rules_link but also returns true if output and input are swapped
--- mesecon.is_powered(pos) --> Returns true if pos is powered by a receptor or a conductor
-
--- RULES ROTATION helpsers
+-- mesecon.is_power_on(pos) --> Returns true if pos emits power in any way
+-- mesecon.is_power_off(pos) --> Returns true if pos does not emit power in any way
+-- mesecon.turnon(pos, link) --> link is the input rule that caused calling turnon, turns on every connected node, iterative
+-- mesecon.turnoff(pos, link) --> link is the input rule that caused calling turnoff, turns off every connected node, iterative
+-- mesecon.connected_to_receptor(pos, link) --> Returns true if pos is connected to a receptor directly or via conductors, iterative
+-- mesecon.rules_link(output, input, dug_outputrules) --> Returns true if outputposition + outputrules = inputposition and inputposition + inputrules = outputposition (if the two positions connect)
+-- mesecon.rules_link_anydir(outp., inp., d_outpr.) --> Same as rules mesecon.rules_link but also returns true if output and input are swapped
+-- mesecon.is_powered(pos) --> Returns true if pos is powered by a receptor or a conductor
+
+-- RULES ROTATION helpers
-- mesecon.rotate_rules_right(rules)
-- mesecon.rotate_rules_left(rules)
-- mesecon.rotate_rules_up(rules)
@@ -82,7 +82,6 @@ function mesecon.get_any_outputrules (node)
elseif mesecon.is_receptor(node.name) then
return mesecon.receptor_get_rules(node)
end
- return false
end
function mesecon.get_any_inputrules (node)
@@ -91,7 +90,11 @@ function mesecon.get_any_inputrules (node)
elseif mesecon.is_effector(node.name) then
return mesecon.effector_get_rules(node)
end
- return false
+end
+
+function mesecon.get_any_rules (node)
+ return mesecon.mergetable(mesecon.get_any_inputrules(node) or {},
+ mesecon.get_any_outputrules(node) or {})
end
-- Receptors
@@ -200,8 +203,8 @@ end
-- Deactivation
mesecon.queue:add_function("deactivate", function (pos, rulename)
- node = minetest.get_node(pos)
- effector = mesecon.get_effector(node.name)
+ local node = minetest.get_node(pos)
+ local effector = mesecon.get_effector(node.name)
if effector and effector.action_off then
effector.action_off(pos, node, rulename)
@@ -360,9 +363,7 @@ function mesecon.turnon(pos, link)
-- area not loaded, postpone action
if not node then
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true)
- end
-
- if mesecon.is_conductor_off(node, f.link) then
+ elseif mesecon.is_conductor_off(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
@@ -408,9 +409,7 @@ function mesecon.turnoff(pos, link)
-- area not loaded, postpone action
if not node then
mesecon.queue:add_action(f.pos, "turnoff", {link}, nil, true)
- end
-
- if mesecon.is_conductor_on(node, f.link) then
+ elseif mesecon.is_conductor_on(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
@@ -476,6 +475,7 @@ function mesecon.find_receptor_on(pos, link)
local f = frontiers[depth]
local node = minetest.get_node_or_nil(f.pos)
+ if not node then return false end
if mesecon.is_receptor_on(node.name) then return true end
if mesecon.is_conductor_on(node, f.link) then
local rules = mesecon.conductor_get_rules(node)
diff --git a/mesecons/wires.lua b/mesecons/wires.lua
index 357181f..40c8541 100644
--- a/mesecons/wires.lua
+++ b/mesecons/wires.lua
@@ -18,8 +18,7 @@ local wire_getconnect = function (from_pos, self_pos)
if (minetest.registered_nodes[node.name].mesecon_wire) then
rules = mesecon.rules.default
else
- rules = mesecon.get_any_inputrules(node) or {}
- rules = mesecon.mergetable(mesecon.get_any_outputrules(node) or {}, rules)
+ rules = mesecon.get_any_rules(node)
end
for _, r in ipairs(mesecon.flattenrules(rules)) do
@@ -79,8 +78,7 @@ local update_on_place_dig = function (pos, node)
and minetest.registered_nodes[node.name].mesecon_wire then
rules = mesecon.rules.default
else
- rules = mesecon.get_any_inputrules(node) or {}
- rules = mesecon.mergetable(mesecon.get_any_outputrules(node) or {}, rules)
+ rules = mesecon.get_any_rules(node)
end
if (not rules) then return end
@@ -199,8 +197,9 @@ register_wires = function()
offstate = "mesecons:wire_"..nodeid.."_off"
}}
- local groups_on = {dig_immediate = 3, not_in_creative_inventory = 1}
- local groups_off = {dig_immediate = 3}
+ local groups_on = {dig_immediate = 3, mesecon_conductor_craftable = 1,
+ not_in_creative_inventory = 1}
+ local groups_off = {dig_immediate = 3, mesecon_conductor_craftable = 1}
if nodeid ~= "00000000" then
groups_off["not_in_creative_inventory"] = 1
end
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua
index f6a11f9..2cbebd6 100644
--- a/mesecons_luacontroller/init.lua
+++ b/mesecons_luacontroller/init.lua
@@ -168,19 +168,8 @@ end
-- Parsing and running --
-------------------------
--- Limit printing to prevent flooding
-local print_count = 0
-
local function safe_print(param)
- local to_print = dump(param, "")
- print_count = print_count + 1 + (#to_print / 64)
- for c in to_print:gmatch("\n") do
- print_count = print_count + 1
- end
- if print_count > 8 then
- error("Too much printing!")
- end
- print(to_print)
+ print(dump(param))
end
minetest.register_globalstep(function(dtime)
@@ -210,13 +199,12 @@ local function remove_functions(x)
return x
end
-
local function get_interrupt(pos)
-- iid = interrupt id
local function interrupt(time, iid)
if type(time) ~= "number" then return end
local luac_id = minetest.get_meta(pos):get_int("luac_id")
- mesecon.queue:add_action(pos, "LuaController interrupt", {iid, luac_id}, time, iid, 1)
+ mesecon.queue:add_action(pos, "lc_interrupt", {luac_id, iid}, time, iid, 1)
end
return interrupt
end
@@ -404,6 +392,12 @@ local function run(pos, event)
set_port_states(pos, env.port)
end
+mesecon.queue:add_function("lc_interrupt", function (pos, luac_id, iid)
+ -- There is no luacontroller anymore / it has been reprogrammed / replaced
+ if (minetest.get_meta(pos):get_int("luac_id") ~= luac_id) then return end
+ run(pos, {type="interrupt", iid = iid})
+end)
+
local function reset_meta(pos, code, errmsg)
local meta = minetest.get_meta(pos)
meta:set_string("code", code)
@@ -424,15 +418,6 @@ local function reset(pos)
end
-mesecon.queue:add_function("LuaController interrupt", function(pos, iid, luac_id)
- -- There is no LuaController anymore / it has been reprogrammed / replaced
- if minetest.get_meta(pos):get_int("luac_id") ~= luac_id then
- return
- end
- run(pos, {type="interrupt", iid = iid})
-end)
-
-
-----------------------
-- Node Registration --
-----------------------
diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua
index dcbb00b..7790658 100644
--- a/mesecons_movestones/init.lua
+++ b/mesecons_movestones/init.lua
@@ -67,7 +67,7 @@ minetest.register_node("mesecons_movestones:movestone", {
local direction=mesecon.get_movestone_direction(pos)
if not direction then return end
minetest.remove_node(pos)
- mesecon.update_autoconnect(pos)
+ mesecon.on_dignode(pos, node)
minetest.add_entity(pos, "mesecons_movestones:movestone_entity")
end
}}
@@ -100,16 +100,20 @@ minetest.register_entity("mesecons_movestones:movestone_entity", {
or minetest.registered_nodes[name].liquidtype == "none") then
mesecon.mvps_push(pos, self.lastdir, maxpush)
end
- minetest.add_node(pos, {name="mesecons_movestones:movestone"})
+ local nn = {name="mesecons_movestones:movestone"}
+ minetest.add_node(pos, nn)
self.object:remove()
+ mesecon.on_placenode(pos, nn)
return
end
local success, stack, oldstack =
mesecon.mvps_push(pos, direction, maxpush)
if not success then -- Too large stack/stopper in the way
- minetest.add_node(pos, {name="mesecons_movestones:movestone"})
+ local nn = {name="mesecons_movestones:movestone"}
+ minetest.add_node(pos, nn)
self.object:remove()
+ mesecon.on_placenode(pos, nn)
return
else
mesecon.mvps_process_stack (stack)
@@ -147,7 +151,7 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
local direction=mesecon.get_movestone_direction(pos)
if not direction then return end
minetest.remove_node(pos)
- mesecon.update_autoconnect(pos)
+ mesecon.on_dignode(pos, node)
minetest.add_entity(pos, "mesecons_movestones:sticky_movestone_entity")
end
}}
@@ -184,20 +188,25 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", {
if name ~= "air" and name ~= "ignore"
and ((not minetest.registered_nodes[name])
or minetest.registered_nodes[name].liquidtype == "none") then
- mesecon.mvps_push(pos, self.lastdir, MOVESTONE_MAXIMUM_PUSH)
+ mesecon.mvps_push(pos, self.lastdir,
+ mesecon.setting("movestone_max_push", 50))
--STICKY
mesecon.mvps_pull_all(pos, self.lastdir)
end
- minetest.add_node(pos, {name="mesecons_movestones:sticky_movestone"})
+ local nn = {name="mesecons_movestones:sticky_movestone"}
+ minetest.add_node(pos, nn)
self.object:remove()
+ mesecon.on_placenode(pos, nn)
return
end
local success, stack, oldstack =
- mesecon.mvps_push(pos, direction, MOVESTONE_MAXIMUM_PUSH)
+ mesecon.mvps_push(pos, direction, mesecon.setting("movestone_max_push", 50))
if not success then -- Too large stack/stopper in the way
- minetest.add_node(pos, {name="mesecons_movestones:sticky_movestone"})
+ local nn = {name="mesecons_movestones:sticky_movestone"}
+ minetest.add_node(pos, nn)
self.object:remove()
+ mesecon.on_placenode(pos, nn)
return
else
mesecon.mvps_process_stack (stack)
diff --git a/mesecons_switch/init.lua b/mesecons_switch/init.lua
index 074dc62..2b3c3ee 100644
--- a/mesecons_switch/init.lua
+++ b/mesecons_switch/init.lua
@@ -2,7 +2,6 @@
mesecon.register_node("mesecons_switch:mesecon_switch", {
paramtype2="facedir",
- groups = {dig_immediate=2},
description="Switch",
sounds = default.node_sound_stone_defaults(),
on_punch = function (pos, node)
@@ -14,11 +13,13 @@ mesecon.register_node("mesecons_switch:mesecon_switch", {
minetest.sound_play("mesecons_switch", {pos=pos})
end
},{
+ groups = {dig_immediate=2},
tiles = { "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png",
"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png",
"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_off.png"},
mesecons = {receptor = { state = mesecon.state.off }}
},{
+ groups = {dig_immediate=2, not_in_creative_inventory=1},
tiles = { "jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png",
"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_side.png",
"jeija_mesecon_switch_side.png", "jeija_mesecon_switch_on.png"},