machine.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. local material = {}
  2. local block = {}
  3. local make_ok = false
  4. local anzahl = 0
  5. local material2 = {}
  6. local stone = {}
  7. local deco = {}
  8. local color_tab = {
  9. {'black', 'Black', 'dye:black'},
  10. {'blue', 'Blue', 'dye:blue'},
  11. {'brown', 'Brown', 'dye:brown'},
  12. {'cyan', 'Cyan', 'dye:cyan'},
  13. {'dark_green', 'Dark Green', 'dye:dark_green'},
  14. {'dark_grey', 'Dark Grey', 'dye:dark_grey'},
  15. {'green', 'Green', 'dye:green'},
  16. {'grey', 'Grey', 'dye:grey'},
  17. {'magenta', 'Magenta', 'dye:magenta'},
  18. {'orange', 'Orange', 'dye:orange'},
  19. {'pink', 'Pink', 'dye:pink'},
  20. {'red', 'Red', 'dye:red'},
  21. {'violet', 'Violet', 'dye:violet'},
  22. {'white', 'White', 'dye:white'},
  23. {'yellow', 'Yellow', 'dye:yellow'},
  24. {'cement', '', ''},
  25. }
  26. minetest.register_node('mylandscaping:machine', {
  27. description = 'Concrete Forms',
  28. drawtype = 'mesh',
  29. mesh = 'mylandscaping_cement_mixer.obj',
  30. tiles = {
  31. {name='mylandscaping_tex3.png'},{name='mylandscaping_tex1.png'},
  32. {name='default_gravel.png'},{name='mylandscaping_tex2.png'}},
  33. groups = {oddly_breakable_by_hand=2},
  34. paramtype = 'light',
  35. paramtype2 = 'facedir',
  36. selection_box = {
  37. type = 'fixed',
  38. fixed = {
  39. {-0.5, -0.5, -0.5, 1.1, 0.5, 0.5},
  40. {1.1, -0.5, -0.1, 1.5, -0.3, 0.5}
  41. }
  42. },
  43. collision_box = {
  44. type = 'fixed',
  45. fixed = {
  46. {-0.5, -0.5, -0.5, 1.1, 0.5, 0.5},
  47. {1.1, -0.5, -0.1, 1.5, -0.3, 0.5}
  48. }
  49. },
  50. can_dig = function(pos,player)
  51. local meta = minetest.get_meta(pos);
  52. local inv = meta:get_inventory()
  53. if player:get_player_name() == meta:get_string('owner') and
  54. inv:is_empty('input') and
  55. inv:is_empty('dye') and
  56. inv:is_empty('output') then
  57. return true
  58. else
  59. return false
  60. end
  61. end,
  62. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  63. local input = stack:get_name()
  64. if listname == 'input' then
  65. if input == 'mylandscaping:concrete' or input == 'mylandscaping:concrete_bag' then
  66. return 99
  67. else
  68. return 0
  69. end
  70. elseif listname == 'dye' then
  71. if minetest.get_item_group(input, 'dye') > 0 then
  72. return 99
  73. else
  74. return 0
  75. end
  76. elseif listname == 'output' then
  77. return 0
  78. end
  79. end,
  80. after_place_node = function(pos, placer, itemstack)
  81. if not epic.space_to_side(pos) then
  82. minetest.remove_node(pos)
  83. return itemstack
  84. else
  85. local meta = minetest.get_meta(pos)
  86. meta:set_string('owner',placer:get_player_name())
  87. meta:set_string('infotext','Concrete Mixer (owned by '..placer:get_player_name()..')')
  88. end
  89. end,
  90. after_dig_node = function(pos, oldnode)
  91. epic.remove_side_node(pos, oldnode)
  92. end,
  93. on_construct = function(pos)
  94. local meta = minetest.get_meta(pos)
  95. meta:set_string('formspec', retaining_walls)
  96. meta:set_string('infotext', 'Concrete Mixer')
  97. local inv = meta:get_inventory()
  98. inv:set_size('input', 1)
  99. inv:set_size('output', 1)
  100. inv:set_size('dye', 1)
  101. end,
  102. on_receive_fields = function(pos, formname, fields, sender)
  103. local meta = minetest.get_meta(pos)
  104. local inv = meta:get_inventory()
  105. if fields['retain'] then
  106. meta:set_string('formspec', retaining_walls)
  107. elseif fields['patio'] then
  108. meta:set_string('formspec', patio_pavers)
  109. elseif fields['deco'] then
  110. meta:set_string('formspec', deco_walls)
  111. elseif fields['column'] then
  112. meta:set_string('formspec', columns)
  113. end
  114. for i in ipairs (color_tab) do
  115. local col = color_tab[i][1]
  116. local coldesc = color_tab[i][2]
  117. local dyecol = color_tab[i][3]
  118. if fields['awall1']
  119. or fields['awall2']
  120. or fields['awall3']
  121. or fields['awall4']
  122. or fields['awall5']
  123. then
  124. if fields['awall1'] then
  125. make_ok = false
  126. anzahl = 2
  127. block = 'mylandscaping:awall_left_'
  128. if inv:is_empty('input') then
  129. return
  130. end
  131. end
  132. if fields['awall2'] then
  133. make_ok = false
  134. anzahl = 2
  135. block = 'mylandscaping:awall_middle_'
  136. if inv:is_empty('input') then
  137. return
  138. end
  139. end
  140. if fields['awall3'] then
  141. make_ok = false
  142. anzahl = 2
  143. block = 'mylandscaping:awall_right_'
  144. if inv:is_empty('input') then
  145. return
  146. end
  147. end
  148. if fields['awall4'] then
  149. make_ok = false
  150. anzahl = 2
  151. block = 'mylandscaping:awall_icorner_'
  152. if inv:is_empty('input') then
  153. return
  154. end
  155. end
  156. if fields['awall5'] then
  157. make_ok = false
  158. anzahl = 2
  159. block = 'mylandscaping:awall_ocorner_'
  160. if inv:is_empty('input') then
  161. return
  162. end
  163. end
  164. local instack = inv:get_stack('input', 1)
  165. local outstack = inv:get_stack('output', 1)
  166. local dyestack = inv:get_stack('dye', 1)
  167. ---------------------------------------------------------------------
  168. if instack:get_name()== 'mylandscaping:concrete_bag' and dyestack:get_name()== dyecol
  169. or instack:get_name()== 'mylandscaping:concrete' and dyestack:get_name()== dyecol then
  170. material = col
  171. make_ok = true
  172. end
  173. ---------------------------------------------------------------------
  174. if make_ok == true then
  175. local give = {}
  176. if inv:room_for_item('output', block..col) then
  177. inv:add_item('output', block..col..' '..anzahl)
  178. instack:take_item()
  179. inv:set_stack('input',1,instack)
  180. if dyestack:get_name() == 'dye:'..col then
  181. dyestack:take_item()
  182. inv:set_stack('dye',1,dyestack)
  183. end
  184. end
  185. end
  186. end
  187. ---------------------------------------------------------------------
  188. if fields['fwall1']
  189. or fields['fwall2']
  190. or fields['fwall3']
  191. or fields['fwall4']
  192. then
  193. if fields['fwall1'] then
  194. make_ok = false
  195. anzahl = 2
  196. block = 'mylandscaping:fwall_left_'
  197. if inv:is_empty('input') then
  198. return
  199. end
  200. end
  201. if fields['fwall2'] then
  202. make_ok = false
  203. anzahl = 2
  204. block = 'mylandscaping:fwall_middle_'
  205. if inv:is_empty('input') then
  206. return
  207. end
  208. end
  209. if fields['fwall3'] then
  210. make_ok = false
  211. anzahl = 2
  212. block = 'mylandscaping:fwall_right_'
  213. if inv:is_empty('input') then
  214. return
  215. end
  216. end
  217. if fields['fwall4'] then
  218. make_ok = false
  219. anzahl = 2
  220. block = 'mylandscaping:fwall_corner_'
  221. if inv:is_empty('input') then
  222. return
  223. end
  224. end
  225. local instack = inv:get_stack('input', 1)
  226. local outstack = inv:get_stack('output', 1)
  227. local dyestack = inv:get_stack('dye', 1)
  228. ---------------------------------------------------------------------
  229. if instack:get_name()== 'mylandscaping:concrete_bag' and dyestack:get_name()== dyecol
  230. or instack:get_name()== 'mylandscaping:concrete' and dyestack:get_name()== dyecol then
  231. material = col
  232. make_ok = true
  233. end
  234. ---------------------------------------------------------------------
  235. if make_ok == true then
  236. local give = {}
  237. if inv:room_for_item('output', block..col) then
  238. inv:add_item('output', block..col..' '..anzahl)
  239. instack:take_item()
  240. inv:set_stack('input',1,instack)
  241. if dyestack:get_name() == 'dye:'..col then
  242. dyestack:take_item()
  243. inv:set_stack('dye',1,dyestack)
  244. end
  245. end
  246. end
  247. end
  248. ---------------------------------------------------------------------
  249. if fields['mwall1']
  250. or fields['mwall2']
  251. or fields['mwall3']
  252. then
  253. if fields['mwall1'] then
  254. make_ok = false
  255. anzahl = 2
  256. block = 'mylandscaping:mwall_middle_'
  257. if inv:is_empty('input') then
  258. return
  259. end
  260. end
  261. if fields['mwall2'] then
  262. make_ok = false
  263. anzahl = 2
  264. block = 'mylandscaping:mwall_icorner_'
  265. if inv:is_empty('input') then
  266. return
  267. end
  268. end
  269. if fields['mwall3'] then
  270. make_ok = false
  271. anzahl = 2
  272. block = 'mylandscaping:mwall_ocorner_'
  273. if inv:is_empty('input') then
  274. return
  275. end
  276. end
  277. local instack = inv:get_stack('input', 1)
  278. local outstack = inv:get_stack('output', 1)
  279. local dyestack = inv:get_stack('dye', 1)
  280. ---------------------------------------------------------------------
  281. if instack:get_name()== 'mylandscaping:concrete_bag' and dyestack:get_name()== dyecol
  282. or instack:get_name()== 'mylandscaping:concrete' and dyestack:get_name()== dyecol then
  283. material = col
  284. make_ok = true
  285. end
  286. ---------------------------------------------------------------------
  287. if make_ok == true then
  288. local give = {}
  289. if inv:room_for_item('output', block..col) then
  290. inv:add_item('output', block..col..' '..anzahl)
  291. instack:take_item()
  292. inv:set_stack('input',1,instack)
  293. if dyestack:get_name() == 'dye:'..col then
  294. dyestack:take_item()
  295. inv:set_stack('dye',1,dyestack)
  296. end
  297. end
  298. end
  299. end
  300. ---------------------------------------------------------------------
  301. --all columns here, possible decorative caps too.
  302. if fields['acolumn1']
  303. or fields['acolumn2']
  304. or fields['acolumn3']
  305. or fields['fcolumn1']
  306. or fields['fcolumn2']
  307. or fields['fcolumn3']
  308. or fields['mcolumn1']
  309. or fields['mcolumn2']
  310. or fields['mcolumn3']
  311. or fields['column_sphere']
  312. or fields['column_dragon']
  313. or fields['column_suzanne']
  314. or fields['column_cross']
  315. then
  316. if fields['acolumn1'] then
  317. make_ok = false
  318. anzahl = 1
  319. block = 'mylandscaping:awall_column_m_t_'
  320. if inv:is_empty('input') then
  321. return
  322. end
  323. end
  324. if fields['acolumn2'] then
  325. make_ok = false
  326. anzahl = 1
  327. block = 'mylandscaping:awall_column_ic_t_'
  328. if inv:is_empty('input') then
  329. return
  330. end
  331. end
  332. if fields['acolumn3'] then
  333. make_ok = false
  334. anzahl = 1
  335. block = 'mylandscaping:awall_column_oc_t_'
  336. if inv:is_empty('input') then
  337. return
  338. end
  339. end
  340. if fields['fcolumn1'] then
  341. make_ok = false
  342. anzahl = 1
  343. block = 'mylandscaping:fwall_column_m_t_'
  344. if inv:is_empty('input') then
  345. return
  346. end
  347. end
  348. if fields['fcolumn2'] then
  349. make_ok = false
  350. anzahl = 1
  351. block = 'mylandscaping:fwall_column_ic_t_'
  352. if inv:is_empty('input') then
  353. return
  354. end
  355. end
  356. if fields['fcolumn3'] then
  357. make_ok = false
  358. anzahl = 1
  359. block = 'mylandscaping:fwall_column_oc_t_'
  360. if inv:is_empty('input') then
  361. return
  362. end
  363. end
  364. if fields['column_sphere'] then
  365. make_ok = false
  366. anzahl = 2
  367. block = 'mylandscaping:column_t_sphere_'
  368. if inv:is_empty('input') then
  369. return
  370. end
  371. end
  372. if fields['column_dragon'] then
  373. make_ok = false
  374. anzahl = 1
  375. block = 'mylandscaping:column_t_dragon_'
  376. if inv:is_empty('input') then
  377. return
  378. end
  379. end
  380. if fields['column_suzanne'] then
  381. make_ok = false
  382. anzahl = 2
  383. block = 'mylandscaping:column_t_suzanne_'
  384. if inv:is_empty('input') then
  385. return
  386. end
  387. end
  388. if fields['column_cross'] then
  389. make_ok = false
  390. anzahl = 2
  391. block = 'mylandscaping:column_t_cross_'
  392. if inv:is_empty('input') then
  393. return
  394. end
  395. end
  396. local instack = inv:get_stack('input', 1)
  397. local outstack = inv:get_stack('output', 1)
  398. local dyestack = inv:get_stack('dye', 1)
  399. ---------------------------------------------------------------------
  400. if instack:get_name()== 'mylandscaping:concrete_bag' and dyestack:get_name()== dyecol
  401. or instack:get_name()== 'mylandscaping:concrete' and dyestack:get_name()== dyecol then
  402. material = col
  403. make_ok = true
  404. end
  405. if make_ok == true then
  406. local give = {}
  407. if inv:room_for_item('output', block..col) then
  408. inv:add_item('output', block..col..' '..anzahl)
  409. instack:take_item()
  410. inv:set_stack('input',1,instack)
  411. if dyestack:get_name() == 'dye:'..col then
  412. dyestack:take_item()
  413. inv:set_stack('dye',1,dyestack)
  414. end
  415. end
  416. end
  417. end
  418. if fields['patio1']
  419. or fields['patio2']
  420. or fields['patio3']
  421. or fields['patio4']
  422. or fields['patio5']
  423. or fields['patio6']
  424. or fields['patio7']
  425. then
  426. if fields['patio1'] then
  427. make_ok = false
  428. anzahl = 3
  429. stone = 'mylandscaping:stone_square'
  430. if inv:is_empty('input') then
  431. return
  432. end
  433. end
  434. if fields['patio2'] then
  435. make_ok = false
  436. anzahl = 3
  437. stone = 'mylandscaping:stone_square_sm'
  438. if inv:is_empty('input') then
  439. return
  440. end
  441. end
  442. if fields['patio7'] then
  443. make_ok = false
  444. anzahl = 3
  445. stone = 'mylandscaping:stone_square_xsm'
  446. if inv:is_empty('input') then
  447. return
  448. end
  449. end
  450. if fields['patio3'] then
  451. make_ok = false
  452. anzahl = 3
  453. stone = 'mylandscaping:stone_pavers'
  454. if inv:is_empty('input') then
  455. return
  456. end
  457. end
  458. if fields['patio4'] then
  459. make_ok = false
  460. anzahl = 3
  461. stone = 'mylandscaping:stone_ashlar'
  462. if inv:is_empty('input') then
  463. return
  464. end
  465. end
  466. if fields['patio5'] then
  467. make_ok = false
  468. anzahl = 3
  469. stone = 'mylandscaping:stone_flagstone'
  470. if inv:is_empty('input') then
  471. return
  472. end
  473. end
  474. if fields['patio6'] then
  475. make_ok = false
  476. anzahl = 3
  477. stone = 'mylandscaping:stone_pinwheel'
  478. if inv:is_empty('input') then
  479. return
  480. end
  481. end
  482. local instack = inv:get_stack('input', 1)
  483. local outstack = inv:get_stack('output', 1)
  484. local dyestack = inv:get_stack('dye', 1)
  485. if instack:get_name()== 'mylandscaping:concrete_bag' and dyestack:get_name()== dyecol
  486. or instack:get_name()== 'mylandscaping:concrete' and dyestack:get_name()== dyecol then
  487. make_ok = true
  488. end
  489. ---------------------------------------------------------------------
  490. if make_ok == true then
  491. local give = {}
  492. if inv:room_for_item('output', stone..col) then
  493. inv:add_item('output', stone..col..' '..anzahl)
  494. instack:take_item()
  495. inv:set_stack('input',1,instack)
  496. if dyestack:get_name() == 'dye:'..col then
  497. dyestack:take_item()
  498. inv:set_stack('dye',1,dyestack)
  499. end
  500. end
  501. end
  502. end
  503. ---------------------------------------------------------------------
  504. if fields['deco1']
  505. or fields['deco2']
  506. or fields['deco3']
  507. or fields['deco4']
  508. or fields['deco5']
  509. then
  510. if fields['deco1'] then
  511. make_ok = false
  512. anzahl = 4
  513. deco = 'mylandscaping:deco_wall_s_'
  514. if inv:is_empty('input') then
  515. return
  516. end
  517. end
  518. if fields['deco2'] then
  519. make_ok = false
  520. anzahl = 4
  521. deco = 'mylandscaping:deco_wall_f_'
  522. if inv:is_empty('input') then
  523. return
  524. end
  525. end
  526. if fields['deco3'] then
  527. make_ok = false
  528. anzahl = 4
  529. deco = 'mylandscaping:deco_wall_p_'
  530. if inv:is_empty('input') then
  531. return
  532. end
  533. end
  534. if fields['deco4'] then
  535. make_ok = false
  536. anzahl = 4
  537. deco = 'mylandscaping:deco_wall_r_'
  538. if inv:is_empty('input') then
  539. return
  540. end
  541. end
  542. if fields['deco5'] then
  543. make_ok = false
  544. anzahl = 4
  545. deco = 'mylandscaping:deco_column_'
  546. if inv:is_empty('input') then
  547. return
  548. end
  549. end
  550. local instack = inv:get_stack('input', 1)
  551. local outstack = inv:get_stack('output', 1)
  552. local dyestack = inv:get_stack('dye', 1)
  553. if instack:get_name()== 'mylandscaping:concrete_bag' and dyestack:get_name()== dyecol
  554. or instack:get_name()== 'mylandscaping:concrete' and dyestack:get_name()== dyecol then
  555. make_ok = true
  556. end
  557. ---------------------------------------------------------------------
  558. if make_ok == true then
  559. local give = {}
  560. if inv:room_for_item('output', deco..col) then
  561. inv:add_item('output', deco..col..' '..anzahl)
  562. instack:take_item()
  563. inv:set_stack('input',1,instack)
  564. if dyestack:get_name() == 'dye:'..col then
  565. dyestack:take_item()
  566. inv:set_stack('dye',1,dyestack)
  567. end
  568. end
  569. end
  570. end
  571. end
  572. end
  573. })