init.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. -- Minetest 0.4 mod: default
  2. -- See README.txt for licensing and other information.
  3. flowers = {}
  4. -- Map Generation
  5. dofile(minetest.get_modpath("flowers").."/mapgen.lua")
  6. -- Aliases for original flowers mod
  7. minetest.register_alias("flowers:flower_dandelion_white", "flowers:dandelion_white")
  8. minetest.register_alias("flowers:flower_dandelion_yellow", "flowers:dandelion_yellow")
  9. minetest.register_alias("flowers:flower_geranium", "flowers:geranium")
  10. minetest.register_alias("flowers:flower_rose", "flowers:rose")
  11. minetest.register_alias("flowers:flower_tulip", "flowers:tulip")
  12. minetest.register_alias("flowers:flower_viola", "flowers:viola")
  13. flowers.flowers = {
  14. -- flower name, desc, groups
  15. {"dandelion_white", "White Dandelion", {flower=1, flora=1, color_white=1}},
  16. {"dandelion_yellow", "Yellow Dandelion", {flower=1, flora=1, color_yellow=1}},
  17. {"geranium", "Blue Geranium", {flower=1, flora=1, color_blue=1}},
  18. {"rose", "Rose", {flower=1, flora=1, color_red=1}},
  19. {"tulip", "Tulip", {flower=1, flora=1, color_orange=1}},
  20. {"viola", "Viola", {flower=1, flora=1, color_violet=1}},
  21. }
  22. -- Flowers
  23. for _, row in ipairs(flowers.flowers) do
  24. local name = row[1]
  25. local desc = row[2]
  26. local groups = row[3]
  27. groups.dig_immediate = 3
  28. groups.flammable = 2
  29. groups.falling_node = 1
  30. minetest.register_node("flowers:"..name, {
  31. description = desc,
  32. drawtype = "torchlike",
  33. tiles = {"flowers_"..name..".png"},
  34. inventory_image = "flowers_"..name..".png",
  35. wield_image = "flowers_"..name..".png",
  36. sunlight_propagates = true,
  37. paramtype = "light",
  38. walkable = false,
  39. buildable_to = true,
  40. floodable = true,
  41. groups = groups,
  42. sounds = default.node_sound_leaves_defaults(),
  43. selection_box = {
  44. type = "fixed",
  45. fixed = { -0.25, -0.5, -0.25, 0.25, 0.25, 0.25},
  46. },
  47. })
  48. end
  49. flowers.mushrooms = {
  50. -- name, desc, groups, hp change
  51. {"mushroom_brown", "Brown Mushroom", {}, 1},
  52. {"mushroom_red", "Red Mushroom", {}, -1},
  53. }
  54. -- Mushrooms
  55. for _, row in ipairs(flowers.mushrooms) do
  56. local name = row[1]
  57. local desc = row[2]
  58. local groups = row[3]
  59. local hp = row[4]
  60. groups.dig_immediate = 3
  61. groups.flammable = 2
  62. groups.falling_node = 1
  63. minetest.register_node("flowers:"..name, {
  64. description = desc,
  65. drawtype = "plantlike",
  66. tiles = {"flowers_"..name..".png"},
  67. inventory_image = "flowers_"..name..".png",
  68. wield_image = "flowers_"..name..".png",
  69. sunlight_propagates = true,
  70. paramtype = "light",
  71. walkable = false,
  72. buildable_to = true,
  73. floodable = true,
  74. groups = groups,
  75. sounds = default.node_sound_leaves_defaults(),
  76. selection_box = {
  77. type = "fixed",
  78. fixed = { -0.25, -0.5, -0.25, 0.25, 0.25, 0.25},
  79. },
  80. on_use = minetest.item_eat(hp),
  81. after_dig_node = function(pos, node, metadata, digger)
  82. if node.param2 ~= 1 then
  83. minetest.add_node(pos, {name="flowers:"..name.."_spores"})
  84. end
  85. end,
  86. on_timer = function(pos)
  87. local node = minetest.get_node(pos)
  88. if node.param2 ~= 1 then return true end
  89. node.param2 = nil
  90. minetest.set_node(pos, node)
  91. end,
  92. after_place_node = function(pos)
  93. minetest.add_node(pos, {name="flowers:"..name, param2=1})
  94. minetest.get_node_timer(pos):start(math.random(6000,48000))
  95. end,
  96. })
  97. minetest.register_node("flowers:"..name.."_spores", {
  98. description = ""..desc.." Spores",
  99. drawtype = "nodebox",
  100. node_box = {
  101. type = "fixed",
  102. fixed = {-0.5, -0.5, -0.5, 0.5, -0.5 + (1 / 16), 0.5}
  103. },
  104. tiles = {"flowers_"..name.."_spores.png"},
  105. inventory_image = "flowers_"..name.."_spores.png",
  106. paramtype = "light",
  107. sunlight_propagates = true,
  108. walkable = false,
  109. buildable_to = true,
  110. groups = {snappy = 3, attached_node = 1},
  111. drop = "",
  112. sounds = default.node_sound_leaves_defaults(),
  113. on_timer = function(pos)
  114. local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y - 1, z = pos.z})
  115. if minetest.get_item_group(node_under.name, "soil") == 0 then
  116. minetest.remove_node(pos)
  117. else
  118. minetest.set_node(pos, {name="flowers:"..name})
  119. end
  120. end,
  121. on_construct = function(pos)
  122. minetest.get_node_timer(pos):start(math.random(6000,48000))
  123. end,
  124. })
  125. end