init.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. -- |\ /| ____ ____ ____ _____ ____ _____
  2. -- | \ / | | | | | | | |\ | |
  3. -- | \/ | |___ ____ |___ | | | | \ | |____
  4. -- | | | | | | | | | \ | |
  5. -- | | |___ ____| |___ |____ |____| | \| ____|
  6. -- by Jeija, Uberi (Temperest), sfan5, VanessaE
  7. --
  8. --
  9. --
  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
  12. --
  13. --
  14. -- For developer documentation see the Developers' section on mesecons.TK
  15. --
  16. --
  17. --
  18. --Quick draft for the mesecons array in the node's definition
  19. --mesecons =
  20. --{
  21. -- receptor =
  22. -- {
  23. -- state = mesecon.state.on/off
  24. -- rules = rules/get_rules
  25. -- },
  26. -- effector =
  27. -- {
  28. -- action_on = function
  29. -- action_off = function
  30. -- action_change = function
  31. -- rules = rules/get_rules
  32. -- },
  33. -- conductor =
  34. -- {
  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
  39. -- }
  40. --}
  41. -- PUBLIC VARIABLES
  42. mesecon={} -- contains all functions and all global variables
  43. mesecon.actions_on={} -- Saves registered function callbacks for mesecon on | DEPRECATED
  44. mesecon.actions_off={} -- Saves registered function callbacks for mesecon off | DEPRECATED
  45. mesecon.actions_change={} -- Saves registered function callbacks for mesecon change | DEPRECATED
  46. mesecon.receptors={} -- saves all information about receptors | DEPRECATED
  47. mesecon.effectors={} -- saves all information about effectors | DEPRECATED
  48. mesecon.conductors={} -- saves all information about conductors | DEPRECATED
  49. -- Settings
  50. dofile(minetest.get_modpath("mesecons").."/settings.lua")
  51. -- Presets (eg default rules)
  52. dofile(minetest.get_modpath("mesecons").."/presets.lua");
  53. -- Utilities like comparing positions,
  54. -- adding positions and rules,
  55. -- mostly things that make the source look cleaner
  56. dofile(minetest.get_modpath("mesecons").."/util.lua");
  57. -- Internal stuff
  58. -- This is the most important file
  59. -- it handles signal transmission and basically everything else
  60. -- It is also responsible for managing the nodedef things,
  61. -- like calling action_on/off/change
  62. dofile(minetest.get_modpath("mesecons").."/internal.lua");
  63. -- Deprecated stuff
  64. -- To be removed in future releases
  65. -- Currently there is nothing here
  66. dofile(minetest.get_modpath("mesecons").."/legacy.lua");
  67. -- API
  68. -- these are the only functions you need to remember
  69. function mesecon:receptor_on(pos, rules)
  70. rules = rules or mesecon.rules.default
  71. for _, rule in ipairs(rules) do
  72. local np = mesecon:addPosRule(pos, rule)
  73. local link, rulename = mesecon:rules_link(pos, np, rules)
  74. if link then
  75. mesecon:turnon(np, rulename)
  76. end
  77. end
  78. end
  79. function mesecon:receptor_off(pos, rules)
  80. rules = rules or mesecon.rules.default
  81. for _, rule in ipairs(rules) do
  82. local np = mesecon:addPosRule(pos, rule)
  83. local link, rulename = mesecon:rules_link(pos, np, rules)
  84. if link then
  85. if not mesecon:connected_to_receptor(np) then
  86. mesecon:turnoff(np, rulename)
  87. else
  88. mesecon:changesignal(np, minetest.env:get_node(np), rulename, mesecon.state.off)
  89. end
  90. end
  91. end
  92. end
  93. print("[OK] Mesecons")
  94. --The actual wires
  95. dofile(minetest.get_modpath("mesecons").."/wires.lua");
  96. --Services like turnoff receptor on dignode and so on
  97. dofile(minetest.get_modpath("mesecons").."/services.lua");