init.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. --MESECON TORCHES
  2. local rotate_torch_rules = function (rules, param2)
  3. if param2 == 5 then
  4. return mesecon.rotate_rules_right(rules)
  5. elseif param2 == 2 then
  6. return mesecon.rotate_rules_right(mesecon.rotate_rules_right(rules)) --180 degrees
  7. elseif param2 == 4 then
  8. return mesecon.rotate_rules_left(rules)
  9. elseif param2 == 1 then
  10. return mesecon.rotate_rules_down(rules)
  11. elseif param2 == 0 then
  12. return mesecon.rotate_rules_up(rules)
  13. else
  14. return rules
  15. end
  16. end
  17. local torch_get_output_rules = function(node)
  18. local rules = {
  19. {x = 1, y = 0, z = 0},
  20. {x = 0, y = 0, z = 1},
  21. {x = 0, y = 0, z =-1},
  22. {x = 0, y = 1, z = 0},
  23. {x = 0, y =-1, z = 0}}
  24. return rotate_torch_rules(rules, node.param2)
  25. end
  26. local torch_get_input_rules = function(node)
  27. local rules = {{x = -2, y = 0, z = 0},
  28. {x = -1, y = 1, z = 0}}
  29. return rotate_torch_rules(rules, node.param2)
  30. end
  31. minetest.register_craft({
  32. output = "mesecons_torch:mesecon_torch_on 4",
  33. recipe = {
  34. {"group:mesecon_conductor_craftable"},
  35. {"default:stick"},}
  36. })
  37. local torch_selectionbox =
  38. {
  39. type = "wallmounted",
  40. wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
  41. wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
  42. wall_side = {-0.5, -0.1, -0.1, -0.5+0.6, 0.1, 0.1},
  43. }
  44. minetest.register_node("mesecons_torch:mesecon_torch_off", {
  45. drawtype = "torchlike",
  46. tiles = {"jeija_torches_off.png", "jeija_torches_off_ceiling.png", "jeija_torches_off_side.png"},
  47. inventory_image = "jeija_torches_off.png",
  48. paramtype = "light",
  49. is_ground_content = false,
  50. walkable = false,
  51. paramtype2 = "wallmounted",
  52. selection_box = torch_selectionbox,
  53. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  54. drop = "mesecons_torch:mesecon_torch_on",
  55. sounds = default.node_sound_defaults(),
  56. mesecons = {receptor = {
  57. state = mesecon.state.off,
  58. rules = torch_get_output_rules
  59. }},
  60. on_blast = mesecon.on_blastnode,
  61. })
  62. minetest.register_node("mesecons_torch:mesecon_torch_on", {
  63. drawtype = "torchlike",
  64. tiles = {"jeija_torches_on.png", "jeija_torches_on_ceiling.png", "jeija_torches_on_side.png"},
  65. inventory_image = "jeija_torches_on.png",
  66. wield_image = "jeija_torches_on.png",
  67. paramtype = "light",
  68. is_ground_content = false,
  69. sunlight_propagates = true,
  70. walkable = false,
  71. paramtype2 = "wallmounted",
  72. selection_box = torch_selectionbox,
  73. groups = {dig_immediate=3},
  74. light_source = minetest.LIGHT_MAX-5,
  75. description="Mesecon Torch",
  76. sounds = default.node_sound_defaults(),
  77. mesecons = {receptor = {
  78. state = mesecon.state.on,
  79. rules = torch_get_output_rules
  80. }},
  81. on_blast = mesecon.on_blastnode,
  82. })
  83. minetest.register_abm({
  84. nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"},
  85. interval = 1,
  86. chance = 1,
  87. action = function(pos, node)
  88. local is_powered = false
  89. for _, rule in ipairs(torch_get_input_rules(node)) do
  90. local src = vector.add(pos, rule)
  91. if mesecon.is_power_on(src) then
  92. is_powered = true
  93. end
  94. end
  95. if is_powered then
  96. if node.name == "mesecons_torch:mesecon_torch_on" then
  97. minetest.swap_node(pos, {name = "mesecons_torch:mesecon_torch_off", param2 = node.param2})
  98. mesecon.receptor_off(pos, torch_get_output_rules(node))
  99. end
  100. elseif node.name == "mesecons_torch:mesecon_torch_off" then
  101. minetest.swap_node(pos, {name = "mesecons_torch:mesecon_torch_on", param2 = node.param2})
  102. mesecon.receptor_on(pos, torch_get_output_rules(node))
  103. end
  104. end
  105. })
  106. -- Param2 Table (Block Attached To)
  107. -- 5 = z-1
  108. -- 3 = x-1
  109. -- 4 = z+1
  110. -- 2 = x+1
  111. -- 0 = y+1
  112. -- 1 = y-1