init.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. electric_furnace = electric_furnace or {}
  2. electric_furnace.modpath = minetest.get_modpath("electric_furnace")
  3. -- Get active formspec.
  4. electric_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.5,0;Fuel & Input]" ..
  11. "list[context;src;3.5,0.5;1,1;]" ..
  12. "list[context;fuel;3.5,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[4.5,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:" ..
  16. (item_percent) .. ":gui_furnace_arrow_fg.png^[transformR270]" ..
  17. "label[5.5,0.46;Destination]" ..
  18. "list[context;dst;5.5,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.75,0;Configuration]" ..
  22. "list[context;cfg;0.75,0.5;2,1;]" ..
  23. "label[0.75,2;Upgrades]" ..
  24. "list[context;upg;0.75,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_furnace.get_inactive_formspec = function()
  35. return electric_furnace.get_active_formspec(100, 0)
  36. end
  37. electric_furnace.on_punch =
  38. function(pos, node, puncher, pointed_thing)
  39. machines.initialize_typedata(pos, "electric_furnace:inactive", "mv")
  40. electric_furnace.trigger_update(pos)
  41. end
  42. electric_furnace.trigger_update =
  43. function(pos)
  44. local timer = minetest.get_node_timer(pos)
  45. if not timer:is_started() then
  46. timer:start(1.0)
  47. end
  48. end
  49. electric_furnace.can_dig = function(pos, player)
  50. local meta = minetest.get_meta(pos);
  51. local inv = meta:get_inventory()
  52. return inv:is_empty("fuel") and
  53. inv:is_empty("dst") and
  54. inv:is_empty("src") and
  55. inv:is_empty("cfg") and
  56. inv:is_empty("upg")
  57. end
  58. electric_furnace.allow_metadata_inventory_put =
  59. function(pos, listname, index, stack, player)
  60. return machines.allow_metadata_inventory_put(
  61. pos, listname, index, stack, player,
  62. "mesefuel", "fuel", "src", "dst", "cfg", "upg")
  63. end
  64. electric_furnace.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  65. local meta = minetest.get_meta(pos)
  66. local inv = meta:get_inventory()
  67. local stack = inv:get_stack(from_list, from_index)
  68. return electric_furnace.allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
  69. end
  70. electric_furnace.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  71. local pname = player:get_player_name()
  72. if minetest.test_protection(pos, pname) then
  73. return 0
  74. end
  75. return stack:get_count()
  76. end
  77. local MACHINE_DATA = {
  78. name = "Electric Furnace",
  79. method = "cooking",
  80. demand = 300,
  81. swap = {
  82. inactive = "electric_furnace:inactive",
  83. active = "electric_furnace:active",
  84. },
  85. form = {
  86. inactive = electric_furnace.get_inactive_formspec,
  87. active = electric_furnace.get_active_formspec,
  88. },
  89. fuel = "mesefuel",
  90. processable = "Smeltable",
  91. }
  92. electric_furnace.on_timer = function(pos, elapsed)
  93. machines.log_update(pos, "Furnace")
  94. return machines.on_machine_timer(pos, elapsed, MACHINE_DATA)
  95. end
  96. electric_furnace.on_blast = function(pos)
  97. local drops = {}
  98. default.get_inventory_drops(pos, "src", drops)
  99. default.get_inventory_drops(pos, "fuel", drops)
  100. default.get_inventory_drops(pos, "dst", drops)
  101. default.get_inventory_drops(pos, "cfg", drops)
  102. default.get_inventory_drops(pos, "upg", drops)
  103. drops[#drops+1] = "electric_furnace:inactive"
  104. minetest.remove_node(pos)
  105. return drops
  106. end
  107. electric_furnace.on_construct =
  108. function(pos)
  109. end
  110. electric_furnace.after_place_node =
  111. function(pos, placer, itemstack, pointed_thing)
  112. machines.initialize_typedata(pos, "electric_furnace:inactive", "mv")
  113. machines.after_place_machine(pos, placer, "Electric Furnace", 1, electric_furnace.get_inactive_formspec)
  114. end
  115. electric_furnace.on_metadata_inventory_move = function(pos)
  116. electric_furnace.trigger_update(pos)
  117. end
  118. electric_furnace.on_metadata_inventory_put = function(pos)
  119. electric_furnace.trigger_update(pos)
  120. end
  121. electric_furnace.on_metadata_inventory_take = function(pos)
  122. electric_furnace.trigger_update(pos)
  123. end
  124. if not electric_furnace.run_once then
  125. for k, v in ipairs({
  126. {name="inactive", light=0, tile="electric_furnace_front.png"},
  127. {name="active", light=8, tile="electric_furnace_front_active.png"},
  128. }) do
  129. minetest.register_node("electric_furnace:" .. v.name, {
  130. description = "Electric Furnace",
  131. tiles = {
  132. "electric_furnace_top.png", "electric_furnace_bottom.png",
  133. "electric_furnace_side.png", "electric_furnace_side.png",
  134. "electric_furnace_side.png", v.tile,
  135. },
  136. groups = utility.dig_groups("machine", {
  137. tubedevice = 1, tubedevice_receiver = 1,
  138. immovable = 1,
  139. tier_mv = 1,
  140. }),
  141. light_source = v.light,
  142. paramtype2 = "facedir",
  143. on_rotate = function(...) return screwdriver.rotate_simple(...) end,
  144. is_ground_content = false,
  145. sounds = default.node_sound_metal_defaults(),
  146. drop = "ecfurn2:mv_inactive",
  147. can_dig = function(...)
  148. return electric_furnace.can_dig(...) end,
  149. on_timer = function(...)
  150. return electric_furnace.on_timer(...) end,
  151. on_construct = function(...)
  152. return electric_furnace.on_construct(...) end,
  153. after_place_node = function(...)
  154. return electric_furnace.after_place_node(...) end,
  155. on_punch = function(...)
  156. return electric_furnace.on_punch(...) end,
  157. on_metadata_inventory_move = function(...)
  158. return electric_furnace.on_metadata_inventory_move(...) end,
  159. on_metadata_inventory_put = function(...)
  160. return electric_furnace.on_metadata_inventory_put(...) end,
  161. on_metadata_inventory_take = function(...)
  162. return electric_furnace.on_metadata_inventory_take(...) end,
  163. on_blast = function(...)
  164. return electric_furnace.on_blast(...) end,
  165. allow_metadata_inventory_put = function(...)
  166. return electric_furnace.allow_metadata_inventory_put(...) end,
  167. allow_metadata_inventory_move = function(...)
  168. return electric_furnace.allow_metadata_inventory_move(...) end,
  169. allow_metadata_inventory_take = function(...)
  170. return electric_furnace.allow_metadata_inventory_take(...) end,
  171. on_machine_execute = function(...)
  172. return machines.on_machine_execute(...) end,
  173. })
  174. end
  175. minetest.register_craft({
  176. output = 'ecfurn2:lv_inactive',
  177. recipe = {
  178. {'stainless_steel:ingot', 'cobble_furnace:inactive', 'stainless_steel:ingot'},
  179. {'default:stone', 'techcrafts:machine_casing','default:stone'},
  180. {'stainless_steel:ingot', 'transformer:lv', 'stainless_steel:ingot'},
  181. }
  182. })
  183. minetest.register_craft({
  184. output = 'ecfurn2:mv_inactive',
  185. recipe = {
  186. {'stainless_steel:ingot', 'ecfurn2:lv_inactive', 'stainless_steel:ingot'},
  187. {'techcrafts:composite_plate', 'transformer:mv', 'techcrafts:machine_casing'},
  188. {'stainless_steel:ingot', 'cb2:mv', 'stainless_steel:ingot'},
  189. }
  190. })
  191. minetest.register_craft({
  192. output = 'ecfurn2:hv_inactive',
  193. recipe = {
  194. {'stainless_steel:ingot', 'ecfurn2:mv_inactive', 'stainless_steel:ingot'},
  195. {'techcrafts:composite_plate', 'transformer:hv', 'techcrafts:composite_plate'},
  196. {'stainless_steel:ingot', 'cb2:hv', 'stainless_steel:ingot'},
  197. }
  198. })
  199. local c = "electric_furnace:core"
  200. local f = electric_furnace.modpath .. "/init.lua"
  201. reload.register_file(c, f, false)
  202. dofile(electric_furnace.modpath .. "/v2.lua")
  203. electric_furnace.run_once = true
  204. end