machine.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. local material = {}
  2. local shape = {}
  3. local make_ok = {}
  4. local anzahl = {}
  5. minetest.register_node("mysheetmetal:machine", {
  6. description = "Eavestrough Machine",
  7. tiles = {
  8. "mysheetmetal_mach_top.png",
  9. "mysheetmetal_mach_top.png",
  10. "mysheetmetal_mach_side.png",
  11. "mysheetmetal_mach_side.png",
  12. "mysheetmetal_mach_back.png",
  13. "mysheetmetal_mach_front.png",
  14. },
  15. drawtype = "nodebox",
  16. paramtype = "light",
  17. paramtype2 = "facedir",
  18. groups = {cracky=2},
  19. node_box = {
  20. type = "fixed",
  21. fixed = {
  22. {-0.5, -0.0625, -0.3125, 0.5, 0.0625, 0.1875},
  23. {-0.5, 0.125, -0.3125, 0.5, 0.1875, 0.125},
  24. {-0.5, 0.1875, -0.25, 0.5, 0.25, 0.125},
  25. {-0.5, -0.0625, -0.4375, 0.5, 0.0625, -0.3125},
  26. {0, -0.25, -0.4375, 0.0625, -0.0625, -0.375},
  27. {0, -0.3125, -0.4375, 0.5, -0.25, -0.375},
  28. {-0.5, -0.5, 0.0625, -0.375, -0.0625, 0.1875},
  29. {0, 0.25, 0, 0.0625, 0.5, 0.0625},
  30. {0.0625, 0.4375, 0, 0.5, 0.5, 0.0625},
  31. {-0.5, 0.0625, 0.125, 0.5, 0.1875, 0.1875},
  32. {-0.5, -0.5, -0.3125, -0.375, -0.0625, -0.1875},
  33. {0.5, -0.0625, -0.3125, 1.5, 0.0625, 0.1875},
  34. {0.5, 0.125, -0.3125, 1.5, 0.1875, 0.125},
  35. {0.5, 0.1875, -0.25, 1.5, 0.25, 0.125},
  36. {0.5, -0.0625, -0.4375, 1.5, 0.0625, -0.3125},
  37. {1, -0.25, -0.4375, 1.0625, -0.0625, -0.375},
  38. {0.5, -0.3125, -0.4375, 1.0625, -0.25, -0.375},
  39. {1.375, -0.5, 0.0625, 1.5, -0.0625, 0.1875},
  40. {1, 0.25, 0, 1.0625, 0.5, 0.0625},
  41. {0.5, 0.4375, 0, 1.0625, 0.5, 0.0625},
  42. {0.5, 0.0625, 0.125, 1.5, 0.1875, 0.1875},
  43. {1.375, -0.5, -0.3125, 1.5, -0.0625, -0.1875},
  44. }
  45. },
  46. selection_box = {
  47. type = "fixed",
  48. fixed = {
  49. {-0.5, -0.0625, -0.3125, 1.5, 0.0625, 0.1875},
  50. {-0.5, 0.125, -0.3125, 1.5, 0.1875, 0.125},
  51. {-0.5, 0.1875, -0.25, 1.5, 0.25, 0.125},
  52. {-0.5, -0.0625, -0.4375, 1.5, 0.0625, -0.3125},
  53. {0, -0.25, -0.4375, 0.0625, -0.0625, -0.375},
  54. {0, -0.3125, -0.4375, 1.0625, -0.25, -0.375},
  55. {-0.5, -0.5, 0.0625, -0.375, -0.0625, 0.1875},
  56. {0, 0.25, 0, 0.0625, 0.4375, 0.0625},
  57. {0, 0.4375, 0, 1.0625, 0.5, 0.0625},
  58. {-0.5, 0.0625, 0.125, 1.5, 0.1875, 0.1875},
  59. {-0.5, -0.5, -0.3125, -0.375, -0.0625, -0.1875},
  60. {1, -0.25, -0.4375, 1.0625, -0.0625, -0.375},
  61. {1.375, -0.5, 0.0625, 1.5, -0.0625, 0.1875},
  62. {1, 0.25, 0, 1.0625, 0.4375, 0.0625},
  63. {1.375, -0.5, -0.3125, 1.5, -0.0625, -0.1875},
  64. }
  65. },
  66. after_place_node = function(pos, placer)
  67. local meta = minetest.get_meta(pos);
  68. meta:set_string("owner", (placer:get_player_name() or ""));
  69. meta:set_string("infotext", "Eavestrough Machine is empty (owned by " .. (placer:get_player_name() or "") .. ")");
  70. end,
  71. can_dig = function(pos,player)
  72. local meta = minetest.env:get_meta(pos);
  73. local inv = meta:get_inventory()
  74. if not inv:is_empty("ingot") or
  75. not inv:is_empty("ingot2") or
  76. not inv:is_empty("res") then
  77. return false
  78. end
  79. return true
  80. end,
  81. on_construct = function(pos)
  82. local meta = minetest.get_meta(pos)
  83. meta:set_string("formspec", "invsize[10,11;]"..
  84. "background[-0.15,-0.25;10.40,11.75;mysheetmetal_background.png]"..
  85. "label[3,5;Steel Ingot:]"..
  86. "list[current_name;ingot;3,5.5;1,1;]"..
  87. "label[4.5,5;White Dye:]"..
  88. "list[current_name;ingot2;4.5,5.5;1,1;]"..
  89. "label[6.5,5;Output:]"..
  90. "list[current_name;res;6.5,5.5;1,1;]"..
  91. "label[0,0;Choose Eavestrough:]"..
  92. "label[0.5,0.5;Sheet Metal]"..
  93. "image_button[0.5,1;1,1;mysheetmetal_mach1.png;et; ]"..
  94. "image_button[1.5,1;1,1;mysheetmetal_mach2.png;etocorner; ]"..
  95. "image_button[2.5,1;1,1;mysheetmetal_mach3.png;eticorner; ]"..
  96. "image_button[3.5,1;1,1;mysheetmetal_mach4.png;etds; ]"..
  97. "image_button[4.5,1;1,1;mysheetmetal_mach5.png;ds; ]"..
  98. "image_button[5.5,1;1,1;mysheetmetal_mach6.png;etcapl; ]"..
  99. "image_button[6.5,1;1,1;mysheetmetal_mach7.png;etcapr; ]"..
  100. "label[0.5,2;Soffit]"..
  101. "image_button[0.5,2.5;1,1;mysheetmetal_mach8.png;soffit; ]"..
  102. "image_button[1.5,2.5;1,1;mysheetmetal_mach9.png;scorner; ]"..
  103. "image_button[2.5,2.5;1,1;mysheetmetal_mach10.png;scap; ]"..
  104. "image_button[3.5,2.5;1,1;mysheetmetal_mach11.png;scicorner; ]"..
  105. "image_button[4.5,2.5;1,1;mysheetmetal_mach12.png;scocorner; ]"..
  106. "label[0.5,3.5;Fascia]"..
  107. "image_button[0.5,4;1,1;mysheetmetal_mach13.png;fascia; ]"..
  108. "list[current_player;main;1,7;8,4;]")
  109. meta:set_string("infotext", "Sheet Metal Machine")
  110. local inv = meta:get_inventory()
  111. inv:set_size("ingot", 1)
  112. inv:set_size("ingot2", 1)
  113. inv:set_size("res", 1)
  114. end,
  115. on_receive_fields = function(pos, formname, fields, sender)
  116. local meta = minetest.get_meta(pos)
  117. local inv = meta:get_inventory()
  118. if fields["et"]
  119. or fields["etocorner"]
  120. or fields["eticorner"]
  121. or fields["etds"]
  122. or fields["ds"]
  123. or fields["etcapl"]
  124. or fields["etcapr"]
  125. or fields["soffit"]
  126. or fields["scorner"]
  127. or fields["scap"]
  128. or fields["scicorner"]
  129. or fields["scocorner"]
  130. or fields["fascia"]
  131. then
  132. if fields["et"] then
  133. make_ok = "0"
  134. anzahl = "4"
  135. shape = "mysheetmetal:eavestrough"
  136. if inv:is_empty("ingot") then
  137. return
  138. end
  139. end
  140. if fields["etocorner"] then
  141. make_ok = "0"
  142. anzahl = "6"
  143. shape = "mysheetmetal:eavestrough_ocorner"
  144. if inv:is_empty("ingot") then
  145. return
  146. end
  147. end
  148. if fields["eticorner"] then
  149. make_ok = "0"
  150. anzahl = "2"
  151. shape = "mysheetmetal:eavestrough_icorner"
  152. if inv:is_empty("ingot") then
  153. return
  154. end
  155. end
  156. if fields["etds"] then
  157. make_ok = "0"
  158. anzahl = "2"
  159. shape = "mysheetmetal:eavestrough_downspout"
  160. if inv:is_empty("ingot") then
  161. return
  162. end
  163. end
  164. if fields["ds"] then
  165. make_ok = "0"
  166. anzahl = "4"
  167. shape = "mysheetmetal:downspout"
  168. if inv:is_empty("ingot") then
  169. return
  170. end
  171. end
  172. if fields["etcapl"] then
  173. make_ok = "0"
  174. anzahl = "4"
  175. shape = "mysheetmetal:eavestrough_lc"
  176. if inv:is_empty("ingot") then
  177. return
  178. end
  179. end
  180. if fields["etcapr"] then
  181. make_ok = "0"
  182. anzahl = "4"
  183. shape = "mysheetmetal:eavestrough_rc"
  184. if inv:is_empty("ingot") then
  185. return
  186. end
  187. end
  188. if fields["soffit"] then
  189. make_ok = "0"
  190. anzahl = "2"
  191. shape = "mysheetmetal:soffit"
  192. if inv:is_empty("ingot") then
  193. return
  194. end
  195. end
  196. if fields["scorner"] then
  197. make_ok = "0"
  198. anzahl = "2"
  199. shape = "mysheetmetal:soffit_corner"
  200. if inv:is_empty("ingot") then
  201. return
  202. end
  203. end
  204. if fields["scap"] then
  205. make_ok = "0"
  206. anzahl = "6"
  207. shape = "mysheetmetal:soffit_cap"
  208. if inv:is_empty("ingot") then
  209. return
  210. end
  211. end
  212. if fields["scicorner"] then
  213. make_ok = "0"
  214. anzahl = "4"
  215. shape = "mysheetmetal:soffit_cap_icorner"
  216. if inv:is_empty("ingot") then
  217. return
  218. end
  219. end
  220. if fields["scocorner"] then
  221. make_ok = "0"
  222. anzahl = "8"
  223. shape = "mysheetmetal:soffit_cap_ocorner"
  224. if inv:is_empty("ingot") then
  225. return
  226. end
  227. end
  228. if fields["fascia"] then
  229. make_ok = "0"
  230. anzahl = "2"
  231. shape = "mysheetmetal:fascia"
  232. if inv:is_empty("ingot") then
  233. return
  234. end
  235. end
  236. local ingotstack = inv:get_stack("ingot", 1)
  237. local ingotstack2 = inv:get_stack("ingot2", 1)
  238. local resstack = inv:get_stack("res", 1)
  239. if ingotstack:get_name()=="default:steel_ingot" and
  240. ingotstack2:get_name()=="dye:white" then
  241. make_ok = "1"
  242. end
  243. if make_ok == "1" then
  244. local give = {}
  245. for i = 0, anzahl-1 do
  246. give[i+1]=inv:add_item("res",shape)
  247. end
  248. if not minetest.settings:get_bool("creative_mode") then
  249. ingotstack:take_item()
  250. ingotstack2:take_item()
  251. end
  252. inv:set_stack("ingot",1,ingotstack)
  253. inv:set_stack("ingot2",1,ingotstack2)
  254. end
  255. end
  256. end
  257. })
  258. --Craft
  259. minetest.register_craft({
  260. output = 'mysheetmetal:machine',
  261. recipe = {
  262. {'default:iron_lump', '', 'default:iron_lump'},
  263. {'default:wood', 'default:wood', 'default:wood'},
  264. {'default:wood', "default:wood", 'default:wood'},
  265. },
  266. })