Cleanup, make and use util.lua, port command block and delayer to nodedef

This commit is contained in:
Jeija
2012-12-08 21:56:09 +01:00
parent 8578fd89c8
commit 00e071b695
10 changed files with 364 additions and 351 deletions

View File

@ -3,41 +3,105 @@
-- | \/ | |___ ____ |___ | | | | \ | |____
-- | | | | | | | | | \ | |
-- | | |___ ____| |___ |____ |____| | \| ____|
-- by Jeija, Uberi (Temperest), sfan5, VanessaE,
-- by Jeija, Uberi (Temperest), sfan5, VanessaE
--
--
--
-- This mod adds mesecons[=minecraft redstone] and different receptors/effectors to minetest.
--
-- See the documentation on the forum for additional information, especially about crafting
--
-- For developer documentation see the Developers' section on mesecons.tk
--
-- 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
-- }
-- effector =
-- {
-- action_on = function
-- action_off = function
-- action_change = function
-- rules = rules/get_rules
-- }
-- conductor =
-- {
-- state = mesecon.state.on/off
-- offstate = opposite state (for state = on only)
-- onstate = opposite state (for state = off only)
-- rules = rules/get_rules
-- }
--}
-- PUBLIC VARIABLES
mesecon={} -- contains all functions and all global variables
mesecon.actions_on={} -- Saves registered function callbacks for mesecon on
mesecon.actions_off={} -- Saves registered function callbacks for mesecon off
mesecon.actions_change={} -- Saves registered function callbacks for mesecon change
mesecon.receptors={}
mesecon.effectors={}
mesecon.conductors={}
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
-- INCLUDE SETTINGS
-- Settings
dofile(minetest.get_modpath("mesecons").."/settings.lua")
--Presets (eg default rules)
-- Presets (eg default rules)
dofile(minetest.get_modpath("mesecons").."/presets.lua");
--Internal API
-- 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
dofile(minetest.get_modpath("mesecons").."/internal.lua");
--Deprecated stuff
-- Deprecated stuff
-- To be removed in future releases
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
-- API API API API API API API API API API API API API API API API API API
-- 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
local np = {
x = pos.x + rule.x,
y = pos.y + rule.y,
z = pos.z + rule.z}
if mesecon:rules_link(pos, np, rules) then
mesecon:turnon(np, pos)
end
end
end
function mesecon:receptor_off(pos, rules)
rules = rules or mesecon.rules.default
for _, rule in ipairs(rules) do
local np = {
x = pos.x + rule.x,
y = pos.y + rule.y,
z = pos.z + rule.z}
if mesecon:rules_link(pos, np, rules) and not mesecon:connected_to_pw_src(np) then
mesecon:turnoff(np, pos)
end
end
end
print("[OK] mesecons")