init.lua 16 KB

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