plant_growth.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. minetest.register_node("potions:grass_growth_accel", {
  2. description = "Grass Growth Accelerator",
  3. inventory_image = "default_grass.png",
  4. tiles = {"default_grass.png"},
  5. groups = {cracky=3,},
  6. })
  7. local function random_pos(pos, dist)
  8. local p = {
  9. x=pos.x + math.random(-dist, dist),
  10. y=pos.y + 4,
  11. z=pos.z + math.random(-dist, dist),
  12. }
  13. while p.y > pos.y - dist do
  14. local n = minetest.get_node(p)
  15. if n.name ~= "air" and n.name ~= "ignore" then
  16. if n.name == "default:water_source" or n.name == "default:water_flowing" then
  17. return nil
  18. end
  19. return p
  20. end
  21. p.y = p.y - 1
  22. end
  23. return nil
  24. end
  25. minetest.register_abm({
  26. nodenames = "potions:grass_growth_accel",
  27. interval = 1,
  28. chance = 1,
  29. action = function(pos)
  30. local p = random_pos(pos, 10)
  31. if not p then return end
  32. local b = minetest.get_node(p)
  33. if b.name == "default:dirt" or b.name == "default:dirt_with_dry_grass" then
  34. minetest.set_node(p, {name="default:dirt_with_grass"})
  35. elseif b.name == "default:dirt_with_grass" then
  36. p.y = p.y + 1
  37. local n = minetest.get_node(p)
  38. if n.name == "air" then
  39. minetest.set_node(p, {name="default:grass_1"})
  40. end
  41. elseif b.name == "default:grass_1" then
  42. minetest.set_node(p, {name="default:grass_2"})
  43. elseif b.name == "default:grass_2" then
  44. minetest.set_node(p, {name="default:grass_3"})
  45. elseif b.name == "default:grass_3" then
  46. minetest.set_node(p, {name="default:grass_4"})
  47. elseif b.name == "default:grass_4" then
  48. minetest.set_node(p, {name="default:grass_5"})
  49. elseif b.name == "default:grass_5" then
  50. return
  51. end
  52. end,
  53. })
  54. minetest.register_node("potions:flower_growth_accel", {
  55. description = "Flower Growth Accelerator",
  56. inventory_image = "default_grass.png^flowers_rose.png",
  57. tiles = {"default_grass.png^flowers_rose.png"},
  58. groups = {cracky=3,},
  59. })
  60. minetest.register_abm({
  61. nodenames = "potions:flower_growth_accel",
  62. interval = 1,
  63. chance = 1,
  64. action = function(pos)
  65. local p = random_pos(pos, 10)
  66. if not p then return end
  67. local b = minetest.get_node(p)
  68. if b.name == "default:dirt" then
  69. minetest.set_node(p, {name="default:dirt_with_grass"})
  70. else
  71. if b.name == "default:dirt_with_grass" then
  72. p.y = p.y + 1
  73. local n = minetest.get_node(p)
  74. if n.name == "air" then
  75. local f = flowers.datas[math.random(#flowers.datas)]
  76. minetest.set_node(p, {name="flowers:"..f[1]})
  77. end
  78. else
  79. local def = minetest.registered_nodes[b.name]
  80. if def.groups.grass then
  81. local f = flowers.datas[math.random(#flowers.datas)]
  82. minetest.set_node(p, {name="flowers:"..f[1]})
  83. end
  84. end
  85. end
  86. end,
  87. })
  88. -- TODO: mushroom accelerator
  89. -- max lifetime for these nodes