1 -- |\ /| ____ ____ ____ _____ ____ _____
2 -- | \ / | | | | | | | |\ | |
3 -- | \/ | |___ ____ |___ | | | | \ | |____
4 -- | | | | | | | | | \ | |
5 -- | | |___ ____| |___ |____ |____| | \| ____|
6 -- by Jeija, Uberi (Temperest), sfan5, VanessaE, Hawk777 and contributors
10 -- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest.
11 -- See the documentation on the forum for additional information, especially about crafting
14 -- For basic development resources, see http://mesecons.net/developers.html
18 --Quick draft for the mesecons array in the node's definition
23 -- state = mesecon.state.on/off
24 -- rules = rules/get_rules
28 -- action_on = function
29 -- action_off = function
30 -- action_change = function
31 -- rules = rules/get_rules
35 -- state = mesecon.state.on/off
36 -- offstate = opposite state (for state = on only)
37 -- onstate = opposite state (for state = off only)
38 -- rules = rules/get_rules
43 mesecon
={} -- contains all functions and all global variables
44 mesecon
.queue
={} -- contains the ActionQueue
45 mesecon
.queue
.funcs
={} -- contains all ActionQueue functions
48 dofile(minetest
.get_modpath("mesecons").."/settings.lua")
50 -- Utilities like comparing positions,
51 -- adding positions and rules,
52 -- mostly things that make the source look cleaner
53 dofile(minetest
.get_modpath("mesecons").."/util.lua");
55 -- Presets (eg default rules)
56 dofile(minetest
.get_modpath("mesecons").."/presets.lua");
59 -- Saves all the actions that have to be execute in the future
60 dofile(minetest
.get_modpath("mesecons").."/actionqueue.lua");
63 -- This is the most important file
64 -- it handles signal transmission and basically everything else
65 -- It is also responsible for managing the nodedef things,
66 -- like calling action_on/off/change
67 dofile(minetest
.get_modpath("mesecons").."/internal.lua");
70 -- these are the only functions you need to remember
72 mesecon
.queue
:add_function("receptor_on", function (pos
, rules
)
75 rules
= rules
or mesecon
.rules
.default
77 -- Call turnon on all linking positions
78 for _
, rule
in ipairs(mesecon
.flattenrules(rules
)) do
79 local np
= vector
.add(pos
, rule
)
80 local rulenames
= mesecon
.rules_link_rule_all(pos
, rule
)
81 for _
, rulename
in ipairs(rulenames
) do
82 mesecon
.turnon(np
, rulename
)
85 if minetest
.get_item_group(minetest
.get_node(np
).name
, "opaque") == 1 then
86 for _
, neighbor
in ipairs(mesecon
.mcl_get_neighbors(np
)) do
87 mesecon
.turnon(neighbor
.pos
, vector
.add(rule
, neighbor
.link
))
96 function mesecon
.receptor_on(pos
, rules
)
97 mesecon
.queue
:add_action(pos
, "receptor_on", {rules
}, nil, rules
)
100 mesecon
.queue
:add_function("receptor_off", function (pos
, rules
)
101 rules
= rules
or mesecon
.rules
.default
103 -- Call turnoff on all linking positions
104 for _
, rule
in ipairs(mesecon
.flattenrules(rules
)) do
105 local np
= vector
.add(pos
, rule
)
106 local rulenames
= mesecon
.rules_link_rule_all(pos
, rule
)
107 for _
, rulename
in ipairs(rulenames
) do
109 mesecon
.changesignal(np
, minetest
.get_node(np
), rulename
, mesecon
.state
.off
, 2)
111 -- Turnoff returns true if turnoff process was successful, no onstate receptor
112 -- was found along the way. Commit changes that were made in voxelmanip. If turnoff
113 -- returns true, an onstate receptor was found, abort voxelmanip transaction.
114 if (mesecon
.turnoff(np
, rulename
)) then
121 if minetest
.get_item_group(minetest
.get_node(np
).name
, "opaque") == 1 then
122 for _
, neighbor
in ipairs(mesecon
.mcl_get_neighbors(np
)) do
124 mesecon
.changesignal(neighbor
.pos
, minetest
.get_node(neighbor
.pos
), vector
.add(rule
, neighbor
.link
), mesecon
.state
.off
, 2)
125 if (mesecon
.turnoff(neighbor
.pos
, vector
.add(rule
, neighbor
.link
))) then
136 function mesecon
.receptor_off(pos
, rules
)
137 mesecon
.queue
:add_action(pos
, "receptor_off", {rules
}, nil, rules
)
141 print("[OK] Mesecons")
143 --Services like turnoff receptor on dignode and so on
144 dofile(minetest
.get_modpath("mesecons").."/services.lua");