init.lua 14 KB

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