agave.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. -- check available mods for default sound and sand node
  2. local def = minetest.get_modpath("default")
  3. local sand = "default:desert_sand"
  4. local snd_l = def and default.node_sound_leaves_defaults()
  5. if minetest.get_modpath("mcl_core") then
  6. sand = "mcl_core:sand"
  7. snd_l = mcl_sounds.node_sound_leaves_defaults()
  8. end
  9. local S = wine.S
  10. -- blue agave
  11. minetest.register_node("wine:blue_agave", {
  12. description = S("Blue Agave"),
  13. drawtype = "plantlike",
  14. visual_scale = 0.8,
  15. tiles = {"wine_blue_agave.png"},
  16. inventory_image = "wine_blue_agave.png",
  17. wield_image = "wine_blue_agave.png",
  18. paramtype = "light",
  19. is_ground_content = false,
  20. sunlight_propagates = true,
  21. walkable = false,
  22. selection_box = {
  23. type = "fixed",
  24. fixed = {-0.2, -0.5, -0.2, 0.2, 0.3, 0.2}
  25. },
  26. groups = {snappy = 3, attached_node = 1, plant = 1},
  27. sounds = snd_l,
  28. on_use = minetest.item_eat(2),
  29. on_construct = function(pos)
  30. minetest.get_node_timer(pos):start(17)
  31. end,
  32. on_timer = function(pos)
  33. local light = minetest.get_node_light(pos)
  34. if not light or light < 13 or math.random() > 1/76 then
  35. return true -- go to next iteration
  36. end
  37. local n = minetest.find_nodes_in_area_under_air(
  38. {x = pos.x + 2, y = pos.y + 1, z = pos.z + 2},
  39. {x = pos.x - 2, y = pos.y - 1, z = pos.z - 2}, {"wine:blue_agave"})
  40. -- too crowded, we'll wait for another iteration
  41. if n and #n > 2 then
  42. return true
  43. end
  44. -- find desert sand with air above (grow across and down only)
  45. n = minetest.find_nodes_in_area_under_air(
  46. {x = pos.x + 1, y = pos.y - 1, z = pos.z + 1},
  47. {x = pos.x - 1, y = pos.y - 2, z = pos.z - 1}, {sand})
  48. -- place blue agave
  49. if n and #n > 0 then
  50. local new_pos = n[math.random(#n)]
  51. new_pos.y = new_pos.y + 1
  52. minetest.set_node(new_pos, {name = "wine:blue_agave"})
  53. end
  54. return true
  55. end
  56. })
  57. -- blue agave into cyan dye
  58. if minetest.get_modpath("dye") then
  59. minetest.register_craft( {
  60. output = "dye:cyan 4",
  61. recipe = {{"wine:blue_agave"}}
  62. })
  63. end
  64. -- blue agave as fuel
  65. minetest.register_craft({
  66. type = "fuel",
  67. recipe = "wine:blue_agave",
  68. burntime = 10
  69. })
  70. -- cook blue agave into a sugar syrup
  71. minetest.register_craftitem("wine:agave_syrup", {
  72. description = "Agave Syrup",
  73. inventory_image = "wine_agave_syrup.png",
  74. groups = {food_sugar = 1, vessel = 1, flammable = 3}
  75. })
  76. minetest.register_craft({
  77. type = "cooking",
  78. cooktime = 7,
  79. output = "wine:agave_syrup 2",
  80. recipe = "wine:blue_agave"
  81. })
  82. -- blue agave into paper
  83. minetest.register_craft( {
  84. output = "default:paper 3",
  85. recipe = {
  86. {"wine:blue_agave", "wine:blue_agave", "wine:blue_agave"}
  87. }
  88. })
  89. -- register blue agave on mapgen
  90. minetest.register_decoration({
  91. deco_type = "simple",
  92. place_on = {sand},
  93. sidelen = 16,
  94. fill_ratio = 0.001,
  95. biomes = {"desert"},
  96. decoration = {"wine:blue_agave"},
  97. y_min = 15,
  98. y_max = 50,
  99. spawn_by = sand,
  100. num_spawn_by = 6
  101. })
  102. -- add lbm to start agave timers
  103. minetest.register_lbm({
  104. name = "wine:agave_timer_init",
  105. nodenames = {"wine:blue_agave"},
  106. run_at_every_load = false,
  107. action = function(pos)
  108. minetest.get_node_timer(pos):start(17)
  109. end
  110. })
  111. -- add to bonemeal as decoration if available
  112. if minetest.get_modpath("bonemeal") then
  113. bonemeal:add_deco({
  114. {sand, {}, {"default:dry_shrub", "wine:blue_agave", "", ""}}
  115. })
  116. end