init.lua 7.5 KB

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