drink_machines.lua 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. --Craft Recipes
  2. minetest.register_craft({
  3. output = 'drinks:juice_press',
  4. recipe = {
  5. {'default:stick', 'default:steel_ingot', 'default:stick'},
  6. {'default:stick', 'bucket:bucket_empty', 'default:stick'},
  7. {'stairs:slab_wood', 'stairs:slab_wood', 'vessels:drinking_glass'},
  8. }
  9. })
  10. minetest.register_craft({
  11. output = 'drinks:liquid_barrel',
  12. recipe = {
  13. {'group:wood', 'group:wood', 'group:wood'},
  14. {'group:wood', 'group:wood', 'group:wood'},
  15. {'stairs:slab_wood', '', 'stairs:slab_wood'},
  16. }
  17. })
  18. minetest.register_craft({
  19. output = 'drinks:liquid_silo',
  20. recipe = {
  21. {'drinks:liquid_barrel'},
  22. {'drinks:liquid_barrel'},
  23. {'drinks:liquid_barrel'}
  24. }
  25. })
  26. local press_idle_formspec =
  27. 'size[8,7]'..
  28. 'label[1.5,0;Organic juice is just a squish away.]' ..
  29. 'label[4.3,.75;Put fruit here ->]'..
  30. 'label[3.5,1.75;Put container here ->]'..
  31. 'label[0.2,1.8;4 fruits to a glass,]'..
  32. 'label[0.2,2.1;8 fruits to a bottle,]'..
  33. 'label[0.2,2.4;16 fruits to a bucket.]'..
  34. 'button[1,1;2,1;press;Start Juicing]'..
  35. 'list[current_name;src;6.5,.5;1,1;]'..
  36. 'list[current_name;dst;6.5,1.5;1,1;]'..
  37. 'list[current_player;main;0,3;8,4;]'
  38. local press_running_formspec =
  39. 'size[8,7]'..
  40. 'label[1.5,0;Organic juice coming right up.]' ..
  41. 'label[4.3,.75;Put fruit here ->]'..
  42. 'label[3.5,1.75;Put container here ->]'..
  43. 'label[0.2,1.8;4 fruits to a glass,]'..
  44. 'label[0.2,2.1;8 fruits to a bottle,]'..
  45. 'label[0.2,2.4;16 fruits to a bucket.]'..
  46. 'button[1,1;2,1;press;Start Juicing]'..
  47. 'list[current_name;src;6.5,.5;1,1;]'..
  48. 'list[current_name;dst;6.5,1.5;1,1;]'..
  49. 'list[current_player;main;0,3;8,4;]'
  50. local press_error_formspec =
  51. 'size[8,7]'..
  52. 'label[1.5,0;You need to add more fruit.]' ..
  53. 'label[4.3,.75;Put fruit here ->]'..
  54. 'label[3.5,1.75;Put container here ->]'..
  55. 'label[0.2,1.8;4 fruits to a glass,]'..
  56. 'label[0.2,2.1;8 fruits to a bottle,]'..
  57. 'label[0.2,2.4;16 fruits to a bucket.]'..
  58. 'button[1,1;2,1;press;Start Juicing]'..
  59. 'list[current_name;src;6.5,.5;1,1;]'..
  60. 'list[current_name;dst;6.5,1.5;1,1;]'..
  61. 'list[current_player;main;0,3;8,4;]'
  62. minetest.register_node('drinks:juice_press', {
  63. description = 'Juice Press',
  64. _doc_items_longdesc = "A machine for creating drinks out of various fruits and vegetables.",
  65. _doc_items_usagehelp = "Right-click the press to access inventory and begin juicing.",
  66. drawtype = 'mesh',
  67. mesh = 'drinks_press.obj',
  68. tiles = {'drinks_press.png'},
  69. use_texture_alpha = 'opaque',
  70. groups = {choppy=2, dig_immediate=2,},
  71. paramtype = 'light',
  72. paramtype2 = 'facedir',
  73. selection_box = {
  74. type = 'fixed',
  75. fixed = {-.5, -.5, -.5, .5, .5, .5},
  76. },
  77. collision_box = {
  78. type = 'fixed',
  79. fixed = {-.5, -.5, -.5, .5, .5, .5},
  80. },
  81. on_construct = function(pos)
  82. local meta = minetest.get_meta(pos)
  83. local inv = meta:get_inventory()
  84. inv:set_size('main', 8*4)
  85. inv:set_size('src', 1)
  86. inv:set_size('dst', 1)
  87. meta:set_string('infotext', 'Empty Juice Press')
  88. meta:set_string('formspec', press_idle_formspec)
  89. end,
  90. on_receive_fields = function(pos, formname, fields, sender)
  91. if fields ['press'] then
  92. local meta = minetest.get_meta(pos)
  93. local inv = meta:get_inventory()
  94. local timer = minetest.get_node_timer(pos)
  95. local instack = inv:get_stack("src", 1)
  96. local fruitstack = instack:get_name()
  97. local mod, fruit = fruitstack:match("([^:]+):([^:]+)")
  98. if drinks.juiceable[fruit] then
  99. local fruit_name = drinks.juice_name[fruit]
  100. meta:set_string('fruit', fruit_name)
  101. local outstack = inv:get_stack("dst", 1)
  102. local vessel = outstack:get_name()
  103. if vessel == 'vessels:drinking_glass' then
  104. if instack:get_count() >= 4 then
  105. meta:set_string('container', 'jcu_')
  106. meta:set_string('fruitnumber', 4)
  107. meta:set_string('infotext', 'Juicing...')
  108. meta:set_string('formspec', press_running_formspec)
  109. timer:start(4)
  110. else
  111. meta:set_string('infotext', 'You need more fruit.')
  112. meta:set_string('formspec', press_error_formspec)
  113. end
  114. elseif vessel == 'vessels:glass_bottle' then
  115. if instack:get_count() >= 8 then
  116. meta:set_string('container', 'jbo_')
  117. meta:set_string('fruitnumber', 8)
  118. meta:set_string('infotext', 'Juicing...')
  119. meta:set_string('formspec', press_running_formspec)
  120. timer:start(8)
  121. else
  122. meta:set_string('infotext', 'You need more fruit.')
  123. meta:set_string('formspec', press_error_formspec)
  124. end
  125. elseif vessel == 'vessels:steel_bottle' then
  126. if instack:get_count() >= 8 then
  127. meta:set_string('container', 'jsb_')
  128. meta:set_string('fruitnumber', 8)
  129. meta:set_string('infotext', 'Juicing...')
  130. meta:set_string('formspec', press_running_formspec)
  131. timer:start(8)
  132. else
  133. meta:set_string('infotext', 'You need more fruit.')
  134. meta:set_string('formspec', press_error_formspec)
  135. end
  136. elseif vessel == 'bucket:bucket_empty' then
  137. if instack:get_count() >= 16 then
  138. meta:set_string('container', 'jbu_')
  139. meta:set_string('fruitnumber', 16)
  140. meta:set_string('infotext', 'Juicing...')
  141. meta:set_string('formspec', press_running_formspec)
  142. timer:start(16)
  143. else
  144. meta:set_string('infotext', 'You need more fruit.')
  145. meta:set_string('formspec', press_error_formspec)
  146. end
  147. elseif vessel == 'default:papyrus' then
  148. if instack:get_count() >= 2 then
  149. local under_node = {x=pos.x, y=pos.y-1, z=pos.z}
  150. local under_node_name = minetest.get_node_or_nil(under_node)
  151. local under_node_2 = {x=pos.x, y=pos.y-2, z=pos.z}
  152. local under_node_name_2 = minetest.get_node_or_nil(under_node_2)
  153. if under_node_name.name == 'drinks:liquid_barrel' then
  154. local meta_u = minetest.get_meta(under_node)
  155. local stored_fruit = meta_u:get_string('fruit')
  156. if fruit == stored_fruit or stored_fruit == 'empty' then
  157. meta:set_string('container', 'tube')
  158. meta:set_string('fruitnumber', 2)
  159. meta:set_string('infotext', 'Juicing...')
  160. meta_u:set_string('fruit', fruit_name)
  161. timer:start(4)
  162. else
  163. meta:set_string('infotext', "You can't mix juices.")
  164. end
  165. elseif under_node_name_2.name == 'drinks:liquid_silo' then
  166. local meta_u = minetest.get_meta(under_node_2)
  167. local stored_fruit = meta_u:get_string('fruit')
  168. if fruit == stored_fruit or stored_fruit == 'empty' then
  169. meta:set_string('container', 'tube')
  170. meta:set_string('fruitnumber', 2)
  171. meta:set_string('infotext', 'Juicing...')
  172. meta_u:set_string('fruit', fruit_name)
  173. timer:start(4)
  174. else
  175. meta:set_string('infotext', "You can't mix juices.")
  176. end
  177. else
  178. meta:set_string('infotext', 'You need more fruit.')
  179. meta:set_string('formspec', press_error_formspec)
  180. end
  181. end
  182. end
  183. end
  184. end
  185. end,
  186. on_timer = function(pos)
  187. local meta = minetest.get_meta(pos)
  188. local inv = meta:get_inventory()
  189. local container = meta:get_string('container')
  190. local instack = inv:get_stack("src", 1)
  191. local outstack = inv:get_stack("dst", 1)
  192. local fruit = meta:get_string('fruit')
  193. local fruitnumber = tonumber(meta:get_string('fruitnumber'))
  194. if container == 'tube' then
  195. local timer = minetest.get_node_timer(pos)
  196. local under_node = {x=pos.x, y=pos.y-1, z=pos.z}
  197. local under_node_name = minetest.get_node_or_nil(under_node)
  198. local under_node_2 = {x=pos.x, y=pos.y-2, z=pos.z}
  199. local under_node_name_2 = minetest.get_node_or_nil(under_node_2)
  200. if under_node_name.name == 'drinks:liquid_barrel' then
  201. local meta_u = minetest.get_meta(under_node)
  202. local fullness = tonumber(meta_u:get_string('fullness'))
  203. instack:take_item(tonumber(fruitnumber))
  204. inv:set_stack('src', 1, instack)
  205. if fullness + 2 > 128 then
  206. timer:stop()
  207. meta:set_string('infotext', 'Barrel is full of juice.')
  208. return
  209. else
  210. local fullness = fullness + 2
  211. meta_u:set_string('fullness', fullness)
  212. meta_u:set_string('infotext', (math.floor((fullness/128)*100))..' % full of '..fruit..' juice.')
  213. meta_u:set_string('formspec', drinks.liquid_storage_formspec(fruit, fullness, 128))
  214. if instack:get_count() >= 2 then
  215. timer:start(4)
  216. else
  217. meta:set_string('infotext', 'You need more fruit.')
  218. end
  219. end
  220. elseif under_node_name_2.name == 'drinks:liquid_silo' then
  221. local meta_u = minetest.get_meta(under_node_2)
  222. local fullness = tonumber(meta_u:get_string('fullness'))
  223. instack:take_item(tonumber(fruitnumber))
  224. inv:set_stack('src', 1, instack)
  225. if fullness + 2 > 256 then
  226. timer:stop()
  227. meta:set_string('infotext', 'Silo is full of juice.')
  228. return
  229. else
  230. local fullness = fullness + 2
  231. meta_u:set_string('fullness', fullness)
  232. meta_u:set_string('infotext', (math.floor((fullness/256)*100))..' % full of '..fruit..' juice.')
  233. meta_u:set_string('formspec', drinks.liquid_storage_formspec(fruit, fullness, 256))
  234. if instack:get_count() >= 2 then
  235. timer:start(4)
  236. else
  237. meta:set_string('infotext', 'You need more fruit.')
  238. end
  239. end
  240. end
  241. else
  242. meta:set_string('infotext', 'Collect your juice.')
  243. meta:set_string('formspec', press_idle_formspec)
  244. instack:take_item(tonumber(fruitnumber))
  245. inv:set_stack('src', 1, instack)
  246. inv:set_stack('dst', 1 ,'drinks:'..container..fruit)
  247. end
  248. end,
  249. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  250. local timer = minetest.get_node_timer(pos)
  251. local meta = minetest.get_meta(pos)
  252. local inv = meta:get_inventory()
  253. timer:stop()
  254. meta:set_string('infotext', 'Ready for more juicing.')
  255. meta:set_string('formspec', press_idle_formspec)
  256. end,
  257. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  258. local meta = minetest.get_meta(pos)
  259. meta:set_string('infotext', 'Ready for juicing.')
  260. end,
  261. can_dig = function(pos)
  262. local meta = minetest.get_meta(pos);
  263. local inv = meta:get_inventory()
  264. if inv:is_empty("src") and
  265. inv:is_empty("dst") then
  266. return true
  267. else
  268. return false
  269. end
  270. end,
  271. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  272. if listname == 'dst' then
  273. local meta = minetest.get_meta(pos)
  274. local inv = meta:get_inventory()
  275. local outstack = inv:get_stack("dst", 1)
  276. local count = outstack:get_count()
  277. if count < 1 then
  278. if stack:get_name() == ('bucket:bucket_empty') then
  279. return 1
  280. elseif stack:get_name() == ('vessels:drinking_glass') then
  281. return 1
  282. elseif stack:get_name() == ('vessels:glass_bottle') then
  283. return 1
  284. elseif stack:get_name() == ('vessels:steel_bottle') then
  285. return 1
  286. elseif stack:get_name() == ('default:papyrus') then
  287. return 1
  288. else
  289. return 0
  290. end
  291. else
  292. return 0
  293. end
  294. else
  295. return 99
  296. end
  297. end,
  298. })
  299. function drinks.drinks_liquid_sub(liq_vol, ves_typ, ves_vol, pos, able_to_fill, leftover_count, outputstack)
  300. local meta = minetest.get_meta(pos)
  301. local fullness = tonumber(meta:get_string('fullness'))
  302. local fruit = meta:get_string('fruit')
  303. local fruit_name = meta:get_string('fruit_name')
  304. local inv = meta:get_inventory()
  305. local fullness = fullness - (liq_vol*able_to_fill)
  306. meta:set_string('fullness', fullness)
  307. meta:set_string('infotext', (math.floor((fullness/ves_vol)*100))..' % full of '..fruit_name..' juice.')
  308. if ves_vol == 128 then
  309. meta:set_string('formspec', drinks.liquid_storage_formspec(fruit_name, fullness, 128))
  310. elseif ves_vol == 256 then
  311. meta:set_string('formspec', drinks.liquid_storage_formspec(fruit_name, fullness, 256))
  312. end
  313. if ves_typ == 'jcu' or ves_typ == 'jbo' or ves_typ == 'jsb' or ves_typ == 'jbu' then
  314. inv:set_stack('dst', 1, 'drinks:'..ves_typ..'_'..fruit..' '..able_to_fill)
  315. inv:set_stack('src', 1, outputstack..' '..leftover_count)
  316. elseif ves_typ == 'thirsty:bronze_canteen' then
  317. inv:set_stack('dst', 1, {name="thirsty:bronze_canteen", count=1, wear=60, metadata=""})
  318. elseif ves_typ == 'thirsty:steel_canteen' then
  319. inv:set_stack('dst', 1, {name="thirsty:steel_canteen", count=1, wear=40, metadata=""})
  320. end
  321. end
  322. function drinks.drinks_liquid_avail_sub(liq_vol, ves_typ, ves_vol, outputstack, pos, count)
  323. local meta = minetest.get_meta(pos)
  324. local fullness = tonumber(meta:get_string('fullness'))
  325. if fullness - (liq_vol*count) < 0 then
  326. local able_to_fill = math.floor(fullness/liq_vol)
  327. local leftover_count = count - able_to_fill
  328. drinks.drinks_liquid_sub(liq_vol, ves_typ, ves_vol, pos, able_to_fill, leftover_count, outputstack)
  329. elseif fullness - (liq_vol*count) >= 0 then
  330. drinks.drinks_liquid_sub(liq_vol, ves_typ, ves_vol, pos, count, 0, outputstack)
  331. end
  332. end
  333. function drinks.drinks_liquid_add(liq_vol, ves_typ, ves_vol, pos, inputcount, leftover_count, inputstack)
  334. local meta = minetest.get_meta(pos)
  335. local fullness = tonumber(meta:get_string('fullness'))
  336. local fruit = meta:get_string('fruit')
  337. local fruit_name = meta:get_string('fruit_name')
  338. local inv = meta:get_inventory()
  339. local fullness = fullness + (liq_vol*inputcount)
  340. meta:set_string('fullness', fullness)
  341. inv:set_stack('src', 1, ves_typ..' '..inputcount)
  342. inv:set_stack('dst', 1, inputstack..' '..leftover_count)
  343. meta:set_string('infotext', (math.floor((fullness/ves_vol)*100))..' % full of '..fruit_name..' juice.')
  344. if ves_vol == 256 then
  345. meta:set_string('formspec', drinks.liquid_storage_formspec(fruit_name, fullness, 256))
  346. elseif ves_vol == 128 then
  347. meta:set_string('formspec', drinks.liquid_storage_formspec(fruit_name, fullness, 128))
  348. end
  349. end
  350. function drinks.drinks_liquid_avail_add(liq_vol, ves_typ, ves_vol, pos, inputstack, inputcount)
  351. local meta = minetest.get_meta(pos)
  352. local fullness = tonumber(meta:get_string('fullness'))
  353. if fullness + (liq_vol*inputcount) > ves_vol then
  354. local avail_ves_vol = ves_vol - fullness
  355. local can_empty = math.floor(avail_ves_vol/liq_vol)
  356. local leftover_count = inputcount - can_empty
  357. drinks.drinks_liquid_add(liq_vol, ves_typ, ves_vol, pos, can_empty, leftover_count, inputstack)
  358. elseif fullness + (liq_vol*inputcount) <= ves_vol then
  359. drinks.drinks_liquid_add(liq_vol, ves_typ, ves_vol, pos, inputcount, 0, inputstack)
  360. end
  361. end
  362. function drinks.drinks_barrel(pos, inputstack, inputcount)
  363. local meta = minetest.get_meta(pos)
  364. local vessel = string.sub(inputstack, 8, 10)
  365. drinks.drinks_liquid_avail_add(drinks.shortname[vessel].size, drinks.shortname[vessel].name, 128, pos, inputstack, inputcount)
  366. end
  367. function drinks.drinks_silo(pos, inputstack, inputcount)
  368. local meta = minetest.get_meta(pos)
  369. local vessel = string.sub(inputstack, 8, 10)
  370. drinks.drinks_liquid_avail_add(drinks.shortname[vessel].size, drinks.shortname[vessel].name, 256, pos, inputstack, inputcount)
  371. end
  372. minetest.register_node('drinks:liquid_barrel', {
  373. description = 'Barrel of Liquid',
  374. _doc_items_longdesc = "A node that provides a simple way to store juice.",
  375. _doc_items_usagehelp = "Add or remove liquids from the barrel using buckets, bottles, or cups.",
  376. drawtype = 'mesh',
  377. mesh = 'drinks_liquid_barrel.obj',
  378. tiles = {'drinks_barrel.png'},
  379. use_texture_alpha = 'opaque',
  380. groups = {choppy=2, dig_immediate=2,},
  381. paramtype = 'light',
  382. paramtype2 = 'facedir',
  383. selection_box = {
  384. type = 'fixed',
  385. fixed = {-.5, -.5, -.5, .5, .5, .5},
  386. },
  387. collision_box = {
  388. type = 'fixed',
  389. fixed = {-.5, -.5, -.5, .5, .5, .5},
  390. },
  391. on_construct = function(pos)
  392. local meta = minetest.get_meta(pos)
  393. local inv = meta:get_inventory()
  394. inv:set_size('main', 8*4)
  395. inv:set_size('src', 1)
  396. inv:set_size('dst', 1)
  397. meta:set_string('fullness', 0)
  398. meta:set_string('fruit', 'empty')
  399. meta:set_string('infotext', 'Empty Drink Barrel')
  400. meta:set_string('formspec', 'size[8,8]'..
  401. 'label[0,0;Fill with the drink of your choice,]'..
  402. 'label[0,.4;you can only add more of the same type of drink.]'..
  403. 'label[4.5,1.2;Add liquid ->]'..
  404. 'label[.75,1.75;The barrel is empty]'..
  405. 'label[4.5,2.25;Take liquid ->]'..
  406. 'label[2,3.2;(This empties the barrel completely)]'..
  407. 'button[0,3;2,1;purge;Purge]'..
  408. 'list[current_name;src;6.5,1;1,1;]'..
  409. 'list[current_name;dst;6.5,2;1,1;]'..
  410. 'list[current_player;main;0,4;8,5;]')
  411. end,
  412. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  413. local meta = minetest.get_meta(pos)
  414. local inv = meta:get_inventory()
  415. local instack = inv:get_stack('src', 1)
  416. local outstack = inv:get_stack('dst', 1)
  417. local outputstack = outstack:get_name()
  418. local inputstack = instack:get_name()
  419. local outputcount = outstack:get_count()
  420. local inputcount = instack:get_count()
  421. local fruit = string.sub(inputstack, 12, -1)
  422. local fruit_in = meta:get_string('fruit')
  423. if fruit_in == 'empty' then
  424. meta:set_string('fruit', fruit)
  425. local fruit_name = minetest.registered_nodes[instack:get_name()]
  426. meta:set_string('fruit_name', string.lower(fruit_name.juice_type))
  427. local vessel = string.sub(inputstack, 8, 10)
  428. drinks.drinks_barrel(pos, inputstack, inputcount)
  429. end
  430. if fruit == fruit_in then
  431. local vessel = string.sub(inputstack, 8, 10)
  432. drinks.drinks_barrel(pos, inputstack, inputcount)
  433. end
  434. if drinks.longname[outputstack] then
  435. drinks.drinks_liquid_avail_sub(drinks.longname[outputstack].size, drinks.longname[outputstack].name, 128, outputstack, pos, outputcount)
  436. end
  437. end,
  438. on_receive_fields = function(pos, formname, fields, sender)
  439. if fields['purge'] then
  440. local player_name = sender:get_player_name()
  441. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  442. return
  443. end
  444. local meta = minetest.get_meta(pos)
  445. local fullness = 0
  446. local fruit_name = 'no'
  447. meta:set_string('fullness', 0)
  448. meta:set_string('fruit', 'empty')
  449. meta:set_string('infotext', 'Empty Drink Barrel')
  450. meta:set_string('formspec', drinks.liquid_storage_formspec(fruit_name, fullness, 128))
  451. end
  452. end,
  453. can_dig = function(pos)
  454. local meta = minetest.get_meta(pos);
  455. local inv = meta:get_inventory()
  456. if inv:is_empty("src") and
  457. inv:is_empty("dst") and
  458. tonumber(meta:get_string('fullness')) == 0 then
  459. return true
  460. else
  461. return false
  462. end
  463. end,
  464. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  465. local meta = minetest.get_meta(pos)
  466. if minetest.is_protected(pos, player:get_player_name()) and not minetest.check_player_privs(player, 'protection_bypass') then
  467. return 0
  468. end
  469. if listname == 'src' then --adding liquid
  470. local inputstack = stack:get_name()
  471. local inputcount = stack:get_count()
  472. local valid = string.sub(inputstack, 1, 8)
  473. if valid == 'drinks:j' then
  474. return inputcount
  475. else
  476. return 0
  477. end
  478. elseif listname == 'dst' then --removing liquid
  479. --make sure there is a liquid to remove
  480. local juice = meta:get_string('fruit')
  481. if juice ~= 'empty' then
  482. local inputstack = stack:get_name()
  483. local inputcount = stack:get_count()
  484. local valid = string.sub(inputstack, 1, 7)
  485. if valid == 'vessels' or valid == 'bucket:' then
  486. return inputcount
  487. else
  488. return 0
  489. end
  490. else
  491. return 0
  492. end
  493. end
  494. end,
  495. })
  496. minetest.register_node('drinks:liquid_silo', {
  497. description = 'Silo of Liquid',
  498. _doc_items_longdesc = "A node that provides a simple way to store juice.",
  499. _doc_items_usagehelp = "Add or remove liquids from the silo using buckets, bottles, or cups.",
  500. drawtype = 'mesh',
  501. mesh = 'drinks_silo.obj',
  502. tiles = {'drinks_silo.png'},
  503. groups = {choppy=2, dig_immediate=2,},
  504. paramtype = 'light',
  505. paramtype2 = 'facedir',
  506. selection_box = {
  507. type = 'fixed',
  508. fixed = {-.5, -.5, -.5, .5, 1.5, .5},
  509. },
  510. collision_box = {
  511. type = 'fixed',
  512. fixed = {-.5, -.5, -.5, .5, 1.5, .5},
  513. },
  514. after_place_node = function(pos, placer, itemstack)
  515. if not epic.space_on_top(pos) then
  516. minetest.remove_node(pos)
  517. return itemstack
  518. end
  519. end,
  520. on_construct = function(pos)
  521. local meta = minetest.get_meta(pos)
  522. local inv = meta:get_inventory()
  523. inv:set_size('main', 8*4)
  524. inv:set_size('src', 1)
  525. inv:set_size('dst', 1)
  526. meta:set_string('fullness', 0)
  527. meta:set_string('fruit', 'empty')
  528. meta:set_string('infotext', 'Empty Drink Silo')
  529. meta:set_string('formspec', 'size[8,8]'..
  530. 'label[0,0;Fill with the drink of your choice,]'..
  531. 'label[0,.4;you can only add more of the same type of drink.]'..
  532. 'label[4.5,1.2;Add liquid ->]'..
  533. 'label[.75,1.75;The Silo is empty]'..
  534. 'label[4.5,2.25;Take liquid ->]'..
  535. 'label[2,3.2;(This empties the silo completely)]'..
  536. 'button[0,3;2,1;purge;Purge]'..
  537. 'list[current_name;src;6.5,1;1,1;]'..
  538. 'list[current_name;dst;6.5,2;1,1;]'..
  539. 'list[current_player;main;0,4;8,5;]')
  540. end,
  541. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  542. local meta = minetest.get_meta(pos)
  543. local inv = meta:get_inventory()
  544. local instack = inv:get_stack("src", 1)
  545. local outstack = inv:get_stack('dst', 1)
  546. local outputstack = outstack:get_name()
  547. local inputstack = instack:get_name()
  548. local outputcount = outstack:get_count()
  549. local inputcount = instack:get_count()
  550. local fruit = string.sub(inputstack, 12, -1)
  551. local fruit_in = meta:get_string('fruit')
  552. if fruit_in == 'empty' then
  553. meta:set_string('fruit', fruit)
  554. local fruit_name = minetest.registered_nodes[instack:get_name()]
  555. meta:set_string('fruit_name', string.lower(fruit_name.juice_type))
  556. local vessel = string.sub(inputstack, 8, 10)
  557. drinks.drinks_silo(pos, inputstack, inputcount)
  558. end
  559. if fruit == fruit_in then
  560. local vessel = string.sub(inputstack, 8, 10)
  561. drinks.drinks_silo(pos, inputstack, inputcount)
  562. end
  563. if drinks.longname[outputstack] then
  564. drinks.drinks_liquid_avail_sub(drinks.longname[outputstack].size, drinks.longname[outputstack].name, 256, outputstack, pos, outputcount)
  565. end
  566. end,
  567. on_receive_fields = function(pos, formname, fields, sender)
  568. local player_name = sender:get_player_name()
  569. if fields['purge'] then
  570. if minetest.is_protected(pos, player_name) and not minetest.check_player_privs(sender, 'protection_bypass') then
  571. return
  572. end
  573. local meta = minetest.get_meta(pos)
  574. local fullness = 0
  575. local fruit_name = 'no'
  576. meta:set_string('fullness', 0)
  577. meta:set_string('fruit', 'empty')
  578. meta:set_string('infotext', 'Empty Drink Silo')
  579. meta:set_string('formspec', drinks.liquid_storage_formspec(fruit_name, fullness, 256))
  580. end
  581. end,
  582. can_dig = function(pos)
  583. local meta = minetest.get_meta(pos);
  584. local inv = meta:get_inventory()
  585. if inv:is_empty("src") and
  586. inv:is_empty("dst") and
  587. tonumber(meta:get_string('fullness')) == 0 then
  588. return true
  589. else
  590. return false
  591. end
  592. end,
  593. after_dig_node = function(pos, oldnode, oldmetadata, digger)
  594. epic.remove_top_node(pos)
  595. end,
  596. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  597. local meta = minetest.get_meta(pos)
  598. if minetest.is_protected(pos, player:get_player_name()) and not minetest.check_player_privs(player, 'protection_bypass') then
  599. return 0
  600. end
  601. if listname == 'src' then --adding liquid
  602. local inputstack = stack:get_name()
  603. local inputcount = stack:get_count()
  604. local valid = string.sub(inputstack, 1, 8)
  605. if valid == 'drinks:j' then
  606. return inputcount
  607. else
  608. return 0
  609. end
  610. elseif listname == 'dst' then --removing liquid
  611. --make sure there is liquid to take_item
  612. local juice = meta:get_string('fruit')
  613. if juice ~= 'empty' then
  614. local inputstack = stack:get_name()
  615. local inputcount = stack:get_count()
  616. local valid = string.sub(inputstack, 1, 7)
  617. if valid == 'vessels' or valid == 'bucket:' then
  618. return inputcount
  619. else
  620. return 0
  621. end
  622. else
  623. return 0
  624. end
  625. end
  626. end,
  627. })