init.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. walkable = false,
  50. paramtype2 = "wallmounted",
  51. selection_box = torch_selectionbox,
  52. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  53. drop = "mesecons_torch:mesecon_torch_on",
  54. mesecons = {receptor = {
  55. state = mesecon.state.off,
  56. rules = torch_get_output_rules
  57. }}
  58. })
  59. minetest.register_node("mesecons_torch:mesecon_torch_on", {
  60. drawtype = "torchlike",
  61. tiles = {"jeija_torches_on.png", "jeija_torches_on_ceiling.png", "jeija_torches_on_side.png"},
  62. inventory_image = "jeija_torches_on.png",
  63. wield_image = "jeija_torches_on.png",
  64. paramtype = "light",
  65. sunlight_propagates = true,
  66. walkable = false,
  67. paramtype2 = "wallmounted",
  68. selection_box = torch_selectionbox,
  69. groups = {dig_immediate=3},
  70. light_source = LIGHT_MAX-5,
  71. description="Mesecon Torch",
  72. mesecons = {receptor = {
  73. state = mesecon.state.on,
  74. rules = torch_get_output_rules
  75. }},
  76. })
  77. minetest.register_abm({
  78. nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"},
  79. interval = 1,
  80. chance = 1,
  81. action = function(pos, node)
  82. local is_powered = false
  83. for _, rule in ipairs(torch_get_input_rules(node)) do
  84. local src = mesecon:addPosRule(pos, rule)
  85. if mesecon:is_power_on(src) then
  86. is_powered = true
  87. end
  88. end
  89. if is_powered then
  90. if node.name == "mesecons_torch:mesecon_torch_on" then
  91. mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_off")
  92. mesecon:receptor_off(pos, torch_get_output_rules(node))
  93. end
  94. elseif node.name == "mesecons_torch:mesecon_torch_off" then
  95. mesecon:swap_node(pos, "mesecons_torch:mesecon_torch_on")
  96. mesecon:receptor_on(pos, torch_get_output_rules(node))
  97. end
  98. end
  99. })
  100. -- Param2 Table (Block Attached To)
  101. -- 5 = z-1
  102. -- 3 = x-1
  103. -- 4 = z+1
  104. -- 2 = x+1
  105. -- 0 = y+1
  106. -- 1 = y-1