init.lua 14 KB

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