miner.lua 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. minetest.register_node("factory:miner_on", {
  2. description = "Industrial Miner",
  3. tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png", "factory_belt_bottom_clean.png",
  4. "factory_belt_bottom_clean.png", "factory_belt_bottom_clean.png", {name="factory_miner.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.7}}},
  5. groups = {cracky = 2, mesecon_effector_off = 1},
  6. paramtype2 = "facedir",
  7. is_ground_content = true,
  8. legacy_facedir_simple = true,
  9. mesecons = {effector = {
  10. action_on = function(pos, node)
  11. minetest.swap_node(pos, {name = "factory:miner_off", param2 = node.param2})
  12. end
  13. }},
  14. after_place_node = function(pos, placer, itemstack, pointed_thing)
  15. local meta = minetest:get_meta(pos)
  16. if placer:is_player() then
  17. meta:set_string("owner", placer:get_player_name())
  18. end
  19. end,
  20. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  21. for i = 1, factory.minerDigLimit do
  22. local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z})
  23. if node.name == "factory:miner_drillbit" then
  24. minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"})
  25. end
  26. end
  27. end,
  28. })
  29. minetest.register_node("factory:miner_off", {
  30. description = "Industrial Miner",
  31. tiles = {{name="factory_fan.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}, "factory_belt_bottom.png", "factory_belt_bottom_clean.png",
  32. "factory_belt_bottom_clean.png", "factory_belt_bottom_clean.png", {name="factory_miner.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}},
  33. groups = {cracky = 2, not_in_creative_inventory = 1, mesecon_effector_on = 1},
  34. paramtype2 = "facedir",
  35. is_ground_content = true,
  36. legacy_facedir_simple = true,
  37. drop="factory:miner_on",
  38. mesecons = {effector = {
  39. action_off = function(pos, node)
  40. minetest.swap_node(pos, {name = "factory:miner_on", param2 = node.param2})
  41. end
  42. }},
  43. after_place_node = function(pos, placer, itemstack, pointed_thing)
  44. -- not supposed to be placed. switch to factory:miner_on
  45. minetest.swap_node(pos, {name = "factory:miner_on", param2 = node.param2})
  46. end,
  47. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  48. for i = 1, factory.minerDigLimit do
  49. local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z})
  50. if node.name == "factory:miner_drillbit" then
  51. minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"})
  52. end
  53. end
  54. end,
  55. })
  56. minetest.register_node("factory:miner_drillbit", {
  57. tiles = {"factory_machine_steel_dark.png"},
  58. diggable = false,
  59. groups = {not_in_creative_inventory = 1},
  60. drawtype = "nodebox",
  61. paramtype = "light",
  62. drop = nil,
  63. node_box = {
  64. type = "fixed",
  65. fixed = {
  66. {-0.125, -0.5, -0.125, 0.125, 0.5, 0.125},
  67. }
  68. }
  69. })
  70. minetest.register_abm({
  71. nodenames = {"factory:miner_on"},
  72. neighbors = nil,
  73. interval = 4.8,
  74. chance = 1,
  75. action = function(pos, node, active_object_count, active_object_count_wider)
  76. for i = 1, factory.minerDigLimit do
  77. local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z})
  78. local registered = minetest.registered_nodes[node.name]
  79. local meta = minetest.get_meta(pos)
  80. if node.name == "ignore" then
  81. minetest.forceload_block({x = pos.x, y = pos.y-i-2, z = pos.z})
  82. return
  83. end
  84. if node.name ~= "factory:miner_drillbit" then
  85. if meta:get_string("owner") ~= nil and minetest.is_protected(node.pos, meta:get_string("owner")) then
  86. minetest.swap_node(pos, {name = "factory:miner_off", param2 = node.param2})
  87. return
  88. end
  89. if node.name ~= "air" and registered.diggable ~= nil and not registered.diggable then
  90. minetest.swap_node(pos, {name = "factory:miner_off", param2 = node.param2})
  91. return
  92. end
  93. minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="factory:miner_drillbit"})
  94. if node.name == "air" then return end
  95. local itemstacks = minetest.get_node_drops(node.name)
  96. for _, itemname in ipairs(itemstacks) do
  97. minetest.add_item({x = pos.x, y = pos.y+1, z = pos.z}, itemname)
  98. end
  99. return
  100. end
  101. end
  102. end,
  103. })
  104. --
  105. minetest.register_node("factory:miner_upgraded_on", {
  106. description = "Upgraded Miner",
  107. tiles = {{name="factory_fan.png^factory_gold_ring_x2.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.2}}, "factory_belt_bottom.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png",
  108. "factory_belt_bottom_clean.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png", {name="factory_miner_upgraded.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0.7}}},
  109. groups = {cracky = 2, mesecon_effector_off = 1},
  110. paramtype2 = "facedir",
  111. is_ground_content = true,
  112. legacy_facedir_simple = true,
  113. mesecons = {effector = {
  114. action_on = function(pos, node)
  115. minetest.swap_node(pos, {name = "factory:miner_upgraded_off", param2 = node.param2})
  116. end
  117. }},
  118. after_place_node = function(pos, placer, itemstack, pointed_thing)
  119. local meta = minetest:get_meta(pos)
  120. if placer:is_player() then
  121. meta:set_string("owner", placer:get_player_name())
  122. end
  123. end,
  124. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  125. for i = 1, factory.minerDigLimit do
  126. local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z})
  127. if node.name == "factory:miner_drillbit" then
  128. minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"})
  129. end
  130. end
  131. end,
  132. })
  133. minetest.register_node("factory:miner_upgraded_off", {
  134. description = "Industrial Miner",
  135. tiles = {{name="factory_fan.png^factory_gold_ring_x2.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}, "factory_belt_bottom.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png",
  136. "factory_belt_bottom_clean.png^factory_gold_ring.png", "factory_belt_bottom_clean.png^factory_gold_ring.png", {name="factory_miner_upgraded.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=0}}},
  137. groups = {cracky = 2, not_in_creative_inventory = 1, mesecon_effector_on = 1},
  138. paramtype2 = "facedir",
  139. is_ground_content = true,
  140. legacy_facedir_simple = true,
  141. drop="factory:miner_on",
  142. mesecons = {effector = {
  143. action_off = function(pos, node)
  144. minetest.swap_node(pos, {name = "factory:miner_upgraded_on", param2 = node.param2})
  145. end
  146. }},
  147. after_place_node = function(pos, placer, itemstack, pointed_thing)
  148. -- not supposed to be placed. switch to factory:miner_on
  149. minetest.swap_node(pos, {name = "factory:miner_upgraded_on", param2 = node.param2})
  150. end,
  151. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  152. for i = 1, factory.minerDigLimit do
  153. local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z})
  154. if node.name == "factory:miner_drillbit" then
  155. minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="air"})
  156. end
  157. end
  158. end,
  159. })
  160. minetest.register_abm({
  161. nodenames = {"factory:miner_upgraded_on"},
  162. neighbors = nil,
  163. interval = 1.8,
  164. chance = 1,
  165. action = function(pos, node, active_object_count, active_object_count_wider)
  166. for i = 1, factory.minerDigLimit do
  167. local node = minetest.get_node({x = pos.x, y = pos.y-i, z = pos.z})
  168. local registered = minetest.registered_nodes[node.name]
  169. local meta = minetest.get_meta(pos)
  170. if node.name == "ignore" then
  171. minetest.forceload_block({x = pos.x, y = pos.y-i-2, z = pos.z})
  172. return
  173. end
  174. if node.name ~= "factory:miner_drillbit" then
  175. if meta:get_string("owner") ~= nil and minetest.is_protected(node.pos, meta:get_string("owner")) then
  176. minetest.swap_node(pos, {name = "factory:miner_upgraded_off", param2 = node.param2})
  177. return
  178. end
  179. if node.name ~= "air" and registered.diggable ~= nil and not registered.diggable then
  180. minetest.swap_node(pos, {name = "factory:miner_upgraded_off", param2 = node.param2})
  181. return
  182. end
  183. minetest.set_node({x = pos.x, y = pos.y-i, z = pos.z}, {name="factory:miner_drillbit"})
  184. if node.name == "air" then return end
  185. local itemstacks = minetest.get_node_drops(node.name)
  186. for _, itemname in ipairs(itemstacks) do
  187. minetest.add_item({x = pos.x, y = pos.y+1, z = pos.z}, itemname)
  188. end
  189. return
  190. end
  191. end
  192. end,
  193. })