2012-03-05 19:21:26 +01:00
|
|
|
-- |\ /| ____ ____ ____ _____ ____ _____
|
|
|
|
-- | \ / | | | | | | | |\ | |
|
|
|
|
-- | \/ | |___ ____ |___ | | | | \ | |____
|
|
|
|
-- | | | | | | | | | \ | |
|
|
|
|
-- | | |___ ____| |___ |____ |____| | \| ____|
|
2012-12-08 21:56:09 +01:00
|
|
|
-- by Jeija, Uberi (Temperest), sfan5, VanessaE
|
2012-03-05 19:21:26 +01:00
|
|
|
--
|
|
|
|
--
|
|
|
|
--
|
|
|
|
-- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest.
|
|
|
|
-- See the documentation on the forum for additional information, especially about crafting
|
|
|
|
--
|
2012-12-08 21:56:09 +01:00
|
|
|
--
|
|
|
|
-- For developer documentation see the Developers' section on mesecons.TK
|
|
|
|
--
|
|
|
|
--
|
|
|
|
--
|
|
|
|
--Quick draft for the mesecons array in the node's definition
|
|
|
|
--mesecons =
|
|
|
|
--{
|
|
|
|
-- receptor =
|
|
|
|
-- {
|
|
|
|
-- state = mesecon.state.on/off
|
|
|
|
-- rules = rules/get_rules
|
2012-12-15 18:45:51 +01:00
|
|
|
-- },
|
2012-12-08 21:56:09 +01:00
|
|
|
-- effector =
|
|
|
|
-- {
|
|
|
|
-- action_on = function
|
|
|
|
-- action_off = function
|
|
|
|
-- action_change = function
|
|
|
|
-- rules = rules/get_rules
|
2012-12-15 18:45:51 +01:00
|
|
|
-- },
|
2012-12-08 21:56:09 +01:00
|
|
|
-- conductor =
|
|
|
|
-- {
|
|
|
|
-- state = mesecon.state.on/off
|
|
|
|
-- offstate = opposite state (for state = on only)
|
|
|
|
-- onstate = opposite state (for state = off only)
|
|
|
|
-- rules = rules/get_rules
|
|
|
|
-- }
|
|
|
|
--}
|
2012-03-05 19:21:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
-- PUBLIC VARIABLES
|
|
|
|
mesecon={} -- contains all functions and all global variables
|
2012-12-08 21:56:09 +01:00
|
|
|
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on | DEPRECATED
|
|
|
|
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off | DEPRECATED
|
|
|
|
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change | DEPRECATED
|
|
|
|
mesecon.receptors={} -- saves all information about receptors | DEPRECATED
|
|
|
|
mesecon.effectors={} -- saves all information about effectors | DEPRECATED
|
|
|
|
mesecon.conductors={} -- saves all information about conductors | DEPRECATED
|
|
|
|
|
|
|
|
-- Settings
|
2012-08-11 22:58:00 +02:00
|
|
|
dofile(minetest.get_modpath("mesecons").."/settings.lua")
|
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
-- Presets (eg default rules)
|
2012-12-08 14:14:04 +01:00
|
|
|
dofile(minetest.get_modpath("mesecons").."/presets.lua");
|
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
|
|
|
|
-- Utilities like comparing positions,
|
|
|
|
-- adding positions and rules,
|
|
|
|
-- mostly things that make the source look cleaner
|
|
|
|
dofile(minetest.get_modpath("mesecons").."/util.lua");
|
|
|
|
|
|
|
|
-- Internal stuff
|
|
|
|
-- This is the most important file
|
|
|
|
-- it handles signal transmission and basically everything else
|
|
|
|
-- It is also responsible for managing the nodedef things,
|
|
|
|
-- like calling action_on/off/change
|
2012-08-13 11:58:04 +02:00
|
|
|
dofile(minetest.get_modpath("mesecons").."/internal.lua");
|
2012-04-22 07:48:45 +02:00
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
-- Deprecated stuff
|
|
|
|
-- To be removed in future releases
|
2012-12-08 14:14:04 +01:00
|
|
|
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
-- API
|
|
|
|
-- these are the only functions you need to remember
|
|
|
|
|
|
|
|
function mesecon:receptor_on(pos, rules)
|
|
|
|
rules = rules or mesecon.rules.default
|
|
|
|
|
|
|
|
for _, rule in ipairs(rules) do
|
2012-12-16 16:29:03 +01:00
|
|
|
local np = mesecon:addPosRule(pos, rule)
|
2012-12-19 17:34:05 +01:00
|
|
|
local link, rulename = mesecon:rules_link(pos, np, rules)
|
|
|
|
if link then
|
|
|
|
mesecon:turnon(np, rulename)
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
function mesecon:receptor_off(pos, rules)
|
|
|
|
rules = rules or mesecon.rules.default
|
2012-03-29 22:11:17 +02:00
|
|
|
|
2012-12-08 21:56:09 +01:00
|
|
|
for _, rule in ipairs(rules) do
|
2012-12-16 16:29:03 +01:00
|
|
|
local np = mesecon:addPosRule(pos, rule)
|
2012-12-19 17:34:05 +01:00
|
|
|
local link, rulename = mesecon:rules_link(pos, np, rules)
|
2012-12-21 16:04:19 +01:00
|
|
|
if link and not mesecon:connected_to_receptor(np) then
|
2012-12-19 17:34:05 +01:00
|
|
|
mesecon:turnoff(np, rulename)
|
2012-12-08 21:56:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-08-10 18:58:21 +02:00
|
|
|
|
2012-03-29 11:35:23 +02:00
|
|
|
|
2012-12-08 14:14:04 +01:00
|
|
|
print("[OK] mesecons")
|
2012-03-05 19:21:26 +01:00
|
|
|
|
2012-08-11 22:58:00 +02:00
|
|
|
--The actual wires
|
|
|
|
dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
2012-08-13 08:50:10 +02:00
|
|
|
|
|
|
|
--Services like turnoff receptor on dignode and so on
|
|
|
|
dofile(minetest.get_modpath("mesecons").."/services.lua");
|