init.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. extractor = extractor or {}
  2. extractor.modpath = minetest.get_modpath("extractor")
  3. extractor.get_formspec_defaults = function()
  4. local str =
  5. default.gui_bg ..
  6. default.gui_bg_img ..
  7. default.gui_slots
  8. return str
  9. end
  10. extractor.formspec_active = function(fuel_percent, item_percent)
  11. local formspec =
  12. "size[8,8.5]" ..
  13. extractor.get_formspec_defaults() ..
  14. "label[3.5,0;Fuel & Input]" ..
  15. "list[context;src;3.5,0.5;1,1;]" ..
  16. "list[context;fuel;3.5,2.5;1,1;]" ..
  17. "image[3.5,1.5;1,1;machine_progress_bg.png^[lowpart:" ..
  18. (100-fuel_percent) .. ":machine_progress_fg.png]" ..
  19. "image[4.5,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:" ..
  20. (item_percent) .. ":gui_furnace_arrow_fg.png^[transformR270]" ..
  21. "label[5.5,0.46;Destination]" ..
  22. "list[context;dst;5.5,0.96;2,2;]" ..
  23. "list[current_player;main;0,4.25;8,1;]" ..
  24. "list[current_player;main;0,5.5;8,3;8]" ..
  25. "label[0.75,0;Configuration]" ..
  26. "list[context;cfg;0.75,0.5;2,1;]" ..
  27. "label[0.75,2;Upgrades]" ..
  28. "list[context;upg;0.75,2.5;2,1;]" ..
  29. "listring[context;dst]" ..
  30. "listring[current_player;main]" ..
  31. "listring[context;src]" ..
  32. "listring[current_player;main]" ..
  33. "listring[context;fuel]" ..
  34. "listring[current_player;main]" ..
  35. default.get_hotbar_bg(0, 4.25)
  36. return formspec
  37. end
  38. extractor.formspec_inactive = function()
  39. return extractor.formspec_active(100, 0)
  40. end
  41. extractor.on_punch =
  42. function(pos, node, puncher, pointed_thing)
  43. machines.initialize_typedata(pos, "extractor:inactive", "mv")
  44. extractor.trigger_update(pos)
  45. end
  46. extractor.trigger_update =
  47. function(pos)
  48. local timer = minetest.get_node_timer(pos)
  49. if not timer:is_started() then
  50. timer:start(1.0)
  51. end
  52. end
  53. extractor.can_dig = function(pos, player)
  54. local meta = minetest.get_meta(pos);
  55. local inv = meta:get_inventory()
  56. return inv:is_empty("fuel") and
  57. inv:is_empty("dst") and
  58. inv:is_empty("src") and
  59. inv:is_empty("cfg") and
  60. inv:is_empty("upg")
  61. end
  62. extractor.allow_metadata_inventory_put =
  63. function(pos, listname, index, stack, player)
  64. return machines.allow_metadata_inventory_put(
  65. pos, listname, index, stack, player,
  66. "mesefuel", "fuel", "src", "dst", "cfg", "upg")
  67. end
  68. extractor.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  69. local meta = minetest.get_meta(pos)
  70. local inv = meta:get_inventory()
  71. local stack = inv:get_stack(from_list, from_index)
  72. return extractor.allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
  73. end
  74. extractor.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  75. if minetest.test_protection(pos, player:get_player_name()) then
  76. return 0
  77. end
  78. return stack:get_count()
  79. end
  80. local MACHINE_DATA = {
  81. name = "Extractor",
  82. method = "extracting",
  83. demand = 100,
  84. swap = {
  85. inactive = "extractor:inactive",
  86. active = "extractor:active",
  87. },
  88. form = {
  89. inactive = extractor.formspec_inactive,
  90. active = extractor.formspec_active,
  91. },
  92. fuel = "mesefuel",
  93. processable = "Extractable",
  94. }
  95. extractor.on_timer = function(pos, elapsed)
  96. machines.log_update(pos, "Extractor")
  97. return machines.on_machine_timer(pos, elapsed, MACHINE_DATA)
  98. end
  99. extractor.on_construct =
  100. function(pos)
  101. end
  102. extractor.after_place_node =
  103. function(pos, placer, itemstack, pointed_thing)
  104. machines.initialize_typedata(pos, "extractor:inactive", "mv")
  105. machines.after_place_machine(pos, placer, "Extractor", 1, extractor.formspec_inactive)
  106. end
  107. extractor.on_metadata_inventory_move = function(pos)
  108. extractor.trigger_update(pos)
  109. end
  110. extractor.on_metadata_inventory_put = function(pos)
  111. extractor.trigger_update(pos)
  112. end
  113. extractor.on_metadata_inventory_take = function(pos)
  114. extractor.trigger_update(pos)
  115. end
  116. extractor.on_blast = function(pos)
  117. local drops = {}
  118. default.get_inventory_drops(pos, "src", drops)
  119. default.get_inventory_drops(pos, "fuel", drops)
  120. default.get_inventory_drops(pos, "dst", drops)
  121. default.get_inventory_drops(pos, "cfg", drops)
  122. default.get_inventory_drops(pos, "upg", drops)
  123. drops[#drops+1] = "extractor:inactive"
  124. minetest.remove_node(pos)
  125. return drops
  126. end
  127. if not extractor.run_once then
  128. for k, v in ipairs({
  129. {name="inactive", light=0, tile="technic_lv_extractor_front.png"},
  130. {name="active", light=8, tile="technic_lv_extractor_front_active.png"},
  131. }) do
  132. minetest.register_node("extractor:" .. v.name, {
  133. description = "Extractor",
  134. tiles = {
  135. "technic_lv_extractor_top.png", "technic_lv_extractor_bottom.png",
  136. "technic_lv_extractor_side.png", "technic_lv_extractor_side.png",
  137. "technic_lv_extractor_side.png", v.tile,
  138. },
  139. paramtype2 = "facedir",
  140. groups = utility.dig_groups("machine", {
  141. tubedevice = 1, tubedevice_receiver = 1,
  142. immovable = 1,
  143. tier_mv = 1,
  144. }),
  145. light_source = v.light,
  146. on_rotate = function(...) return screwdriver.rotate_simple(...) end,
  147. is_ground_content = false,
  148. sounds = default.node_sound_metal_defaults(),
  149. drop = "extract2:mv_inactive",
  150. can_dig = function(...)
  151. return extractor.can_dig(...) end,
  152. on_timer = function(...)
  153. return extractor.on_timer(...) end,
  154. on_construct = function(...)
  155. return extractor.on_construct(...) end,
  156. on_blast = function(...)
  157. return extractor.on_blast(...) end,
  158. on_punch = function(...)
  159. return extractor.on_punch(...) end,
  160. after_place_node = function(...)
  161. return extractor.after_place_node(...) end,
  162. on_metadata_inventory_move = function(...)
  163. return extractor.on_metadata_inventory_move(...) end,
  164. on_metadata_inventory_put = function(...)
  165. return extractor.on_metadata_inventory_put(...) end,
  166. on_metadata_inventory_take = function(...)
  167. return extractor.on_metadata_inventory_take(...) end,
  168. allow_metadata_inventory_put = function(...)
  169. return extractor.allow_metadata_inventory_put(...) end,
  170. allow_metadata_inventory_move = function(...)
  171. return extractor.allow_metadata_inventory_move(...) end,
  172. allow_metadata_inventory_take = function(...)
  173. return extractor.allow_metadata_inventory_take(...) end,
  174. on_machine_execute = function(...)
  175. return machines.on_machine_execute(...) end,
  176. })
  177. end
  178. minetest.register_alias("extractor:extractor", "extractor:inactive")
  179. minetest.register_alias("extractor:extractor_active", "extractor:active")
  180. minetest.register_craft({
  181. output = 'extract2:lv_inactive',
  182. recipe = {
  183. {'tree_tap:tree_tap', 'techcrafts:electric_motor', 'tree_tap:tree_tap'},
  184. {'tree_tap:tree_tap', 'techcrafts:machine_casing', 'tree_tap:tree_tap'},
  185. {'default:stonebrick','techcrafts:control_logic_unit','default:stonebrick'},
  186. }
  187. })
  188. minetest.register_craft({
  189. output = 'extract2:mv_inactive',
  190. recipe = {
  191. {'stainless_steel:ingot', 'extract2:lv_inactive', 'stainless_steel:ingot'},
  192. {'stack_filter:filter', 'transformer:mv', 'stack_filter:filter'},
  193. {'stainless_steel:ingot', 'cb2:mv', 'stainless_steel:ingot'},
  194. }
  195. })
  196. local c = "extractor:core"
  197. local f = extractor.modpath .. "/init.lua"
  198. reload.register_file(c, f, false)
  199. dofile(extractor.modpath .. "/v2.lua")
  200. extractor.run_once = true
  201. end