init.lua 16 KB

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