init.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. local def = minetest.get_modpath("default")
  2. wine = {
  3. snd_d = def and default.node_sound_defaults(),
  4. snd_g = def and default.node_sound_glass_defaults(),
  5. snd_l = def and default.node_sound_leaves_defaults(),
  6. sand = "default:desert_sand"
  7. }
  8. -- check for MineClone2
  9. local mcl = minetest.get_modpath("mcl_core")
  10. if mcl then
  11. wine.snd_d = mcl_sounds.node_sound_glass_defaults()
  12. wine.snd_g = mcl_sounds.node_sound_defaults()
  13. wine.snd_l = mcl_sounds.node_sound_leaves_defaults()
  14. wine.sand = "mcl_core:sand"
  15. end
  16. -- check for Unified Inventory
  17. local is_uninv = minetest.global_exists("unified_inventory") or false
  18. -- Intllib
  19. local S
  20. if minetest.get_modpath("intllib") then
  21. S = intllib.Getter()
  22. else
  23. S = function(s, a, ...)
  24. if a == nil then
  25. return s
  26. end
  27. a = {a, ...}
  28. return s:gsub("(@?)@(%(?)(%d+)(%)?)",
  29. function(e, o, n, c)
  30. if e == ""then
  31. return a[tonumber(n)] .. (o == "" and c or "")
  32. else
  33. return "@" .. o .. n .. c
  34. end
  35. end)
  36. end
  37. end
  38. -- Unified Inventory hints
  39. if is_uninv then
  40. unified_inventory.register_craft_type("barrel", {
  41. description = "Barrel",
  42. icon = 'wine_barrel.png',
  43. width = 1,
  44. height = 1,
  45. })
  46. end
  47. local ferment = {
  48. {"farming:grapes", "wine:glass_wine"},
  49. {"farming:barley", "wine:glass_beer"},
  50. {"mobs:honey", "wine:glass_mead"},
  51. {"default:apple", "wine:glass_cider"},
  52. {"default:papyrus", "wine:glass_rum"},
  53. {"wine:blue_agave", "wine:glass_tequila"},
  54. {"farming:wheat", "wine:glass_wheat_beer"},
  55. {"farming:rice", "wine:glass_sake"},
  56. {"farming:corn", "wine:glass_bourbon"},
  57. {"farming:baked_potato", "wine:glass_vodka"}
  58. }
  59. if mcl then
  60. ferment[4] = {"mcl_core:apple", "wine:glass_cider"}
  61. ferment[5] = {"mcl_core:paper", "wine:glass_rum"}
  62. end
  63. if is_uninv then
  64. for _, f in pairs(ferment) do
  65. unified_inventory.register_craft({
  66. type = "barrel",
  67. items = { f[1] },
  68. output = f[2],
  69. })
  70. end
  71. end
  72. function wine:add_item(list)
  73. for n = 1, #list do
  74. table.insert(ferment, list[n])
  75. if is_uninv then
  76. unified_inventory.register_craft({
  77. type = "barrel",
  78. items = { list[n][1] },
  79. output = list[n][2],
  80. })
  81. end
  82. end
  83. end
  84. -- glass of wine
  85. minetest.register_node("wine:glass_wine", {
  86. description = S("Glass of Wine"),
  87. drawtype = "plantlike",
  88. visual_scale = 0.8,
  89. tiles = {"wine_glass.png"},
  90. inventory_image = "wine_glass.png",
  91. wield_image = "wine_glass.png",
  92. paramtype = "light",
  93. is_ground_content = false,
  94. sunlight_propagates = true,
  95. walkable = false,
  96. selection_box = {
  97. type = "fixed",
  98. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  99. },
  100. groups = {
  101. food_wine = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  102. alcohol = 1
  103. },
  104. sounds = wine.snd_g,
  105. on_use = minetest.item_eat(2),
  106. })
  107. -- bottle of wine
  108. minetest.register_node("wine:bottle_wine", {
  109. description = S("Bottle of Wine"),
  110. drawtype = "plantlike",
  111. tiles = {"wine_bottle.png"},
  112. inventory_image = "wine_bottle.png",
  113. paramtype = "light",
  114. sunlight_propagates = true,
  115. walkable = false,
  116. selection_box = {
  117. type = "fixed",
  118. fixed = { -0.15, -0.5, -0.15, 0.15, 0.25, 0.15 }
  119. },
  120. groups = {dig_immediate = 3, attached_node = 1, vessel = 1},
  121. sounds = wine.snd_d,
  122. })
  123. minetest.register_craft({
  124. output = "wine:bottle_wine",
  125. recipe = {
  126. {"wine:glass_wine", "wine:glass_wine", "wine:glass_wine"},
  127. {"wine:glass_wine", "wine:glass_wine", "wine:glass_wine"},
  128. {"wine:glass_wine", "wine:glass_wine", "wine:glass_wine"},
  129. },
  130. })
  131. minetest.register_craft({
  132. type = "shapeless",
  133. output = "wine:glass_wine 9",
  134. recipe = {"wine:bottle_wine"},
  135. })
  136. -- glass of rum
  137. minetest.register_node("wine:glass_rum", {
  138. description = S("Rum"),
  139. drawtype = "plantlike",
  140. visual_scale = 0.8,
  141. tiles = {"wine_rum_glass.png"},
  142. inventory_image = "wine_rum_glass.png",
  143. wield_image = "wine_rum_glass.png",
  144. paramtype = "light",
  145. is_ground_content = false,
  146. sunlight_propagates = true,
  147. walkable = false,
  148. selection_box = {
  149. type = "fixed",
  150. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  151. },
  152. groups = {
  153. food_rum = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  154. alcohol = 1
  155. },
  156. sounds = wine.snd_g,
  157. on_use = minetest.item_eat(2),
  158. })
  159. -- bottle of rum
  160. minetest.register_node("wine:bottle_rum", {
  161. description = S("Bottle of Rum"),
  162. drawtype = "plantlike",
  163. tiles = {"wine_rum_bottle.png"},
  164. inventory_image = "wine_rum_bottle.png",
  165. paramtype = "light",
  166. sunlight_propagates = true,
  167. walkable = false,
  168. selection_box = {
  169. type = "fixed",
  170. fixed = { -0.15, -0.5, -0.15, 0.15, 0.25, 0.15 }
  171. },
  172. groups = {dig_immediate = 3, attached_node = 1, vessel = 1},
  173. sounds = wine.snd_d,
  174. })
  175. minetest.register_craft({
  176. output = "wine:bottle_rum",
  177. recipe = {
  178. {"wine:glass_rum", "wine:glass_rum", "wine:glass_rum"},
  179. {"wine:glass_rum", "wine:glass_rum", "wine:glass_rum"},
  180. {"wine:glass_rum", "wine:glass_rum", "wine:glass_rum"},
  181. },
  182. })
  183. minetest.register_craft({
  184. type = "shapeless",
  185. output = "wine:glass_rum 9",
  186. recipe = {"wine:bottle_rum"},
  187. })
  188. -- glass of weizen, or wheat beer
  189. -- The image is a lighter version of the one from RiverKpocc @ deviantart.com
  190. minetest.register_node("wine:glass_wheat_beer", {
  191. description = S("Wheat Beer"),
  192. drawtype = "torchlike", --"plantlike",
  193. visual_scale = 0.8,
  194. tiles = {"wine_wheat_beer_glass.png"},
  195. inventory_image = "wine_wheat_beer_glass.png",
  196. wield_image = "wine_wheat_beer_glass.png",
  197. paramtype = "light",
  198. is_ground_content = false,
  199. sunlight_propagates = true,
  200. walkable = false,
  201. selection_box = {
  202. type = "fixed",
  203. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  204. },
  205. groups = {
  206. food_beer = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  207. alcohol = 1
  208. },
  209. sounds = wine.snd_g,
  210. on_use = minetest.item_eat(2),
  211. })
  212. -- glass of beer (thanks to RiverKpocc @ deviantart.com for image)
  213. minetest.register_node("wine:glass_beer", {
  214. description = S("Beer"),
  215. drawtype = "torchlike", --"plantlike",
  216. visual_scale = 0.8,
  217. tiles = {"wine_beer_glass.png"},
  218. inventory_image = "wine_beer_glass.png",
  219. wield_image = "wine_beer_glass.png",
  220. paramtype = "light",
  221. is_ground_content = false,
  222. sunlight_propagates = true,
  223. walkable = false,
  224. selection_box = {
  225. type = "fixed",
  226. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  227. },
  228. groups = {
  229. food_beer = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  230. alcohol = 1
  231. },
  232. sounds = wine.snd_g,
  233. on_use = minetest.item_eat(2),
  234. })
  235. -- glass of honey mead
  236. minetest.register_node("wine:glass_mead", {
  237. description = S("Honey-Mead"),
  238. drawtype = "plantlike",
  239. visual_scale = 0.8,
  240. tiles = {"wine_mead_glass.png"},
  241. inventory_image = "wine_mead_glass.png",
  242. wield_image = "wine_mead_glass.png",
  243. paramtype = "light",
  244. is_ground_content = false,
  245. sunlight_propagates = true,
  246. walkable = false,
  247. selection_box = {
  248. type = "fixed",
  249. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  250. },
  251. groups = {
  252. food_mead = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  253. alcohol = 1
  254. },
  255. sounds = wine.snd_g,
  256. on_use = minetest.item_eat(4),
  257. })
  258. -- glass of apple cider
  259. minetest.register_node("wine:glass_cider", {
  260. description = S("Apple Cider"),
  261. drawtype = "plantlike",
  262. visual_scale = 0.8,
  263. tiles = {"wine_cider_glass.png"},
  264. inventory_image = "wine_cider_glass.png",
  265. wield_image = "wine_cider_glass.png",
  266. paramtype = "light",
  267. is_ground_content = false,
  268. sunlight_propagates = true,
  269. walkable = false,
  270. selection_box = {
  271. type = "fixed",
  272. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  273. },
  274. groups = {
  275. food_cider = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  276. alcohol = 1
  277. },
  278. sounds = wine.snd_g,
  279. on_use = minetest.item_eat(2),
  280. })
  281. -- glass of tequila
  282. minetest.register_node("wine:glass_tequila", {
  283. description = S("Tequila"),
  284. drawtype = "plantlike",
  285. visual_scale = 0.8,
  286. tiles = {"wine_tequila.png"},
  287. inventory_image = "wine_tequila.png",
  288. wield_image = "wine_tequila.png",
  289. paramtype = "light",
  290. is_ground_content = false,
  291. sunlight_propagates = true,
  292. walkable = false,
  293. selection_box = {
  294. type = "fixed",
  295. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  296. },
  297. groups = {
  298. food_tequila = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  299. alcohol = 1
  300. },
  301. sounds = wine.snd_g,
  302. on_use = minetest.item_eat(2),
  303. })
  304. -- bottle of tequila
  305. minetest.register_node("wine:bottle_tequila", {
  306. description = S("Bottle of Tequila"),
  307. drawtype = "plantlike",
  308. tiles = {"wine_tequila_bottle.png"},
  309. inventory_image = "wine_tequila_bottle.png",
  310. paramtype = "light",
  311. sunlight_propagates = true,
  312. walkable = false,
  313. selection_box = {
  314. type = "fixed",
  315. fixed = { -0.15, -0.5, -0.15, 0.15, 0.25, 0.15 }
  316. },
  317. groups = {dig_immediate = 3, attached_node = 1, vessel = 1},
  318. sounds = wine.snd_d,
  319. })
  320. minetest.register_craft({
  321. output = "wine:bottle_tequila",
  322. recipe = {
  323. {"wine:glass_tequila", "wine:glass_tequila", "wine:glass_tequila"},
  324. {"wine:glass_tequila", "wine:glass_tequila", "wine:glass_tequila"},
  325. {"wine:glass_tequila", "wine:glass_tequila", "wine:glass_tequila"},
  326. },
  327. })
  328. minetest.register_craft({
  329. type = "shapeless",
  330. output = "wine:glass_tequila 9",
  331. recipe = {"wine:bottle_tequila"},
  332. })
  333. -- glass of sake
  334. minetest.register_node("wine:glass_sake", {
  335. description = S("Sake"),
  336. drawtype = "plantlike",
  337. visual_scale = 0.8,
  338. tiles = {"wine_sake.png"},
  339. inventory_image = "wine_sake.png",
  340. wield_image = "wine_sake.png",
  341. paramtype = "light",
  342. is_ground_content = false,
  343. sunlight_propagates = true,
  344. walkable = false,
  345. selection_box = {
  346. type = "fixed",
  347. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  348. },
  349. groups = {
  350. food_sake = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  351. alcohol = 1
  352. },
  353. sounds = wine.snd_g,
  354. on_use = minetest.item_eat(2),
  355. })
  356. -- glass of bourbon
  357. minetest.register_node("wine:glass_bourbon", {
  358. description = S("Glass of Bourbon"),
  359. drawtype = "plantlike",
  360. visual_scale = 0.8,
  361. tiles = {"wine_bourbon_glass.png"},
  362. inventory_image = "wine_bourbon_glass.png",
  363. wield_image = "wine_bourbon_glass.png",
  364. paramtype = "light",
  365. is_ground_content = false,
  366. sunlight_propagates = true,
  367. walkable = false,
  368. selection_box = {
  369. type = "fixed",
  370. fixed = {-0.2, -0.5, -0.2, 0.2, 0.2, 0.2}
  371. },
  372. groups = {
  373. food_wine = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  374. alcohol = 1
  375. },
  376. sounds = wine.snd_g,
  377. on_use = minetest.item_eat(2),
  378. })
  379. -- bottle of bourbon
  380. minetest.register_node("wine:bottle_bourbon", {
  381. description = S("Bottle of Bourbon"),
  382. drawtype = "plantlike",
  383. tiles = {"wine_bourbon_bottle.png"},
  384. inventory_image = "wine_bourbon_bottle.png",
  385. paramtype = "light",
  386. sunlight_propagates = true,
  387. walkable = false,
  388. selection_box = {
  389. type = "fixed",
  390. fixed = { -0.15, -0.5, -0.15, 0.15, 0.25, 0.15 }
  391. },
  392. groups = {dig_immediate = 3, attached_node = 1, vessel = 1},
  393. sounds = wine.snd_d,
  394. })
  395. minetest.register_craft({
  396. output = "wine:bottle_bourbon",
  397. recipe = {
  398. {"wine:glass_bourbon", "wine:glass_bourbon", "wine:glass_bourbon"},
  399. {"wine:glass_bourbon", "wine:glass_bourbon", "wine:glass_bourbon"},
  400. {"wine:glass_bourbon", "wine:glass_bourbon", "wine:glass_bourbon"},
  401. },
  402. })
  403. minetest.register_craft({
  404. type = "shapeless",
  405. output = "wine:glass_bourbon 9",
  406. recipe = {"wine:bottle_bourbon"},
  407. })
  408. -- glass of vodka
  409. minetest.register_node("wine:glass_vodka", {
  410. description = S("Glass of Vodka"),
  411. drawtype = "plantlike",
  412. visual_scale = 0.8,
  413. tiles = {"wine_vodka_glass.png"},
  414. inventory_image = "wine_vodka_glass.png",
  415. wield_image = "wine_vodka_glass.png",
  416. paramtype = "light",
  417. is_ground_content = false,
  418. sunlight_propagates = true,
  419. walkable = false,
  420. selection_box = {
  421. type = "fixed",
  422. fixed = {-0.2, -0.5, -0.2, 0.2, 0.2, 0.2}
  423. },
  424. groups = {
  425. food_wine = 1, vessel = 1, dig_immediate = 3, attached_node = 1,
  426. alcohol = 1
  427. },
  428. sounds = wine.snd_g,
  429. on_use = minetest.item_eat(2),
  430. })
  431. -- bottle of vodka
  432. minetest.register_node("wine:bottle_vodka", {
  433. description = S("Bottle of Vodka"),
  434. drawtype = "plantlike",
  435. tiles = {"wine_vodka_bottle.png"},
  436. inventory_image = "wine_vodka_bottle.png",
  437. paramtype = "light",
  438. sunlight_propagates = true,
  439. walkable = false,
  440. selection_box = {
  441. type = "fixed",
  442. fixed = { -0.15, -0.5, -0.15, 0.15, 0.25, 0.15 }
  443. },
  444. groups = {dig_immediate = 3, attached_node = 1, vessel = 1},
  445. sounds = wine.snd_d,
  446. })
  447. minetest.register_craft({
  448. output = "wine:bottle_vodka",
  449. recipe = {
  450. {"wine:glass_vodka", "wine:glass_vodka", "wine:glass_vodka"},
  451. {"wine:glass_vodka", "wine:glass_vodka", "wine:glass_vodka"},
  452. {"wine:glass_vodka", "wine:glass_vodka", "wine:glass_vodka"},
  453. },
  454. })
  455. minetest.register_craft({
  456. type = "shapeless",
  457. output = "wine:glass_vodka 9",
  458. recipe = {"wine:bottle_vodka"},
  459. })
  460. -- blue agave
  461. minetest.register_node("wine:blue_agave", {
  462. description = S("Blue Agave"),
  463. drawtype = "plantlike",
  464. visual_scale = 0.8,
  465. tiles = {"wine_blue_agave.png"},
  466. inventory_image = "wine_blue_agave.png",
  467. wield_image = "wine_blue_agave.png",
  468. paramtype = "light",
  469. is_ground_content = false,
  470. sunlight_propagates = true,
  471. walkable = false,
  472. selection_box = {
  473. type = "fixed",
  474. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  475. },
  476. groups = {snappy = 3, attached_node = 1, plant = 1},
  477. sounds = wine.snd_l,
  478. on_construct = function(pos)
  479. local timer = minetest.get_node_timer(pos)
  480. timer:start(17)
  481. end,
  482. on_timer = function(pos)
  483. local light = minetest.get_node_light(pos)
  484. if not light or light < 13 or math.random() > 1/76 then
  485. return true -- go to next iteration
  486. end
  487. local n = minetest.find_nodes_in_area_under_air(
  488. {x = pos.x + 2, y = pos.y + 1, z = pos.z + 2},
  489. {x = pos.x - 2, y = pos.y - 1, z = pos.z - 2},
  490. {"wine:blue_agave"})
  491. -- too crowded, we'll wait for another iteration
  492. if #n > 2 then
  493. return true
  494. end
  495. -- find desert sand with air above (grow across and down only)
  496. n = minetest.find_nodes_in_area_under_air(
  497. {x = pos.x + 1, y = pos.y - 1, z = pos.z + 1},
  498. {x = pos.x - 1, y = pos.y - 2, z = pos.z - 1},
  499. {wine.sand})
  500. -- place blue agave
  501. if n and #n > 0 then
  502. local new_pos = n[math.random(#n)]
  503. new_pos.y = new_pos.y + 1
  504. minetest.set_node(new_pos, {name = "wine:blue_agave"})
  505. end
  506. return true
  507. end
  508. })
  509. minetest.register_craft( {
  510. type = "shapeless",
  511. output = "dye:cyan 4",
  512. recipe = {"wine:blue_agave"}
  513. })
  514. minetest.register_decoration({
  515. deco_type = "simple",
  516. place_on = {wine.sand},
  517. sidelen = 16,
  518. fill_ratio = 0.001,
  519. biomes = {"desert"},
  520. decoration = {"wine:blue_agave"},
  521. y_min = 15,
  522. y_max = 50,
  523. spawn_by = wine.sand,
  524. num_spawn_by = 6,
  525. })
  526. if minetest.get_modpath("bonemeal") then
  527. bonemeal:add_deco({
  528. {wine.sand, {}, {"default:dry_shrub", "wine:blue_agave", "", ""} }
  529. })
  530. end
  531. -- Wine barrel
  532. winebarrel_formspec = "size[8,9]"
  533. .. "list[current_name;src;2,1;1,1;]"
  534. .. "list[current_name;dst;5,1;1,1;]"
  535. .. "list[current_player;main;0,5;8,4;]"
  536. .. "listring[current_name;dst]"
  537. .. "listring[current_player;main]"
  538. .. "listring[current_name;src]"
  539. .. "listring[current_player;main]"
  540. .. "image[3.5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]"
  541. minetest.register_node("wine:wine_barrel", {
  542. description = S("Fermenting Barrel"),
  543. tiles = {"wine_barrel.png" },
  544. drawtype = "mesh",
  545. mesh = "wine_barrel.obj",
  546. paramtype = "light",
  547. paramtype2 = "facedir",
  548. groups = {
  549. choppy = 2, oddly_breakable_by_hand = 1, flammable = 2,
  550. tubedevice = 1, tubedevice_receiver = 1
  551. },
  552. legacy_facedir_simple = true,
  553. on_place = minetest.rotate_node,
  554. on_construct = function(pos)
  555. local meta = minetest.get_meta(pos)
  556. meta:set_string("formspec", winebarrel_formspec)
  557. meta:set_string("infotext", S("Fermenting Barrel"))
  558. meta:set_float("status", 0.0)
  559. local inv = meta:get_inventory()
  560. inv:set_size("src", 1)
  561. inv:set_size("dst", 1)
  562. end,
  563. can_dig = function(pos,player)
  564. local meta = minetest.get_meta(pos)
  565. local inv = meta:get_inventory()
  566. if not inv:is_empty("dst")
  567. or not inv:is_empty("src") then
  568. return false
  569. end
  570. return true
  571. end,
  572. allow_metadata_inventory_take = function(pos, listname, index, stack, player)
  573. if minetest.is_protected(pos, player:get_player_name()) then
  574. return 0
  575. end
  576. return stack:get_count()
  577. end,
  578. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  579. if minetest.is_protected(pos, player:get_player_name()) then
  580. return 0
  581. end
  582. local meta = minetest.get_meta(pos)
  583. local inv = meta:get_inventory()
  584. if listname == "src" then
  585. return stack:get_count()
  586. elseif listname == "dst" then
  587. return 0
  588. end
  589. end,
  590. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  591. if minetest.is_protected(pos, player:get_player_name()) then
  592. return 0
  593. end
  594. local meta = minetest.get_meta(pos)
  595. local inv = meta:get_inventory()
  596. local stack = inv:get_stack(from_list, from_index)
  597. if to_list == "src" then
  598. return count
  599. elseif to_list == "dst" then
  600. return 0
  601. end
  602. end,
  603. on_metadata_inventory_put = function(pos)
  604. local timer = minetest.get_node_timer(pos)
  605. timer:start(5)
  606. end,
  607. tube = (function() if minetest.get_modpath("pipeworks") then return {
  608. -- using a different stack from defaut when inserting
  609. insert_object = function(pos, node, stack, direction)
  610. local meta = minetest.get_meta(pos)
  611. local inv = meta:get_inventory()
  612. local timer = minetest.get_node_timer(pos)
  613. if not timer:is_started() then
  614. timer:start(5)
  615. end
  616. return inv:add_item("src", stack)
  617. end,
  618. can_insert = function(pos,node,stack,direction)
  619. local meta = minetest.get_meta(pos)
  620. local inv = meta:get_inventory()
  621. return inv:room_for_item("src", stack)
  622. end,
  623. -- the default stack, from which objects will be taken
  624. input_inventory = "dst",
  625. connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
  626. } end end)(),
  627. on_timer = function(pos)
  628. local meta = minetest.get_meta(pos) ; if not meta then return end
  629. local inv = meta:get_inventory()
  630. -- is barrel empty?
  631. if not inv or inv:is_empty("src") then
  632. meta:set_float("status", 0.0)
  633. meta:set_string("infotext", S("Fermenting Barrel"))
  634. return false
  635. end
  636. -- does it contain any of the source items on the list?
  637. local has_item
  638. for n = 1, #ferment do
  639. if inv:contains_item("src", ItemStack(ferment[n][1])) then
  640. has_item = n
  641. break
  642. end
  643. end
  644. if not has_item then
  645. return false
  646. end
  647. -- is there room for additional fermentation?
  648. if not inv:room_for_item("dst", ferment[has_item][2]) then
  649. meta:set_string("infotext", S("Fermenting Barrel (FULL)"))
  650. return true
  651. end
  652. local status = meta:get_float("status")
  653. -- fermenting (change status)
  654. if status < 100 then
  655. meta:set_string("infotext", S("Fermenting Barrel (@1% Done)", status))
  656. meta:set_float("status", status + 5)
  657. else
  658. inv:remove_item("src", ferment[has_item][1])
  659. inv:add_item("dst", ferment[has_item][2])
  660. meta:set_float("status", 0,0)
  661. end
  662. if inv:is_empty("src") then
  663. meta:set_float("status", 0.0)
  664. meta:set_string("infotext", S("Fermenting Barrel"))
  665. end
  666. return true
  667. end,
  668. })
  669. if mcl then
  670. minetest.register_craft({
  671. output = "wine:wine_barrel",
  672. recipe = {
  673. {"group:wood", "group:wood", "group:wood"},
  674. {"mcl_core:iron_ingot", "", "mcl_core:iron_ingot"},
  675. {"group:wood", "group:wood", "group:wood"},
  676. },
  677. })
  678. else
  679. minetest.register_craft({
  680. output = "wine:wine_barrel",
  681. recipe = {
  682. {"group:wood", "group:wood", "group:wood"},
  683. {"default:steel_ingot", "", "default:steel_ingot"},
  684. {"group:wood", "group:wood", "group:wood"},
  685. },
  686. })
  687. end
  688. -- LBMs to start timers on existing, ABM-driven nodes
  689. minetest.register_lbm({
  690. name = "wine:barrel_timer_init",
  691. nodenames = {"wine:wine_barrel"},
  692. run_at_every_load = false,
  693. action = function(pos)
  694. local t = minetest.get_node_timer(pos)
  695. t:start(5)
  696. end,
  697. })
  698. minetest.register_lbm({
  699. name = "wine:agave_timer_init",
  700. nodenames = {"wine:blue_agave"},
  701. run_at_every_load = false,
  702. action = function(pos)
  703. local t = minetest.get_node_timer(pos)
  704. t:start(17)
  705. end,
  706. })
  707. -- add lucky blocks
  708. if minetest.get_modpath("lucky_block") then
  709. lucky_block:add_blocks({
  710. {"dro", {"wine:glass_wine"}, 5},
  711. {"dro", {"wine:glass_beer"}, 5},
  712. {"dro", {"wine:glass_wheat_beer"}, 5},
  713. {"dro", {"wine:glass_mead"}, 5},
  714. {"dro", {"wine:glass_cider"}, 5},
  715. {"dro", {"wine:glass_rum"}, 5},
  716. {"dro", {"wine:glass_tequila"}, 5},
  717. {"dro", {"wine:glass_bourbon"}, 5},
  718. {"dro", {"wine:glass_vodka"}, 5},
  719. {"dro", {"wine:wine_barrel"}, 1},
  720. {"tel", 5, 1},
  721. {"nod", "default:chest", 0, {
  722. {name = "wine:bottle_wine", max = 1},
  723. {name = "wine:bottle_tequila", max = 1},
  724. {name = "wine:bottle_rum", max = 1},
  725. {name = "wine:bottle_bourbon", max = 1},
  726. {name = "wine:bottle_vodka", max = 1},
  727. {name = "wine:wine_barrel", max = 1},
  728. {name = "wine:blue_agave", max = 4}}},
  729. })
  730. end
  731. print (S("[MOD] Wine loaded"))