agave.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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("mcl_dye") then
  59. minetest.register_craft( {
  60. output = "mcl_dye:cyan 4",
  61. recipe = {{"wine:blue_agave"}}
  62. })
  63. elseif minetest.get_modpath("dye") then
  64. minetest.register_craft( {
  65. output = "dye:cyan 4",
  66. type = "shapeless", --forks
  67. recipe = {"wine:blue_agave"},
  68. })
  69. end
  70. -- blue agave as fuel
  71. minetest.register_craft({
  72. type = "fuel",
  73. recipe = "wine:blue_agave",
  74. burntime = 10
  75. })
  76. -- cook blue agave into a sugar syrup
  77. minetest.register_craftitem("wine:agave_syrup", {
  78. description = "Agave Syrup",
  79. inventory_image = "wine_agave_syrup.png",
  80. groups = {food_sugar = 1, vessel = 1, flammable = 3}
  81. })
  82. minetest.register_craft({
  83. type = "cooking",
  84. cooktime = 7,
  85. output = "wine:agave_syrup 2",
  86. recipe = "wine:blue_agave"
  87. })
  88. -- blue agave into paper
  89. minetest.register_craft( {
  90. output = "default:paper 3",
  91. recipe = {
  92. {"wine:blue_agave", "wine:blue_agave", "wine:blue_agave"}
  93. }
  94. })
  95. -- register blue agave on mapgen
  96. minetest.register_decoration({
  97. deco_type = "simple",
  98. place_on = {sand},
  99. sidelen = 16,
  100. fill_ratio = 0.001,
  101. biomes = {"desert"},
  102. decoration = {"wine:blue_agave"},
  103. y_min = 15,
  104. y_max = 50,
  105. spawn_by = sand,
  106. num_spawn_by = 6
  107. })
  108. -- add lbm to start agave timers
  109. minetest.register_lbm({
  110. name = "wine:agave_timer_init",
  111. nodenames = {"wine:blue_agave"},
  112. run_at_every_load = false,
  113. action = function(pos)
  114. minetest.get_node_timer(pos):start(17)
  115. end
  116. })
  117. -- add to bonemeal as decoration if available
  118. if minetest.get_modpath("bonemeal") then
  119. bonemeal:add_deco({
  120. {sand, {}, {"default:dry_shrub", "wine:blue_agave", "", ""}}
  121. })
  122. end