init.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. if not minetest.global_exists("centrifuge") then centrifuge = {} end
  2. centrifuge.modpath = minetest.get_modpath("centrifuge")
  3. centrifuge.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. centrifuge.formspec_active = function(fuel_percent, item_percent)
  11. local formspec =
  12. "size[8,8.5]" ..
  13. centrifuge.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. centrifuge.formspec_inactive = function()
  39. return centrifuge.formspec_active(100, 0)
  40. end
  41. centrifuge.on_punch =
  42. function(pos, node, puncher, pointed_thing)
  43. machines.initialize_typedata(pos, "centrifuge:inactive", "mv")
  44. centrifuge.trigger_update(pos)
  45. end
  46. centrifuge.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. centrifuge.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. centrifuge.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. centrifuge.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 centrifuge.allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
  73. end
  74. centrifuge.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 = "Centrifuge",
  82. method = "separating",
  83. demand = 200,
  84. swap = {
  85. inactive = "centrifuge:inactive",
  86. active = "centrifuge:active",
  87. },
  88. form = {
  89. inactive = centrifuge.formspec_inactive,
  90. active = centrifuge.formspec_active,
  91. },
  92. fuel = "mesefuel",
  93. processable = "Separable",
  94. }
  95. centrifuge.on_timer = function(pos, elapsed)
  96. machines.log_update(pos, "Centrifuge")
  97. return machines.on_machine_timer(pos, elapsed, MACHINE_DATA)
  98. end
  99. centrifuge.on_construct =
  100. function(pos)
  101. end
  102. centrifuge.after_place_node =
  103. function(pos, placer, itemstack, pointed_thing)
  104. machines.initialize_typedata(pos, "centrifuge:inactive", "mv")
  105. machines.after_place_machine(pos, placer, "Centrifuge", 1, centrifuge.formspec_inactive)
  106. end
  107. centrifuge.on_metadata_inventory_move = function(pos)
  108. centrifuge.trigger_update(pos)
  109. end
  110. centrifuge.on_metadata_inventory_put = function(pos)
  111. centrifuge.trigger_update(pos)
  112. end
  113. centrifuge.on_metadata_inventory_take = function(pos)
  114. centrifuge.trigger_update(pos)
  115. end
  116. centrifuge.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] = "centrifuge:inactive"
  124. minetest.remove_node(pos)
  125. return drops
  126. end
  127. if not centrifuge.run_once then
  128. local SIDE_ANIMATED = {
  129. name = "centrifuge_side.png",
  130. animation = {
  131. type = "vertical_frames",
  132. aspect_w = 16,
  133. aspect_h = 16,
  134. length = 0.5,
  135. },
  136. }
  137. local FRONT_ANIMATED = {
  138. image = "centrifuge_front_active.png",
  139. backface_culling = false,
  140. animation = {
  141. type = "vertical_frames",
  142. aspect_w = 16,
  143. aspect_h = 16,
  144. length = 0.5,
  145. },
  146. }
  147. for k, v in ipairs({
  148. {name="inactive", light=0, tile_side="centrifuge_side_no_anim.png", tile_front="centrifuge_front.png"},
  149. {name="active", light=4, tile_side=SIDE_ANIMATED, tile_front=FRONT_ANIMATED},
  150. }) do
  151. minetest.register_node("centrifuge:" .. v.name, {
  152. description = "Centrifuge",
  153. tiles = {
  154. "centrifuge_top.png", "centrifuge_bottom.png",
  155. v.tile_side, v.tile_side,
  156. v.tile_side, v.tile_front,
  157. },
  158. light_source = v.light,
  159. paramtype2 = "facedir",
  160. groups = utility.dig_groups("machine", {
  161. tubedevice = 1, tubedevice_receiver = 1,
  162. immovable = 1,
  163. tier_mv = 1,
  164. }),
  165. on_rotate = function(...) return screwdriver.rotate_simple(...) end,
  166. is_ground_content = false,
  167. sounds = default.node_sound_metal_defaults(),
  168. drop = "cent2:mv_inactive",
  169. can_dig = function(...)
  170. return centrifuge.can_dig(...) end,
  171. on_timer = function(...)
  172. return centrifuge.on_timer(...) end,
  173. on_construct = function(...)
  174. return centrifuge.on_construct(...) end,
  175. on_blast = function(...)
  176. return centrifuge.on_blast(...) end,
  177. on_punch = function(...)
  178. return centrifuge.on_punch(...) end,
  179. after_place_node = function(...)
  180. return centrifuge.after_place_node(...) end,
  181. on_metadata_inventory_move = function(...)
  182. return centrifuge.on_metadata_inventory_move(...) end,
  183. on_metadata_inventory_put = function(...)
  184. return centrifuge.on_metadata_inventory_put(...) end,
  185. on_metadata_inventory_take = function(...)
  186. return centrifuge.on_metadata_inventory_take(...) end,
  187. allow_metadata_inventory_put = function(...)
  188. return centrifuge.allow_metadata_inventory_put(...) end,
  189. allow_metadata_inventory_move = function(...)
  190. return centrifuge.allow_metadata_inventory_move(...) end,
  191. allow_metadata_inventory_take = function(...)
  192. return centrifuge.allow_metadata_inventory_take(...) end,
  193. on_machine_execute = function(...)
  194. return machines.on_machine_execute(...) end,
  195. })
  196. end
  197. minetest.register_craft({
  198. output = 'cent2:mv_inactive',
  199. recipe = {
  200. {"techcrafts:electric_motor", "techcrafts:copper_plate", "techcrafts:control_logic_unit"},
  201. {"techcrafts:copper_plate", "techcrafts:machine_casing", "techcrafts:copper_plate"},
  202. {"stack_filter:filter", "gem_cutter:blade", "stack_filter:filter"},
  203. }
  204. })
  205. local c = "centrifuge:core"
  206. local f = centrifuge.modpath .. "/init.lua"
  207. reload.register_file(c, f, false)
  208. dofile(centrifuge.modpath .. "/v2.lua")
  209. centrifuge.run_once = true
  210. end