init.lua 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. compressor = compressor or {}
  2. compressor.modpath = minetest.get_modpath("compressor")
  3. compressor.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. -- Get active formspec.
  11. compressor.get_active_formspec = function(fuel_percent, item_percent)
  12. local formspec =
  13. "size[8,8.5]" ..
  14. compressor.get_formspec_defaults() ..
  15. "label[3.5,0;Fuel & Input]" ..
  16. "list[context;src;3.5,0.5;1,1;]" ..
  17. "list[context;fuel;3.5,2.5;1,1;]" ..
  18. "image[3.5,1.5;1,1;machine_progress_bg.png^[lowpart:" ..
  19. (100-fuel_percent) .. ":machine_progress_fg.png]" ..
  20. "image[4.5,1.5;1,1;gui_furnace_arrow_bg.png^[lowpart:" ..
  21. (item_percent) .. ":gui_furnace_arrow_fg.png^[transformR270]" ..
  22. "label[5.5,0.46;Destination]" ..
  23. "list[context;dst;5.5,0.96;2,2;]" ..
  24. "list[current_player;main;0,4.25;8,1;]" ..
  25. "list[current_player;main;0,5.5;8,3;8]" ..
  26. "label[0.75,0;Configuration]" ..
  27. "list[context;cfg;0.75,0.5;2,1;]" ..
  28. "label[0.75,2;Upgrades]" ..
  29. "list[context;upg;0.75,2.5;2,1;]" ..
  30. "listring[context;dst]" ..
  31. "listring[current_player;main]" ..
  32. "listring[context;src]" ..
  33. "listring[current_player;main]" ..
  34. "listring[context;fuel]" ..
  35. "listring[current_player;main]" ..
  36. default.get_hotbar_bg(0, 4.25)
  37. return formspec
  38. end
  39. compressor.get_inactive_formspec = function()
  40. return compressor.get_active_formspec(100, 0)
  41. end
  42. compressor.on_punch =
  43. function(pos, node, puncher, pointed_thing)
  44. machines.initialize_typedata(pos, "compressor:inactive", "mv")
  45. compressor.trigger_update(pos)
  46. end
  47. compressor.can_dig = function(pos, player)
  48. local meta = minetest.get_meta(pos);
  49. local inv = meta:get_inventory()
  50. return inv:is_empty("fuel") and
  51. inv:is_empty("dst") and
  52. inv:is_empty("src") and
  53. inv:is_empty("cfg") and
  54. inv:is_empty("upg")
  55. end
  56. compressor.allow_metadata_inventory_put =
  57. function(pos, listname, index, stack, player)
  58. return machines.allow_metadata_inventory_put(
  59. pos, listname, index, stack, player,
  60. "mesefuel", "fuel", "src", "dst", "cfg", "upg")
  61. end
  62. compressor.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  63. local meta = minetest.get_meta(pos)
  64. local inv = meta:get_inventory()
  65. local stack = inv:get_stack(from_list, from_index)
  66. return compressor.allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
  67. end
  68. compressor.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  69. if minetest.test_protection(pos, player:get_player_name()) then
  70. return 0
  71. end
  72. return stack:get_count()
  73. end
  74. local MACHINE_DATA = {
  75. name = "Compressor",
  76. method = "compressing",
  77. demand = 200,
  78. swap = {
  79. inactive = "compressor:inactive",
  80. active = "compressor:active",
  81. },
  82. form = {
  83. inactive = compressor.get_inactive_formspec,
  84. active = compressor.get_active_formspec,
  85. },
  86. fuel = "mesefuel",
  87. processable = "Compressable",
  88. }
  89. compressor.on_timer = function(pos, elapsed)
  90. machines.log_update(pos, "Compressor")
  91. return machines.on_machine_timer(pos, elapsed, MACHINE_DATA)
  92. end
  93. compressor.on_blast = function(pos)
  94. local drops = {}
  95. default.get_inventory_drops(pos, "src", drops)
  96. default.get_inventory_drops(pos, "fuel", drops)
  97. default.get_inventory_drops(pos, "dst", drops)
  98. default.get_inventory_drops(pos, "cfg", drops)
  99. default.get_inventory_drops(pos, "upg", drops)
  100. drops[#drops+1] = "compressor:inactive"
  101. minetest.remove_node(pos)
  102. return drops
  103. end
  104. compressor.on_construct =
  105. function(pos)
  106. end
  107. compressor.after_place_node =
  108. function(pos, placer, itemstack, pointed_thing)
  109. machines.initialize_typedata(pos, "compressor:inactive", "mv")
  110. machines.after_place_machine(pos, placer, "Compressor", 1, compressor.get_inactive_formspec)
  111. end
  112. compressor.on_metadata_inventory_move = function(pos)
  113. compressor.trigger_update(pos)
  114. end
  115. compressor.on_metadata_inventory_put =
  116. function(pos)
  117. compressor.trigger_update(pos)
  118. end
  119. compressor.on_metadata_inventory_take =
  120. function(pos)
  121. compressor.trigger_update(pos)
  122. end
  123. compressor.trigger_update =
  124. function(pos)
  125. local timer = minetest.get_node_timer(pos)
  126. if not timer:is_started() then
  127. timer:start(1.0)
  128. end
  129. end
  130. if not compressor.run_once then
  131. for k, v in ipairs({
  132. {name="inactive", light=0, tile="compressor_front.png"},
  133. {name="active", light=8, tile="compressor_front_active.png"},
  134. }) do
  135. minetest.register_node("compressor:" .. v.name, {
  136. description = "Compressor",
  137. tiles = {
  138. "compressor_top.png", "compressor_top.png",
  139. "compressor_side.png", "compressor_side.png",
  140. "compressor_side.png", v.tile,
  141. },
  142. groups = utility.dig_groups("machine", {
  143. tubedevice = 1, tubedevice_receiver = 1,
  144. immovable = 1,
  145. tier_mv = 1,
  146. }),
  147. light_source = v.light,
  148. paramtype2 = "facedir",
  149. on_rotate = function(...) return screwdriver.rotate_simple(...) end,
  150. is_ground_content = false,
  151. sounds = default.node_sound_metal_defaults(),
  152. drop = "comp2:mv_inactive",
  153. can_dig = function(...)
  154. return compressor.can_dig(...) end,
  155. on_timer = function(...)
  156. return compressor.on_timer(...) end,
  157. on_construct = function(...)
  158. return compressor.on_construct(...) end,
  159. after_place_node = function(...)
  160. return compressor.after_place_node(...) end,
  161. on_punch = function(...)
  162. return compressor.on_punch(...) end,
  163. on_metadata_inventory_move = function(...)
  164. return compressor.on_metadata_inventory_move(...) end,
  165. on_metadata_inventory_put = function(...)
  166. return compressor.on_metadata_inventory_put(...) end,
  167. on_metadata_inventory_take = function(...)
  168. return compressor.on_metadata_inventory_take(...) end,
  169. on_blast = function(...)
  170. return compressor.on_blast(...) end,
  171. allow_metadata_inventory_put = function(...)
  172. return compressor.allow_metadata_inventory_put(...) end,
  173. allow_metadata_inventory_move = function(...)
  174. return compressor.allow_metadata_inventory_move(...) end,
  175. allow_metadata_inventory_take = function(...)
  176. return compressor.allow_metadata_inventory_take(...) end,
  177. on_machine_execute = function(...)
  178. return machines.on_machine_execute(...) end,
  179. })
  180. end
  181. minetest.register_craft({
  182. output = 'comp2:lv_inactive',
  183. recipe = {
  184. {'cast_iron:ingot', 'techcrafts:electric_motor', 'cast_iron:ingot'},
  185. {'default:obsidian_block', 'techcrafts:machine_casing', 'default:obsidian_block'},
  186. {'fine_wire:silver', 'techcrafts:electric_motor', 'fine_wire:silver'},
  187. }
  188. })
  189. minetest.register_craft({
  190. output = 'comp2:mv_inactive',
  191. recipe = {
  192. {'stainless_steel:ingot', 'comp2:lv_inactive', 'stainless_steel:ingot'},
  193. {'techcrafts:copper_plate', 'transformer:mv', 'techcrafts:carbon_plate'},
  194. {'stainless_steel:ingot', 'cb2:mv', 'stainless_steel:ingot'},
  195. }
  196. })
  197. minetest.register_craft({
  198. type = "compressing",
  199. output = "default:ice",
  200. recipe = "default:snowblock",
  201. time = 4,
  202. })
  203. minetest.register_craft({
  204. type = "compressing",
  205. output = "default:desert_stone",
  206. recipe = "default:desert_sandstone 2",
  207. time = 16,
  208. })
  209. minetest.register_craft({
  210. type = "compressing",
  211. output = "default:stone",
  212. recipe = "default:sandstone 2",
  213. time = 16,
  214. })
  215. minetest.register_craft({
  216. type = "compressing",
  217. output = "default:sandstone",
  218. recipe = "default:sand 2",
  219. time = 16,
  220. })
  221. minetest.register_craft({
  222. type = "compressing",
  223. output = "default:desert_sandstone",
  224. recipe = "default:desert_sand 2",
  225. time = 16,
  226. })
  227. minetest.register_craft({
  228. type = "compressing",
  229. output = "default:silver_sandstone",
  230. recipe = "sand:sand_with_ice_crystals 2",
  231. time = 16,
  232. })
  233. minetest.register_craft({
  234. type = "compressing",
  235. output = "plastic:oil_extract",
  236. recipe = "group:seed_oil 15",
  237. time = 7,
  238. })
  239. local c = "compressor:core"
  240. local f = compressor.modpath .. "/init.lua"
  241. reload.register_file(c, f, false)
  242. dofile(compressor.modpath .. "/v2.lua")
  243. compressor.run_once = true
  244. end