machines.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. local material = {}
  2. local shape = {}
  3. local make_ok = {}
  4. local anzahl = {}
  5. minetest.register_node("mymillwork:machine", {
  6. description = "Millwork Machine",
  7. tiles = {
  8. "mymillwork_machine_top.png",
  9. "mymillwork_machine_bottom.png",
  10. "mymillwork_machine_side2.png",
  11. "mymillwork_machine_side1.png",
  12. "mymillwork_machine_back.png",
  13. "mymillwork_machine_front.png"
  14. },
  15. drawtype = "nodebox",
  16. paramtype = "light",
  17. paramtype2 = "facedir",
  18. groups = {oddly_breakable_by_hand=2, cracky=3, dig_immediate=1},
  19. node_box = {
  20. type = "fixed",
  21. fixed = {
  22. {-0.5, -0.1875, -0.5, 0.5, -0.0625, 0.5},
  23. {-0.5, -0.5, -0.5, -0.3125, -0.1875, -0.3125},
  24. {-0.5, -0.5, 0.3125, -0.3125, -0.1875, 0.5},
  25. {0.3125, -0.5, 0.3125, 0.5, -0.1875, 0.5},
  26. {0.3125, -0.5, -0.5, 0.5, -0.1875, -0.3125},
  27. {0, -0.0625, 0.25, 0.0625, 0.375, 0.5},
  28. {-0.125, -0.0625, 0.25, -0.0625, 0.375, 0.5},
  29. {-0.1875, 0.125, -0.3125, 0.125, 0.5, 0.0625},
  30. {-0.125, 0.375, 0.0625, 0.0625, 0.5, 0.5},
  31. {-0.0625, 0.0625, -0.3125, 0, 0.125, 0.0625},
  32. {-0.0625, 0, -0.25, 0, 0.125, 0},
  33. }
  34. },
  35. after_place_node = function(pos, placer)
  36. local meta = minetest.get_meta(pos);
  37. meta:set_string("owner", (placer:get_player_name() or ""));
  38. meta:set_string("infotext", "Millwork Machine (owned by " .. (placer:get_player_name() or "") .. ")");
  39. end,
  40. can_dig = function(pos,player)
  41. local meta = minetest.get_meta(pos);
  42. local inv = meta:get_inventory()
  43. if not inv:is_empty("ingot") or
  44. not inv:is_empty("res") then
  45. return false
  46. end
  47. return true
  48. end,
  49. on_construct = function(pos)
  50. local meta = minetest.get_meta(pos)
  51. meta:set_string("formspec", "invsize[10,11;]"..
  52. "background[-0.15,-0.25;10.40,11.75;mymillwork_background.png]"..
  53. "list[current_name;ingot;7,5.5.5;1,1;]"..
  54. "list[current_name;res;8.5,5.5;1,1;]"..
  55. "label[7,5;Input:]"..
  56. "label[8.5,5;Output:]"..
  57. "label[0,0;Choose Millwork:]"..
  58. "label[0.5,0.5;Crown Mould]"..
  59. "image_button[0.5,1;1,1;mymillwork_mach1.png;crownmould; ]"..
  60. "image_button[1.5,1;1,1;mymillwork_mach2.png;crownmould_ic; ]"..
  61. "image_button[2.5,1;1,1;mymillwork_mach3.png;crownmould_oc; ]"..
  62. "image_button[3.5,1;1,1;mymillwork_mach4.png;crownmould_beam; ]"..
  63. "label[0.5,2;Columns]"..
  64. "image_button[0.5,2.5;1,1;mymillwork_mach5.png;column; ]"..
  65. "image_button[1.5,2.5;1,1;mymillwork_mach6.png;column_base; ]"..
  66. "image_button[2.5,2.5;1,1;mymillwork_mach7.png;column_half; ]"..
  67. "image_button[3.5,2.5;1,1;mymillwork_mach8.png;column_half_base; ]"..
  68. "image_button[4.5,2.5;1,1;mymillwork_mach9.png;column_half_wbeam; ]"..
  69. "image_button[5.5,2.5;1,1;mymillwork_mach10.png;column_quarter; ]"..
  70. "image_button[6.5,2.5;1,1;mymillwork_mach11.png;column_quarter_base; ]"..
  71. "image_button[7.5,2.5;1,1;mymillwork_mach12.png;column_quarter_wbase; ]"..
  72. "image_button[8.5,2.5;1,1;mymillwork_mach13.png;column_quarter_fancybase; ]"..
  73. "label[0.5,3.5;Ceiling and Beams]"..
  74. "image_button[0.5,4;1,1;mymillwork_mach14.png;ceiling; ]"..
  75. "image_button[1.5,4;1,1;mymillwork_mach15.png;ceiling_post; ]"..
  76. "image_button[2.5,4;1,1;mymillwork_mach16.png;beam; ]"..
  77. "image_button[3.5,4;1,1;mymillwork_mach17.png;beam_t; ]"..
  78. "image_button[4.5,4;1,1;mymillwork_mach18.png;beam_ceiling_t; ]"..
  79. "label[0.5,5;Base]"..
  80. "image_button[0.5,5.5;1,1;mymillwork_mach19.png;base; ]"..
  81. "image_button[1.5,5.5;1,1;mymillwork_mach20.png;base_ic; ]"..
  82. "image_button[2.5,5.5;1,1;mymillwork_mach21.png;base_oc; ]"..
  83. "image_button[3.5,5.5;1,1;mymillwork_mach22.png;base_fancy; ]"..
  84. "image_button[4.5,5.5;1,1;mymillwork_mach23.png;base_fancy_ic; ]"..
  85. "image_button[5.5,5.5;1,1;mymillwork_mach24.png;base_fancy_oc; ]"..
  86. "list[current_player;main;1,7;8,4;]")
  87. meta:set_string("infotext", "Millwork Machine")
  88. local inv = meta:get_inventory()
  89. inv:set_size("ingot", 1)
  90. inv:set_size("res", 1)
  91. end,
  92. on_receive_fields = function(pos, formname, fields, sender)
  93. local meta = minetest.get_meta(pos)
  94. local inv = meta:get_inventory()
  95. if fields["crownmould"]
  96. or fields["crownmould_ic"]
  97. or fields["crownmould_oc"]
  98. or fields["crownmould_beam"]
  99. or fields["column"]
  100. or fields["column_base"]
  101. or fields["column_half"]
  102. or fields["column_half_base"]
  103. or fields["column_half_wbeam"]
  104. or fields["column_quarter"]
  105. or fields["column_quarter_base"]
  106. or fields["column_quarter_wbase"]
  107. or fields["column_quarter_fancybase"]
  108. or fields["ceiling"]
  109. or fields["ceiling_post"]
  110. or fields["beam"]
  111. or fields["beam_t"]
  112. or fields["beam_ceiling_t"]
  113. or fields["base"]
  114. or fields["base_ic"]
  115. or fields["base_oc"]
  116. or fields["base_fancy"]
  117. or fields["base_fancy_ic"]
  118. or fields["base_fancy_oc"]
  119. then
  120. if inv:is_empty("ingot") then
  121. return
  122. end
  123. --Crown Mould
  124. if fields["crownmould"] then
  125. make_ok = "0"
  126. anzahl = "1"
  127. shape = "mymillwork:crownmould_"
  128. elseif fields["crownmould_ic"] then
  129. make_ok = "0"
  130. anzahl = "1"
  131. shape = "mymillwork:crownmould_ic_"
  132. elseif fields["crownmould_oc"] then
  133. make_ok = "0"
  134. anzahl = "1"
  135. shape = "mymillwork:crownmould_oc_"
  136. elseif fields["crownmould_beam"] then
  137. make_ok = "0"
  138. anzahl = "1"
  139. shape = "mymillwork:crownmould_beam_"
  140. --Columns
  141. elseif fields["column"] then
  142. make_ok = "0"
  143. anzahl = "1"
  144. shape = "mymillwork:column_"
  145. elseif fields["column_base"] then
  146. make_ok = "0"
  147. anzahl = "1"
  148. shape = "mymillwork:column_base_"
  149. elseif fields["column_half"] then
  150. make_ok = "0"
  151. anzahl = "2"
  152. shape = "mymillwork:column_half_"
  153. elseif fields["column_half_base"] then
  154. make_ok = "0"
  155. anzahl = "2"
  156. shape = "mymillwork:column_half_base_"
  157. elseif fields["column_half_wbeam"] then
  158. make_ok = "0"
  159. anzahl = "1"
  160. shape = "mymillwork:column_half_wbeam_"
  161. elseif fields["column_quarter"] then
  162. make_ok = "0"
  163. anzahl = "4"
  164. shape = "mymillwork:column_quarter_"
  165. elseif fields["column_quarter_base"] then
  166. make_ok = "0"
  167. anzahl = "4"
  168. shape = "mymillwork:column_quarter_base_"
  169. elseif fields["column_quarter_wbase"] then
  170. make_ok = "0"
  171. anzahl = "2"
  172. shape = "mymillwork:column_quarter_wbase_"
  173. elseif fields["column_quarter_fancybase"] then
  174. make_ok = "0"
  175. anzahl = "2"
  176. shape = "mymillwork:column_quarter_fancybase_"
  177. --Ceiling
  178. elseif fields["ceiling"] then
  179. make_ok = "0"
  180. anzahl = "6"
  181. shape = "mymillwork:ceiling_"
  182. elseif fields["ceiling_post"] then
  183. make_ok = "0"
  184. anzahl = "4"
  185. shape = "mymillwork:ceiling_post_"
  186. --Beam
  187. elseif fields["beam"] then
  188. make_ok = "0"
  189. anzahl = "2"
  190. shape = "mymillwork:beam_"
  191. elseif fields["beam_t"] then
  192. make_ok = "0"
  193. anzahl = "2"
  194. shape = "mymillwork:beam_t_"
  195. elseif fields["beam_ceiling_t"] then
  196. make_ok = "0"
  197. anzahl = "2"
  198. shape = "mymillwork:beam_ceiling_t_"
  199. --Base
  200. elseif fields["base"] then
  201. make_ok = "0"
  202. anzahl = "8"
  203. shape = "mymillwork:base_"
  204. elseif fields["base_ic"] then
  205. make_ok = "0"
  206. anzahl = "4"
  207. shape = "mymillwork:base_ic_"
  208. elseif fields["base_oc"] then
  209. make_ok = "0"
  210. anzahl = "10"
  211. shape = "mymillwork:base_oc_"
  212. elseif fields["base_fancy"] then
  213. make_ok = "0"
  214. anzahl = "6"
  215. shape = "mymillwork:base_fancy_"
  216. elseif fields["base_fancy_ic"] then
  217. make_ok = "0"
  218. anzahl = "3"
  219. shape = "mymillwork:base_fancy_ic_"
  220. elseif fields["base_fancy_oc"] then
  221. make_ok = "0"
  222. anzahl = "8"
  223. shape = "mymillwork:base_fancy_oc_"
  224. end
  225. local ingotstack = inv:get_stack("ingot", 1)
  226. local resstack = inv:get_stack("res", 1)
  227. for i in ipairs(mymillwork.registered) do
  228. local itm = mymillwork.registered[i][1]
  229. local mat = mymillwork.registered[i][2]
  230. if ingotstack:get_name()== itm then
  231. material = mat
  232. make_ok = "1"
  233. end
  234. end
  235. if make_ok == "1" then
  236. local give = {}
  237. for i = 0, anzahl-1 do
  238. give[i+1]=inv:add_item("res",shape..material)
  239. end
  240. if not minetest.setting_getbool("creative_mode") then
  241. ingotstack:take_item()
  242. end
  243. inv:set_stack("ingot",1,ingotstack)
  244. end
  245. end
  246. end
  247. })
  248. --Craft
  249. minetest.register_craft({
  250. output = 'mymillwork:machine',
  251. recipe = {
  252. {'', 'default:steel_ingot',''},
  253. {'default:steelblock', 'default:steelblock', 'default:steelblock'},
  254. {'default:steel_ingot','' , 'default:steel_ingot'},
  255. },
  256. })