You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

init.lua 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --
  2. -- trigger_mesecons
  3. --
  4. -- A simple Minetest mod that allows the trigger mod to power mesecons machines.
  5. --
  6. -- Most mesecons machines do not require this, they can be used directly with
  7. -- triggers.
  8. --
  9. -- MIT License
  10. --
  11. -- Copyright © 2017 by luk3yx
  12. --
  13. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  14. -- of this software and associated documentation files (the "Software"), to deal
  15. -- in the Software without restriction, including without limitation the rights
  16. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. -- copies of the Software, and to permit persons to whom the Software is
  18. -- furnished to do so, subject to the following conditions:
  19. --
  20. -- The above copyright notice and this permission notice shall be included in all
  21. -- copies or substantial portions of the Software.
  22. --
  23. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  29. -- SOFTWARE.
  30. -- Define the emitter node
  31. mesecon.register_node("trigger_mesecons:emitter", {
  32. description = "Trigger: Mesecons Emitter",
  33. sounds = default.node_sound_stone_defaults(),
  34. on_trigger = function(pos, node, value)
  35. if value then
  36. minetest.set_node(pos, {name = "trigger_mesecons:emitter_on"})
  37. mesecon.receptor_on(pos, mesecon.rules.alldirs)
  38. else
  39. minetest.set_node(pos, {name = "trigger_mesecons:emitter_off"})
  40. mesecon.receptor_off(pos, mesecon.rules.alldirs)
  41. end
  42. end,
  43. }, {
  44. groups = {oddly_breakable_by_hand = 1},
  45. tiles = {"trigger_texture.png^[colorize:#cc0a^mesecons_wire_inv.png"},
  46. mesecons = {receptor = {
  47. rules = mesecon.rules.alldirs,
  48. state = mesecon.state.off,
  49. }},
  50. }, {
  51. groups = {oddly_breakable_by_hand = 1, not_in_creative_inventory = 1},
  52. tiles = {"(trigger_texture.png^mesecons_wire_inv.png)^[colorize:#ff0a"},
  53. mesecons = {receptor = {
  54. rules = mesecon.rules.alldirs,
  55. state = mesecon.state.on,
  56. }},
  57. })
  58. -- Define the detector node
  59. minetest.register_node("trigger_mesecons:detector", {
  60. description = "Trigger: Mesecons Detector",
  61. sounds = default.node_sound_stone_defaults(),
  62. on_trigger = function(pos, node, value)
  63. if value then
  64. minetest.set_node(pos, {name = "trigger_mesecons:detector_on"})
  65. mesecon.receptor_on(pos, mesecon.rules.alldirs)
  66. else
  67. minetest.set_node(pos, {name = "trigger_mesecons:detector_off"})
  68. mesecon.receptor_off(pos, mesecon.rules.alldirs)
  69. end
  70. end,
  71. groups = {oddly_breakable_by_hand = 1},
  72. tiles = {"trigger_texture.png^[colorize:#cc06^mesecons_wire_inv.png"},
  73. mesecons = {effector = {
  74. rules = mesecon.rules.alldirs,
  75. action_on = function(pos, node)
  76. trigger.send(pos, true)
  77. end,
  78. action_off = function(pos, node)
  79. trigger.send(pos, false)
  80. end,
  81. }},
  82. })
  83. -- For easier typing
  84. minetest.register_alias("trigger_mesecons:emitter", "trigger_mesecons:emitter_off")
  85. -- For whatever reason, these may become useful in the future.
  86. minetest.register_alias("trigger:mesecons_emitter", "trigger_mesecons:emitter_off")
  87. minetest.register_alias("trigger:mesecons_emitter_off", "trigger_mesecons:emitter_off")
  88. minetest.register_alias("trigger:mesecons_emitter_on", "trigger_mesecons:emitter_on")
  89. minetest.register_alias("trigger:mesecons_detector", "trigger_mesecons:detector")