init.lua 7.8 KB

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